-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release/v0.1.48: chore: enhance discord message for delivery metric feat: rank delivery metric item (#642) chore: role permission seeding feat: delivery metric get leader board api (#640) fix: emoji displaying
- Loading branch information
Showing
19 changed files
with
255 additions
and
21 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package deliverymetrics | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/dwarvesf/fortress-api/pkg/model" | ||
) | ||
|
||
func (c controller) GetWeeklyLeaderBoard() (*model.WeeklyLeaderBoard, error) { | ||
w, err := c.store.DeliveryMetric.GetLatestWeek(c.repo.DB()) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get latest week") | ||
} | ||
|
||
// Get top 10 users with highest points | ||
metrics, err := c.store.DeliveryMetric.GetTopWeighMetrics(c.repo.DB(), w, 5) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get top users with highest points") | ||
} | ||
|
||
items := make([]model.LeaderBoardItem, 0, len(metrics)) | ||
// Get user info | ||
for _, m := range metrics { | ||
e, err := c.store.Employee.One(c.repo.DB(), m.EmployeeID.String(), false) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get employee "+m.EmployeeID.String()) | ||
} | ||
|
||
// Get discord acc | ||
d, err := c.store.DiscordAccount.One(c.repo.DB(), e.DiscordAccountID.String()) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get discord account "+e.DiscordAccountID.String()+" of employee "+e.ID.String()) | ||
} | ||
|
||
items = append(items, model.LeaderBoardItem{ | ||
EmployeeID: e.ID.String(), | ||
EmployeeName: e.DisplayName, | ||
Points: m.Weight, | ||
Effectiveness: m.Effectiveness, | ||
DiscordID: d.DiscordID, | ||
DiscordUsername: d.Username, | ||
}) | ||
} | ||
|
||
return &model.WeeklyLeaderBoard{ | ||
Date: w, | ||
Items: rankItems(items), | ||
}, nil | ||
} | ||
|
||
func rankItems(data []model.LeaderBoardItem) []model.LeaderBoardItem { | ||
// Set the rank for each employee | ||
for i := range data { | ||
if i > 0 && data[i].Points.Equal(data[i-1].Points) && data[i].Effectiveness.Equal(data[i-1].Effectiveness) { | ||
data[i].Rank = data[i-1].Rank | ||
} else { | ||
data[i].Rank = i + 1 | ||
} | ||
} | ||
|
||
return data | ||
} |
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
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,14 @@ | ||
package discord | ||
|
||
var mapEmoji = map[string]string{ | ||
"ARROW_DOWN_ANIMATED": "<a:arrow_down_animated:1131789144759214171>", | ||
"ARROW_UP_ANIMATED": "<a:arrow_up_animated:1131789319644921936>", | ||
"BADGE1": "<a:badge1:1131850989062852638>", | ||
"BADGE2": "<a:badge2:1131850991663337554>", | ||
"BADGE3": "<a:badge3:1131850996159610930>", | ||
"BADGE5": "<a:badge5:1131851001117294672>", | ||
} | ||
|
||
func getEmoji(emoji string) string { | ||
return mapEmoji[emoji] | ||
} |
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
Oops, something went wrong.