Commit 27dabfaa authored by Nyo's avatar Nyo
Browse files

Add cron task to fix multiple completed 3 scores, score is now int64

parent 04685ba9
Loading
Loading
Loading
Loading
+22 −16
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ type config struct {
	CalculateOverallAccuracy   bool
	FixCompletedScores         bool `description:"Set to completed = 2 all scores on beatmaps that aren't ranked."`
	RemoveDonorOnExpired       bool
	FixMultipleCompletedScores bool `description:"Set completed=2 if multiple completed=3 scores for same beatmap and user are present."`

	LogQueries bool `description:"You don't wanna do this in prod."`
	Workers    int  `description:"The number of goroutines which should execute queries. Increasing it may make cron faster, depending on your system."`
@@ -154,7 +155,12 @@ func main() {
		go opCalculateOverallAccuracy()
		color.Green(" ok!")
	}

	if c.FixMultipleCompletedScores {
		fmt.Print("Starting fixing multiple completed scores...")
		wg.Add(1)
		go opFixMultipleCompletedScores()
		color.Green(" ok!")
	}
	wg.Wait()
	color.Green("Data elaboration has been terminated.")
	color.Green("Execution time: %.4fs", time.Now().Sub(timeAtStart).Seconds())
@@ -197,7 +203,7 @@ func queryError(err error, query string, params ...interface{}) {

func logquery(q string, params []interface{}) {
	if c.LogQueries {
		// porcodio go se sei odioso a volte
		// porcodio go se sei odioso
		a := []interface{}{
			"=>",
			q,
+58 −0
Original line number Diff line number Diff line
package main

import (
	"fmt"

	"github.com/fatih/color"
)

func opFixMultipleCompletedScores() {
	defer wg.Done()
	const initQuery = "SELECT id, userid, beatmap_md5, play_mode, score FROM scores WHERE completed = 3 ORDER BY id DESC"
	scores := []score{}
	rows, err := db.Query(initQuery)
	if err != nil {
		queryError(err, initQuery)
		return
	}
	for rows.Next() {
		currentScore := score{}
		rows.Scan(
			&currentScore.id,
			&currentScore.userid,
			&currentScore.beatmapMD5,
			&currentScore.score,
			&currentScore.playMode,
		)
		scores = append(scores, currentScore)
	}
	fmt.Println("> FixMultipleCompletedScores: Fetched, now finding bugged completed scores...")

	var ops int64
	fixed := []int{}
	for i := 0; i < len(scores); i++ {
		ops++
		if ops%1000 == 0 {
			fmt.Println("> FixMultipleCompletedScores:", ops)
		}
		if contains(fixed, scores[i].id) {
			continue
		}
		for j := i + 1; j < len(scores); j++ {
			if contains(fixed, scores[j].id) {
				continue
			}
			if (scores[j].id != scores[i].id && scores[j].beatmapMD5 == scores[i].beatmapMD5 && scores[j].userid == scores[i].userid && scores[j].playMode == scores[i].playMode) {
				fmt.Printf("> FixMultipleCompletedScores: Found duplicated completed score (%d/%d)\n", scores[i].id, duplicate.id)
				if (scores[j].score > scores[i].score) {
					op("UPDATE scores SET completed = 2 WHERE id = ?", scores[i].id)
				} else {
					op("UPDATE scores SET completed = 2 WHERE id = ?", scores[j].id)
				}
				fixed = append(fixed, scores[i].id, scores[j].id)
			}
		}
	}

	color.Green("> FixMultipleCompletedScores: done!")
}
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ type score struct {
	id         int
	beatmapMD5 string
	userid     int
	score      int
	score      int64
	maxCombo   int
	mods       int
	playMode   int