Skip to content

Commit

Permalink
added assignee stats
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed May 3, 2024
1 parent 1861bf5 commit b8d2b1f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
1 change: 1 addition & 0 deletions db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ type Database interface {
AverageCompletedTime(r PaymentDateRange, workspace string) uint
TotalBountiesPosted(r PaymentDateRange, workspace string) int64
TotalPaidBounties(r PaymentDateRange, workspace string) int64
TotalAssignedBounties(r PaymentDateRange, workspace string) int64
NewHuntersPaid(r PaymentDateRange, workspace string) int64
TotalHuntersPaid(r PaymentDateRange, workspace string) int64
GetPersonByPubkey(pubkey string) Person
Expand Down
26 changes: 16 additions & 10 deletions db/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ func (db database) TotalPaidBounties(r PaymentDateRange, workspace string) int64
return count
}

func (db database) TotalAssignedBounties(r PaymentDateRange, workspace string) int64 {
var count int64
query := db.db.Model(&NewBounty{}).Where("assignee != ''").Where("paid = ?", false).Where("created >= ?", r.StartDate).Where("created <= ?", r.EndDate)

if workspace != "" {
query.Where("workspace_uuid", workspace)
}

query.Count(&count)
return count
}

func (db database) TotalHuntersPaid(r PaymentDateRange, workspace string) int64 {
var count int64
query := fmt.Sprintf(`SELECT COUNT(DISTINCT assignee) FROM bounty WHERE assignee !='' AND paid=true AND created >= %s AND created <= %s`, r.StartDate, r.EndDate)
Expand Down Expand Up @@ -144,11 +156,11 @@ func (db database) BountiesPaidPercentage(r PaymentDateRange, workspace string)
func (db database) PaidDifference(r PaymentDateRange, workspace string) []DateDifference {
ms := []DateDifference{}

query := fmt.Sprintf("SELECT EXTRACT(EPOCH FROM (paid_date - TO_TIMESTAMP(created))) as diff FROM public.bounty WHERE paid_date IS NOT NULL AND created >= %s AND created <= %s", "`"+r.StartDate+"`", "`"+r.EndDate+"`")
query := fmt.Sprintf("SELECT EXTRACT(EPOCH FROM (paid_date - TO_TIMESTAMP(created))) as diff FROM public.bounty WHERE paid_date IS NOT NULL AND created >= %s AND created <= %s", r.StartDate, r.EndDate)

var workspaceQuery string
if workspace != "" {
workspaceQuery = fmt.Sprintf("AND workspace_uuid = `%s`", workspace)
workspaceQuery = fmt.Sprintf("AND workspace_uuid = '%s'", workspace)
}

allQuery := query + " " + workspaceQuery
Expand Down Expand Up @@ -176,11 +188,11 @@ func (db database) AveragePaidTime(r PaymentDateRange, workspace string) uint {
func (db database) CompletedDifference(r PaymentDateRange, workspace string) []DateDifference {
ms := []DateDifference{}

query := fmt.Sprintf("SELECT EXTRACT(EPOCH FROM (completion_date - TO_TIMESTAMP(created))) as diff FROM public.bounty WHERE completion_date IS NOT NULL AND created >= %s AND created <= %s ", "`"+r.StartDate+"`", "`"+r.EndDate+"`")
query := fmt.Sprintf("SELECT EXTRACT(EPOCH FROM (completion_date - TO_TIMESTAMP(created))) as diff FROM public.bounty WHERE completion_date IS NOT NULL AND created >= %s AND created <= %s", r.StartDate, r.EndDate)

var workspaceQuery string
if workspace != "" {
workspaceQuery = fmt.Sprintf("AND workspace_uuid = `%s`", workspace)
workspaceQuery = fmt.Sprintf("AND workspace_uuid = '%s'", workspace)
}

allQuery := query + " " + workspaceQuery
Expand Down Expand Up @@ -224,8 +236,6 @@ func (db database) GetBountiesByDateRange(r PaymentDateRange, re *http.Request)
providers := keys.Get("provider")
workspace := keys.Get("workspace")

fmt.Println("WORSKPACE === workspace", workspace)

orderQuery := ""
limitQuery := ""
workspaceQuery := ""
Expand Down Expand Up @@ -273,10 +283,6 @@ func (db database) GetBountiesByDateRange(r PaymentDateRange, re *http.Request)
b := []NewBounty{}
db.db.Raw(allQuery).Find(&b)

if workspace != "" {
fmt.Println("Bounties1 ===", b)
fmt.Println("Query1 ===", allQuery)
}
return b
}

Expand Down
1 change: 1 addition & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ type DateDifference struct {
type BountyMetrics struct {
BountiesPosted int64 `json:"bounties_posted"`
BountiesPaid int64 `json:"bounties_paid"`
BountiesAssigned int64 `json:"bounties_assigned"`
BountiesPaidPercentage uint `json:"bounties_paid_average"`
SatsPosted uint `json:"sats_posted"`
SatsPaid uint `json:"sats_paid"`
Expand Down
2 changes: 2 additions & 0 deletions handlers/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (mh *metricHandler) BountyMetrics(w http.ResponseWriter, r *http.Request) {

totalBountiesPosted := mh.db.TotalBountiesPosted(request, workspace)
totalBountiesPaid := mh.db.TotalPaidBounties(request, workspace)
totalBountiesAssigned := mh.db.TotalAssignedBounties(request, workspace)
bountiesPaidPercentage := mh.db.BountiesPaidPercentage(request, workspace)
totalSatsPosted := mh.db.TotalSatsPosted(request, workspace)
totalSatsPaid := mh.db.TotalSatsPaid(request, workspace)
Expand All @@ -164,6 +165,7 @@ func (mh *metricHandler) BountyMetrics(w http.ResponseWriter, r *http.Request) {
bountyMetrics := db.BountyMetrics{
BountiesPosted: totalBountiesPosted,
BountiesPaid: totalBountiesPaid,
BountiesAssigned: totalBountiesAssigned,
BountiesPaidPercentage: bountiesPaidPercentage,
SatsPosted: totalSatsPosted,
SatsPaid: totalSatsPaid,
Expand Down
47 changes: 47 additions & 0 deletions mocks/Database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b8d2b1f

Please sign in to comment.