working on the standings
This commit is contained in:
+9
-11
@@ -261,19 +261,18 @@ func (e *ESDI) telemetry() {
|
||||
lapDelta := string(lapTimeDeltaRepresentation(lapDeltaToBestLap.(float32)))
|
||||
lastLapTime := string(lapTimeRepresentation(lapLastLapTime.(float32)))
|
||||
|
||||
// Relative data
|
||||
// sessionInfoRaw, _ := e.Source.GetSessionInfo()
|
||||
// sessionInfo := sessionInfoRaw.(goirsdk.SessionInfoYAML)
|
||||
// drivers := sessionInfo.DriverInfo.Drivers
|
||||
//
|
||||
// selfID := sessionInfo.DriverInfo.DriverCarIdx
|
||||
// Standings
|
||||
standings := createStandingsTable(i, 9, relativeStandings)
|
||||
positions := i.Vars.Vars["CarIdxPosition"].Value.([]int32)
|
||||
p := positions[9]
|
||||
standings = standings[p - 3: p + 2]
|
||||
|
||||
PlayerCarPosition, err := e.Source.GetData("CarIdxPosition")
|
||||
if err != nil {
|
||||
log.Fatalf("could not get field `CarIdxPosition`: %v", err)
|
||||
fmt.Printf("\033[?25l\033[2J\033[H")
|
||||
for p, v := range standings {
|
||||
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()
|
||||
data = DataPacket{
|
||||
@@ -289,7 +288,6 @@ func (e *ESDI) telemetry() {
|
||||
FuelLiters: fuelLiters,
|
||||
FuelPct: fuelPct,
|
||||
FuelTotal: totalFuel,
|
||||
Position: selfPos,
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user