This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
forked from osuripple/ripple-cron-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fix_score_duplicates.go
84 lines (76 loc) · 1.76 KB
/
fix_score_duplicates.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
75
76
77
78
79
80
81
82
83
84
package main
import "github.com/fatih/color"
type score struct {
id int
beatmapMD5 string
userid int
score int64
maxCombo int
mods int
playMode int
accuracy float64
}
func (s score) sameAs(t score) bool {
return s.beatmapMD5 == t.beatmapMD5 &&
s.userid == t.userid &&
s.score == t.score &&
s.maxCombo == t.maxCombo &&
s.mods == t.mods &&
s.playMode == t.playMode &&
s.accuracy == t.accuracy
}
func opFixScoreDuplicates() {
defer wg.Done()
const initQuery = "SELECT id, beatmap_md5, userid, score, max_combo, mods, play_mode, accuracy FROM scores WHERE completed = '3'"
scores := []score{}
rows, err := db.Query(initQuery)
if err != nil {
queryError(err, initQuery)
return
}
for rows.Next() {
currentScore := score{}
rows.Scan(
¤tScore.id,
¤tScore.beatmapMD5,
¤tScore.userid,
¤tScore.score,
¤tScore.maxCombo,
¤tScore.mods,
¤tScore.playMode,
¤tScore.accuracy,
)
scores = append(scores, currentScore)
}
verboseln("> FixScoreDuplicates: Fetched, now finding duplicates")
// duplicate removing
remove := []int{}
var ops int64
for i := 0; i < len(scores); i++ {
if contains(remove, scores[i].id) {
continue
}
for j := i + 1; j < len(scores); j++ {
if ops%5000000 == 0 {
verboseln("> FixScoreDuplicates:", ops)
}
if scores[i].sameAs(scores[j]) && !contains(remove, scores[j].id) {
verboseln("> FixScoreDuplicates: found one!")
remove = append(remove, scores[j].id)
}
ops++
}
}
for _, v := range remove {
op("DELETE FROM scores WHERE id = ?", v)
}
color.Green("> FixScoreDuplicates: done!")
}
func contains(arr []int, i int) bool {
for _, v := range arr {
if v == i {
return true
}
}
return false
}