package main import ( "fmt" "sort" "testing" ) type StandingsLine struct { CarIdx int LapPct float32 Lap int32 DriverName string EstTime float32 TimeBehind float32 } type standingsFilter func([]StandingsLine, []float32, int) func generalStandings(s []StandingsLine, estTime []float32, id int) { // This will give the delta to the guy ahead // P1 0:00:000 // P2 0:01:000 -> 1s from P1 // P3 0:01:000 -> 1s from P2 for p := range s { theirEstimate := estTime[s[p].CarIdx] var theThing float32 = 0.0 if p != id { theThing = estTime[s[p-1].CarIdx] - theirEstimate } s[p].TimeBehind = theThing } } func relativeStandings(s []StandingsLine, estTime []float32, id int) { // Get the delta to a given carId for p := range s { curCarEstimate := estTime[s[p].CarIdx] var delta float32 = 0.0 delta = abs(estTime[id] - curCarEstimate) s[p].TimeBehind = delta } } func bestLapTime(i GameSource, id int) float32 { best := i.Vars.Vars["LapBestLapTime"].Value.(float32) if best > 0 { return best } return float32(i.SessionInfo.DriverInfo.Drivers[id].CarClassEstLapTime) } // createStandingsTable will create a table with the standings data // still working on this // If the filter applied is generalStandings, the carId has to be 0 // We can do some dynamicProgramming on this thing I guess, I still haven't // though about it much yet tbh func createStandingsTable(i GameSource, carId int, filter standingsFilter) []StandingsLine { driversLapDistPct := i.Vars.Vars["CarIdxLapDistPct"].Value.([]float32) driversEstTime := i.Vars.Vars["CarIdxEstTime"].Value.([]float32) driversLap := i.Vars.Vars["CarIdxLap"].Value.([]int32) drivers := i.SessionInfo.DriverInfo.Drivers standings := make([]StandingsLine, len(drivers)) for k := range len(drivers) { if drivers[k].CarIsPaceCar == 1 || drivers[k].IsSpectator == 1 || drivers[k].UserName == "" { continue } if driversLap[k] == -1 || drivers[k].UserName == "" { continue } standings[k] = StandingsLine{ CarIdx: k, LapPct: driversLapDistPct[k], DriverName: drivers[k].UserName, EstTime: driversEstTime[k], Lap: driversLap[k], TimeBehind: 0, } } // This will sort our standings by lap and LapPct sort.Slice(standings, func(i int, j int) bool { if standings[i].Lap == int32(standings[j].Lap) { return standings[i].LapPct > standings[j].LapPct } return standings[i].Lap > standings[j].Lap }) filter(standings, driversEstTime, carId) return standings } func abs(v float32) float32 { if v < 0 { v = v * -1 } return v } func TestStandingsFunctionality(t *testing.T) { for { } }