-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/track metrics #1019
Merged
Merged
Feat/track metrics #1019
Changes from 26 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
9ca7463
started metrics
elraphty f9a74fe
added redis
elraphty f8f6d2c
added redis get and set functions
elraphty 3b5bc15
added Redis map
elraphty bd57716
modified redis
elraphty 504f0ee
Merge branch 'master' into feat/track_metrics
elraphty af51e07
added endpoints for metrics
elraphty fd2fc0e
merged master
elraphty 452c1c2
merged master
elraphty d27e816
added bounty metrics
elraphty 153c154
added column for date difference
elraphty c1a27f9
added completetion_date difference
elraphty bff247e
Merge branch 'master' into feat/track_metrics
elraphty cfcc9c1
added metrics to redis
elraphty 6b48054
refactored redis
elraphty a2dedb0
Merge branch 'master' into feat/track_metrics
elraphty f54d142
added bounty by range
elraphty 9e8b87a
enforce price in number
elraphty 2585fda
added prettier info
elraphty d4d56e5
renamed routes
elraphty e996718
added Redis to Readme
elraphty af9c997
used completed functions
elraphty 85c3426
added more test for the difference function
elraphty 4f082eb
added tests for all helpers
elraphty 089d952
added superadmin middleware
elraphty 0de702d
added superadmin middleware functionality
elraphty d03c108
Merge branch 'master' into feat/track_metrics
elraphty 1792647
added bounty data for metrics
elraphty 42ebd4e
added SUPER_ADMINS to README
elraphty 7fb0e88
slight changes
elraphty b1ce47b
refactored the metrics average sum
elraphty 7c74653
uncommented redis
elraphty 28b7092
added Redis error clause to metrics code
elraphty 84fa142
fixed merge conflicts
elraphty 78c81b9
fixed config test error
elraphty 1844321
change SUPER_ADMINS to ADMINS
elraphty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
"net/http" | ||
|
||
"github.com/stakwork/sphinx-tribes/utils" | ||
) | ||
|
||
func (db database) TotalPeopleByDateRange(r PaymentDateRange) int64 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont see this being used anywhere |
||
var count int64 | ||
db.db.Model(&Person{}).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Count(&count) | ||
return count | ||
} | ||
|
||
func (db database) TotalOrganizationsByDateRange(r PaymentDateRange) int64 { | ||
var count int64 | ||
db.db.Model(&Organization{}).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Count(&count) | ||
return count | ||
} | ||
|
||
func (db database) TotalPaymentsByDateRange(r PaymentDateRange) uint { | ||
var sum uint | ||
db.db.Model(&PaymentHistory{}).Where("payment_type = ?", r.PaymentType).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Select("SUM(amount)").Row().Scan(&sum) | ||
return sum | ||
} | ||
|
||
func (db database) TotalSatsPosted(r PaymentDateRange) uint { | ||
var sum uint | ||
db.db.Model(&Bounty{}).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Select("SUM(price)").Row().Scan(&sum) | ||
return sum | ||
} | ||
|
||
func (db database) TotalSatsPaid(r PaymentDateRange) uint { | ||
var sum uint | ||
db.db.Model(&Bounty{}).Where("paid = ?", true).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Select("SUM(price)").Row().Scan(&sum) | ||
return sum | ||
} | ||
|
||
func (db database) SatsPaidPercentage(r PaymentDateRange) uint { | ||
satsPosted := DB.TotalSatsPosted(r) | ||
satsPaid := DB.TotalSatsPaid(r) | ||
if satsPaid != 0 && satsPosted != 0 { | ||
value := (satsPaid * 100) / satsPosted | ||
paidPercentage := math.Round(float64(value)) | ||
return uint(paidPercentage) | ||
} | ||
return 0 | ||
} | ||
|
||
func (db database) TotalPaidBounties(r PaymentDateRange) int64 { | ||
var count int64 | ||
db.db.Model(&Bounty{}).Where("paid = ?", true).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Count(&count) | ||
return count | ||
} | ||
|
||
func (db database) TotalBountiesPosted(r PaymentDateRange) int64 { | ||
var count int64 | ||
db.db.Model(&Bounty{}).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Count(&count) | ||
return count | ||
} | ||
|
||
func (db database) BountiesPaidPercentage(r PaymentDateRange) uint { | ||
bountiesPosted := DB.TotalBountiesPosted(r) | ||
bountiesPaid := DB.TotalPaidBounties(r) | ||
if bountiesPaid != 0 && bountiesPosted != 0 { | ||
value := bountiesPaid * 100 / bountiesPosted | ||
paidPercentage := math.Round(float64(value)) | ||
return uint(paidPercentage) | ||
} | ||
return 0 | ||
} | ||
|
||
func (db database) PaidDifferenceSum(r PaymentDateRange) uint { | ||
var sum uint | ||
db.db.Model(&Bounty{}).Where("paid_date_difference != ?", | ||
"").Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Select("SUM(paid_date_difference)").Row().Scan(&sum) | ||
return sum | ||
} | ||
|
||
func (db database) PaidDifferenceCount(r PaymentDateRange) int64 { | ||
var count int64 | ||
db.db.Model(&Bounty{}).Where("paid_date_difference != ?", | ||
"").Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Count(&count) | ||
return count | ||
} | ||
|
||
func (db database) AveragePaidTime(r PaymentDateRange) uint { | ||
paidSum := DB.PaidDifferenceSum(r) | ||
paidCount := DB.PaidDifferenceCount(r) | ||
if paidCount != 0 && paidSum != 0 { | ||
avg := paidSum / uint(paidCount) | ||
avgDays := math.Round(float64(avg)) | ||
return uint(avgDays) | ||
} | ||
return 0 | ||
} | ||
|
||
func (db database) CompletedDifferenceSum(r PaymentDateRange) uint { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont see this being used anywhere |
||
var sum uint | ||
db.db.Model(&Bounty{}).Where("completion_date_difference != ?", | ||
"").Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Select("SUM(completion_date_difference)").Row().Scan(&sum) | ||
return sum | ||
} | ||
|
||
func (db database) CompletedDifferenceCount(r PaymentDateRange) int64 { | ||
var count int64 | ||
db.db.Model(&Bounty{}).Where("completion_date_difference != ?", | ||
"").Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate).Count(&count) | ||
return count | ||
} | ||
|
||
func (db database) AverageCompletedTime(r PaymentDateRange) uint { | ||
paidSum := DB.CompletedDifferenceSum(r) | ||
paidCount := DB.CompletedDifferenceCount(r) | ||
if paidCount != 0 && paidSum != 0 { | ||
avg := paidSum / uint(paidCount) | ||
avgDays := math.Round(float64(avg)) | ||
return uint(avgDays) | ||
} | ||
return 0 | ||
} | ||
|
||
func (db database) GetBountiesByDateRange(r PaymentDateRange, re *http.Request) []Bounty { | ||
offset, limit, sortBy, direction, _ := utils.GetPaginationParams(re) | ||
|
||
orderQuery := "" | ||
limitQuery := "" | ||
|
||
if sortBy != "" && direction != "" { | ||
orderQuery = "ORDER BY " + "body." + sortBy + " " + direction | ||
} else { | ||
orderQuery = " ORDER BY " + "body." + sortBy + "" + "DESC" | ||
} | ||
if limit != 0 { | ||
limitQuery = fmt.Sprintf("LIMIT %d OFFSET %d", limit, offset) | ||
} | ||
|
||
query := `SELECT * public.bounty WHERE created >= '` + r.StartDate + `' AND created <= '` + r.EndDate + `'` | ||
allQuery := query + " " + " " + orderQuery + " " + limitQuery | ||
|
||
b := []Bounty{} | ||
db.db.Raw(allQuery).Scan(&b) | ||
return b | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can add this ENV var to the README and what it is used for that would be helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elraphty can you change this value to just
ADMINS
aswellSUPER_ADMINS
seems a bit much especially since we don't even have the concept of admins implemented yet