forked from osuripple/ripple-cron-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_pp_relax.go
74 lines (64 loc) · 1.6 KB
/
calculate_pp_relax.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"math"
"github.com/fatih/color"
)
type ppUserModeRX struct {
countScores int
ppTotal int
}
func opCalculatePPRX() {
defer wg.Done()
const ppQuery = "SELECT scores_relax.userid, pp, scores_relax.play_mode FROM scores_relax INNER JOIN users ON users.id=scores_relax.userid JOIN beatmaps USING(beatmap_md5) WHERE completed = 3 AND ranked >= 2 AND pp IS NOT NULL ORDER BY pp DESC"
rows, err := db.Query(ppQuery)
if err != nil {
queryError(err, ppQuery)
return
}
users := make(map[int]*[4]*ppUserModeRX)
var count int
for rows.Next() {
if count%1000 == 0 {
verboseln("> CalculatePPRX:", count)
}
var (
userid int
ppAmt *float64
playMode int
)
err := rows.Scan(&userid, &ppAmt, &playMode)
if err != nil {
queryError(err, ppQuery)
continue
}
if ppAmt == nil {
continue
}
if users[userid] == nil {
users[userid] = &[4]*ppUserModeRX{
new(ppUserModeRX),
new(ppUserModeRX),
new(ppUserModeRX),
new(ppUserModeRX),
}
}
if users[userid][playMode].countScores > 500 {
continue
}
currentScorePP := round(round(*ppAmt) * math.Pow(0.95, float64(users[userid][playMode].countScores)))
users[userid][playMode].countScores++
users[userid][playMode].ppTotal += int(currentScorePP)
count++
}
rows.Close()
for userid, pps := range users {
for mode, ppUM := range *pps {
op("UPDATE rx_stats SET pp_"+modeToString(mode)+" = ? WHERE id = ? LIMIT 1", ppUM.ppTotal, userid)
}
}
color.Green("> CalculatePP [RELAX]: done!")
if c.PopulateRedis {
verboseln("Starting to populate redis [RELAX]")
go opPopulateRedisRX()
}
}