forked from JustaPenguin/assetto-server-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine_results.go
65 lines (52 loc) · 1.65 KB
/
combine_results.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
package servermanager
func combineResults(results []*SessionResults) *SessionResults {
output := &SessionResults{}
var trackName, trackConfig, championshipID, raceWeekendID string
var sessionType SessionType
for i, result := range results {
if i == 0 {
trackName = result.TrackName
trackConfig = result.TrackConfig
sessionType = result.Type
championshipID = result.ChampionshipID
raceWeekendID = result.RaceWeekendID
} else {
if result.TrackName != trackName || result.TrackConfig != trackConfig || result.Type != sessionType {
// don't merge results from multiple tracks/layouts, or different session types
continue
}
if result.ChampionshipID == championshipID {
// if all from one championship keep the ID
output.ChampionshipID = championshipID
} else {
// if not, clear it completely
output.ChampionshipID = ""
}
if result.RaceWeekendID == raceWeekendID {
// if all from one race weekend keep the ID
output.RaceWeekendID = raceWeekendID
} else {
// if not, clear it completely
output.RaceWeekendID = ""
}
}
output.TrackName = trackName
output.TrackConfig = trackConfig
output.Type = sessionType
output.Date = result.Date
output.SessionFile = result.SessionFile
cars:
for _, car := range result.Cars {
for _, existingCar := range output.Cars {
if existingCar.GetGUID() == car.GetGUID() && existingCar.GetCar() == car.GetCar() {
// car already added, skip
continue cars
}
}
output.Cars = append(output.Cars, car)
}
output.Events = append(output.Events, result.Events...)
output.Laps = append(output.Laps, result.Laps...)
}
return output
}