From 437d5a7cb72fc8a7e67edc68d044f28357334d29 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 18 Feb 2020 14:14:47 +0000 Subject: [PATCH 1/3] improved fallback sorting to deal with some new extreme cases --- championships.go | 4 +++ go.mod | 1 + results.go | 76 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/championships.go b/championships.go index 8561b7cfb..ebac23b5f 100644 --- a/championships.go +++ b/championships.go @@ -1032,6 +1032,8 @@ func (c *ChampionshipClass) standings(events []*ChampionshipEvent, givePoints fu continue } + fmt.Println(fmt.Sprintf("Give %.2f points to: %s", float64(points.PolePosition)*pointsMultiplier, driver.DriverName)) + givePoints(event, driver.DriverGUID, float64(points.PolePosition)*pointsMultiplier, PointsPolePosition) } @@ -1123,6 +1125,8 @@ func (c *ChampionshipClass) Standings(inEvents []*ChampionshipEvent) []*Champion c.standings(events, func(event *ChampionshipEvent, driverGUID string, points float64, reason PointsReason) { var car *SessionCar + // @TODO CHECK THIS + for _, sessionType := range championshipStandingSessionOrder { session, ok := event.Sessions[sessionType] diff --git a/go.mod b/go.mod index ee82e01a1..a0e25dab6 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d // indirect github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 // indirect + github.com/davecgh/go-spew v1.1.1 github.com/dimchansky/utfbom v1.1.0 github.com/dustin/go-humanize v1.0.0 github.com/etcd-io/bbolt v1.3.3 diff --git a/results.go b/results.go index c42876da1..4ed5ed93d 100644 --- a/results.go +++ b/results.go @@ -376,7 +376,7 @@ cars: var bestLap int for y := range s.Laps { - if (s.Cars[i].Driver.GUID == s.Laps[y].DriverGUID) && s.IsDriversFastestLap(s.Cars[i].Driver.GUID, s.Cars[i].Model, s.Laps[y].LapTime, s.Laps[y].Cuts) { + if (s.Cars[i].Driver.GUID == s.Laps[y].DriverGUID) && (s.Cars[i].Model == s.Laps[y].CarModel) && s.IsDriversFastestLap(s.Cars[i].Driver.GUID, s.Cars[i].Model, s.Laps[y].LapTime, s.Laps[y].Cuts) { bestLap = s.Laps[y].LapTime break } @@ -398,6 +398,41 @@ cars: }) } +laps: + // in the crazy case that a driver has laps but is in neither car or results list + for _, lap := range s.Laps { + for _, result := range s.Result { + if result.DriverGUID == lap.DriverGUID { + continue laps + } + } + + bestLap := 0 + + for _, findBestLap := range s.Laps { + if (findBestLap.DriverGUID == lap.DriverGUID) && (findBestLap.CarModel == lap.CarModel) && s.IsDriversFastestLap(findBestLap.DriverGUID, findBestLap.CarModel, findBestLap.LapTime, findBestLap.Cuts) { + bestLap = findBestLap.LapTime + break + } + } + + s.Result = append(s.Result, &SessionResult{ + BallastKG: lap.BallastKG, + BestLap: bestLap, + CarID: lap.CarID, + CarModel: lap.CarModel, + DriverGUID: lap.DriverGUID, + DriverName: lap.DriverName, + Restrictor: lap.Restrictor, + TotalTime: 0, + HasPenalty: false, + PenaltyTime: 0, + LapPenalty: 0, + Disqualified: false, + ClassID: lap.ClassID, + }) + } + for i := range s.Result { s.Result[i].TotalTime = 0 @@ -410,6 +445,45 @@ cars: if s.Result[i].HasPenalty { s.Result[i].TotalTime += int(s.Result[i].PenaltyTime.Seconds()) } + + if s.Result[i].BestLap == 0 { + for _, findBestLap := range s.Laps { + if (findBestLap.DriverGUID == s.Result[i].DriverGUID) && (findBestLap.CarModel == s.Result[i].CarModel) && s.IsDriversFastestLap(findBestLap.DriverGUID, findBestLap.CarModel, findBestLap.LapTime, findBestLap.Cuts) { + s.Result[i].BestLap = findBestLap.LapTime + break + } + } + } + } + +results: + // is this result car in the car list? If not then add it + for _, result := range s.Result { + for _, car := range s.Cars { + if result.DriverGUID == car.Driver.GUID && result.CarModel == car.Model { + continue results + } + } + + guidList := []string{result.DriverGUID} + + driver := SessionDriver{ + GUID: result.DriverGUID, + GuidsList: guidList, + Name: result.DriverName, + Nation: "", + Team: "", + ClassID: result.ClassID, + } + + s.Cars = append(s.Cars, &SessionCar{ + BallastKG: result.BallastKG, + CarID: result.CarID, + Driver: driver, + Model: result.CarModel, + Restrictor: result.Restrictor, + Skin: "", + }) } sort.Slice(s.Result, func(i, j int) bool { From b6d013fb6831dc6b62dd169443f604c666fb1fe2 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 18 Feb 2020 14:16:52 +0000 Subject: [PATCH 2/3] removed test prints --- championships.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/championships.go b/championships.go index ebac23b5f..8561b7cfb 100644 --- a/championships.go +++ b/championships.go @@ -1032,8 +1032,6 @@ func (c *ChampionshipClass) standings(events []*ChampionshipEvent, givePoints fu continue } - fmt.Println(fmt.Sprintf("Give %.2f points to: %s", float64(points.PolePosition)*pointsMultiplier, driver.DriverName)) - givePoints(event, driver.DriverGUID, float64(points.PolePosition)*pointsMultiplier, PointsPolePosition) } @@ -1125,8 +1123,6 @@ func (c *ChampionshipClass) Standings(inEvents []*ChampionshipEvent) []*Champion c.standings(events, func(event *ChampionshipEvent, driverGUID string, points float64, reason PointsReason) { var car *SessionCar - // @TODO CHECK THIS - for _, sessionType := range championshipStandingSessionOrder { session, ok := event.Sessions[sessionType] From c17a9543bf4267dc3d8d53910c47a24a920ba552 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 18 Feb 2020 16:21:56 +0000 Subject: [PATCH 3/3] go mod tidy --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index a0e25dab6..ee82e01a1 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/cznic/b v0.0.0-20181122101859-a26611c4d92d // indirect github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect github.com/cznic/strutil v0.0.0-20181122101858-275e90344537 // indirect - github.com/davecgh/go-spew v1.1.1 github.com/dimchansky/utfbom v1.1.0 github.com/dustin/go-humanize v1.0.0 github.com/etcd-io/bbolt v1.3.3