working on the standings

This commit is contained in:
2025-01-26 14:05:04 +00:00
parent 8cae215cdb
commit d767ec8d73
2 changed files with 122 additions and 12 deletions
+10 -12
View File
@@ -261,19 +261,18 @@ func (e *ESDI) telemetry() {
lapDelta := string(lapTimeDeltaRepresentation(lapDeltaToBestLap.(float32))) lapDelta := string(lapTimeDeltaRepresentation(lapDeltaToBestLap.(float32)))
lastLapTime := string(lapTimeRepresentation(lapLastLapTime.(float32))) lastLapTime := string(lapTimeRepresentation(lapLastLapTime.(float32)))
// Relative data // Standings
// sessionInfoRaw, _ := e.Source.GetSessionInfo() standings := createStandingsTable(i, 9, relativeStandings)
// sessionInfo := sessionInfoRaw.(goirsdk.SessionInfoYAML) positions := i.Vars.Vars["CarIdxPosition"].Value.([]int32)
// drivers := sessionInfo.DriverInfo.Drivers p := positions[9]
// standings = standings[p - 3: p + 2]
// selfID := sessionInfo.DriverInfo.DriverCarIdx
PlayerCarPosition, err := e.Source.GetData("CarIdxPosition") fmt.Printf("\033[?25l\033[2J\033[H")
if err != nil { for p, v := range standings {
log.Fatalf("could not get field `CarIdxPosition`: %v", err) fmt.Printf("[%2d] [%2d]%-30s %3d %10f %s\n",
} p+1, v.CarIdx, v.DriverName, v.Lap, v.LapPct, lapTimeRepresentation(v.TimeBehind))
}
selfPos := int32(PlayerCarPosition.(int))
mu.Lock() mu.Lock()
data = DataPacket{ data = DataPacket{
@@ -289,7 +288,6 @@ func (e *ESDI) telemetry() {
FuelLiters: fuelLiters, FuelLiters: fuelLiters,
FuelPct: fuelPct, FuelPct: fuelPct,
FuelTotal: totalFuel, FuelTotal: totalFuel,
Position: selfPos,
} }
mu.Unlock() mu.Unlock()
} }
+112
View File
@@ -0,0 +1,112 @@
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 {
}
}