Skip to content

Commit

Permalink
Fix leaderboard bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed Mar 21, 2024
1 parent a1fafaf commit 9d02fd3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
8 changes: 7 additions & 1 deletion server/db/sql_queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ SELECT
ORDER BY COALESCE(SUM(team_points.points), 0) DESC;

-- name: TeamPointsHistory :many
SELECT * FROM team_points ORDER BY added_at ASC;
SELECT
team_name,
added_at,
SUM(points) AS points
FROM team_points
GROUP BY team_name
ORDER BY added_at ASC;

-- name: ListTeams :many
SELECT team_name, created_at, accepting_members FROM teams;
Expand Down
27 changes: 17 additions & 10 deletions server/db/sql_queries.sql.go

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

4 changes: 0 additions & 4 deletions server/frontend/styles/_leaderboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
@include highlight-glow;
}

tr > :nth-child(2) {
max-width: 4em;
}

.week-of-code-scores {
position: relative;
font-size: 0;
Expand Down
7 changes: 3 additions & 4 deletions server/r_leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"fmt"
"math"
"net/http"
"slices"
"strings"
Expand Down Expand Up @@ -36,15 +37,14 @@ func (t leaderboardTeamPointsTable) TeamPointsTooltip(teamIx int) string {
pts := t.Points[teamIx]
vals := make([]string, len(t.Reasons))
for i, p := range pts {
vals[i] = fmt.Sprintf("%s: %.0f", t.Reasons[i], p)
vals[i] = fmt.Sprintf("%s: %.0f", t.Reasons[i], math.Floor(p))
}
return strings.Join(vals, ", ")
}

type leaderboardTeamPointsEvent struct {
TeamName string `json:"team_name"`
AddedAt time.Time `json:"added_at"`
Reason string `json:"reason"`
Points float64 `json:"points"`
}

Expand Down Expand Up @@ -150,8 +150,7 @@ func (s *Server) leaderboard(w http.ResponseWriter, r *http.Request) {
events = append(events, leaderboardTeamPointsEvent{
TeamName: row.TeamName,
AddedAt: row.AddedAt,
Reason: row.Reason,
Points: row.Points,
Points: row.Points.Float64,
})
}

Expand Down

0 comments on commit 9d02fd3

Please sign in to comment.