Add daily run rankings
This commit is contained in:
1 parent
71889f7daa
commit
ff98047caa
7 files changed
+168
-111
No files matched your search
+27
@@ -1,5 +1,9 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/Flashfyre/pokerogue-server/defs"
|
||||
)
|
||||
|
||||
func TryAddDailyRun(seed string) error {
|
||||
_, err := handle.Exec("INSERT INTO dailyRuns (seed, date) VALUES (?, UTC_DATE()) ON DUPLICATE KEY UPDATE date = date", seed)
|
||||
if err != nil {
|
||||
@@ -8,3 +12,26 @@ func TryAddDailyRun(seed string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetRankings() ([]defs.DailyRanking, error) {
|
||||
var rankings []defs.DailyRanking
|
||||
|
||||
results, err := handle.Query("SELECT RANK() OVER (ORDER BY sc.score DESC, sc.timestamp), a.username, sc.score FROM seedCompletions sc JOIN dailyRuns dr ON dr.seed = sc.seed JOIN accounts a ON sc.uuid = a.uuid WHERE dr.date = UTC_DATE()")
|
||||
if err != nil {
|
||||
return rankings, err
|
||||
}
|
||||
|
||||
defer results.Close()
|
||||
|
||||
for results.Next() {
|
||||
ranking := defs.DailyRanking{}
|
||||
err = results.Scan(&ranking.Rank, &ranking.Username, &ranking.Score)
|
||||
if err != nil {
|
||||
return rankings, err
|
||||
}
|
||||
|
||||
rankings = append(rankings, ranking)
|
||||
}
|
||||
|
||||
return rankings, nil
|
||||
}
|
||||
Reference in new issue
Block a user