-
Notifications
You must be signed in to change notification settings - Fork 2
/
initial_diff_calc_eyup.go
91 lines (69 loc) · 2.85 KB
/
initial_diff_calc_eyup.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
85
86
87
88
89
90
91
package main
import (
"Waffle/database"
"Waffle/helpers"
"fmt"
"io"
"log"
"os"
"time"
"github.com/Waffle-osu/osu-parser/osu_parser"
"github.com/Waffle-osu/waffle-pp/difficulty"
)
type BeatmapProcessQueryResult struct {
BeatmapId int32
BeatmapSetId int32
Filename string
Playmode byte
}
func InitialDiffCalcEyup() {
//Setup Logger
filename := fmt.Sprintf("logs/%d-log-eyup_initial_calc.txt", time.Now().Unix())
file, fileErr := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if fileErr != nil {
panic(fileErr)
}
multiWriter := io.MultiWriter(file, os.Stdout)
logger := log.New(multiWriter, "Difficulty Calc (eyup): ", log.LstdFlags|log.Lshortfile)
allMapsNotInDiffTableSql := `
SELECT beatmap_id, beatmapset_id, filename, playmode FROM beatmaps WHERE beatmap_id NOT IN (
SELECT beatmap_id FROM osu_beatmap_difficulty
)
`
startTime := time.Now()
mapsQuery, mapsQueryErr := database.Database.Query(allMapsNotInDiffTableSql)
if mapsQueryErr != nil {
logger.Fatalf("Could not query maps for processing... %s\n", mapsQueryErr.Error())
}
insertMap := func(beatmapId int32, setId int32, filename string, eyupStars float64, playmode byte) {
_, insertErr := database.Database.Exec("INSERT INTO osu_beatmap_difficulty (beatmap_id, beatmapset_id, mode, eyup_stars) VALUES (?, ?, ?, ?)", beatmapId, setId, playmode, eyupStars)
if insertErr != nil {
logger.Printf("Failed to insert b: %d; s: %d; m: %d", beatmapId, setId, playmode)
} else {
logger.Printf("[%d %s %s]: %.2f", beatmapId, filename, helpers.FormatPlaymodes(playmode), eyupStars)
}
}
for mapsQuery.Next() {
queryResult := BeatmapProcessQueryResult{}
scanErr := mapsQuery.Scan(&queryResult.BeatmapId, &queryResult.BeatmapSetId, &queryResult.Filename, &queryResult.Playmode)
if scanErr != nil {
logger.Fatalf("Failed to scan! %s\n", scanErr.Error())
}
parsedFile, parseErr := osu_parser.ParseFile(fmt.Sprintf("osus/%s", queryResult.Filename))
if parseErr != nil {
logger.Printf("Failed to parse %s\n", queryResult.Filename)
}
eyupStars := difficulty.CalculateEyupStars(parsedFile)
if queryResult.Playmode == 0 {
//Write all 4 modes, since osu! converts exist
insertMap(queryResult.BeatmapId, queryResult.BeatmapSetId, queryResult.Filename, eyupStars, 0)
insertMap(queryResult.BeatmapId, queryResult.BeatmapSetId, queryResult.Filename, eyupStars, 1)
insertMap(queryResult.BeatmapId, queryResult.BeatmapSetId, queryResult.Filename, eyupStars, 2)
insertMap(queryResult.BeatmapId, queryResult.BeatmapSetId, queryResult.Filename, eyupStars, 3)
} else {
//only write the mode, since for other modes converts dont exist
insertMap(queryResult.BeatmapId, queryResult.BeatmapSetId, queryResult.Filename, eyupStars, queryResult.Playmode)
}
}
logger.Printf("Took %.2f seconds for entire diffcalc", time.Since(startTime).Seconds())
}