processor

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CarStateOut    = "OUT"
	CarStateRun    = "RUN"
	CarStatePit    = "PIT"
	CarStateSlow   = "SLOW"
	CarStateFinish = "FIN"
	CarSlowSpeed   = 25 // a car is considered slow if it is slower than this (km/h)
)
View Source
const (
	MarkerOverallBest  = "ob"
	MarkerClassBest    = "clb"
	MarkerCarBest      = "cb"
	MarkerPersonalBest = "pb"
	MarkerOldLap       = "old"
)
View Source
const (
	INVALID   = "INVALID"
	PREP      = "PREP"
	PARADE    = "PARADE"
	GREEN     = "GREEN"
	YELLOW    = "YELLOW"
	CHECKERED = "CHECKERED"
	WHITE     = "WHITE"
)

Variables

View Source
var ErrUnknownValueWithUnit = errors.New("Unknown value with unit format")

Functions

func CarManifest

func CarManifest(gpd *GlobalProcessingData) []string

func GetMetricUnit

func GetMetricUnit(s string) (float64, error)

func GetTrackLengthInMeters

func GetTrackLengthInMeters(s string) (float64, error)

func HasDriverChange

func HasDriverChange(current, last *yaml.DriverInfo) bool

checks if relevant driver info changed we need this to detect new drivers and driver changes in team races

func MessageManifest

func MessageManifest() []string

func SessionManifest

func SessionManifest() []string

func SetSpeedmapSpeedThreshold added in v0.10.0

func SetSpeedmapSpeedThreshold(pct float64)

Types

type BestSectionProc

type BestSectionProc struct {
	// contains filtered or unexported fields
}

an argument of -1 means: don't evaluate

func NewBestSectionProc

func NewBestSectionProc(
	numSectors int,
	carClassIds, carIds []int,
	collector CollectCarLaptiming,
) *BestSectionProc

type CarData

type CarData struct {
	// contains filtered or unexported fields
}

CarData is a struct that contains the logic to process data for a single car data. Part of data is computed externally (e.g. CarProc) and passed in

func NewCarData

func NewCarData(
	carIdx int32,
	carDriverProc *CarDriverProc,
	pitBoundaryProc *PitBoundaryProc,
	gpd *GlobalProcessingData,
	reportLapStatus ReportTimingStatus,
) *CarData

func (*CarData) GetMsgData

func (cd *CarData) GetMsgData() map[string]interface{}

func (*CarData) PostProcess

func (cd *CarData) PostProcess()

func (*CarData) PreProcess

func (cd *CarData) PreProcess(api *irsdk.Irsdk)

type CarDriverProc

type CarDriverProc struct {
	// contains filtered or unexported fields
}

CarDriverProc is the main processor for managing driver and team data

func NewCarDriverProc

func NewCarDriverProc(
	api *irsdk.Irsdk,
	output chan model.CarData,
) *CarDriverProc

func (*CarDriverProc) GetCurrentDriver

func (d *CarDriverProc) GetCurrentDriver(carIdx int32) yaml.Drivers

func (*CarDriverProc) Process

func (d *CarDriverProc) Process(y *yaml.IrsdkYaml)

gets called when main processor detects new driver data

func (*CarDriverProc) SetReportChangeFunc

func (d *CarDriverProc) SetReportChangeFunc(reportChangeFunc func(carIdx int))

type CarLaptiming

type CarLaptiming struct {
	// contains filtered or unexported fields
}

func NewCarLaptiming

func NewCarLaptiming(numSectors int, reportLapStatus ReportTimingStatus) *CarLaptiming

type CarProc

type CarProc struct {
	// contains filtered or unexported fields
}

this struct is responsible for processing overall car data. this means overall standings, gaps, etc. the data for single cars is processed in CarData

func NewCarProc

func NewCarProc(
	api *irsdk.Irsdk,
	gpd *GlobalProcessingData,
	carDriverProc *CarDriverProc,
	pitBoundaryProc *PitBoundaryProc,
	speedmapProc *SpeedmapProc,
	messageProc *MessageProc,
	maxSpeed float64,
) *CarProc

func (*CarProc) CheckeredFlagIssued

func (p *CarProc) CheckeredFlagIssued()

func (*CarProc) CreatePayload

func (p *CarProc) CreatePayload() [][]interface{}

func (*CarProc) Process

func (p *CarProc) Process()

will be called every tick, we can assume to have valid data (no unexpected -1 values)

func (*CarProc) RaceStarts

func (p *CarProc) RaceStarts()

type ChunkData

type ChunkData struct {
	// contains filtered or unexported fields
}

collects speed data for a chunk of track we use this data to compute the current interval to another car

type CollectCarLaptiming

type CollectCarLaptiming func(carClassId, carId int) []*CarLaptiming

an argument of -1 means: don't evaluate

type GenericMessage

type GenericMessage map[string]interface{}

type GlobalProcessingData

type GlobalProcessingData struct {
	TrackInfo     model.TrackInfo
	EventDataInfo model.EventDataInfo
}

type MessageProc

type MessageProc struct {
	// contains filtered or unexported fields
}

func NewMessageProc

func NewMessageProc(carDriverProc *CarDriverProc) *MessageProc

func (*MessageProc) CheckeredFlagIssued

func (p *MessageProc) CheckeredFlagIssued()

func (*MessageProc) Clear

func (p *MessageProc) Clear()

func (*MessageProc) CreatePayload

func (p *MessageProc) CreatePayload() [][]interface{}

func (*MessageProc) DriverEnteredCar

func (p *MessageProc) DriverEnteredCar(carIdx int)

func (*MessageProc) RaceStarts

func (p *MessageProc) RaceStarts()

func (*MessageProc) RecordingDone

func (p *MessageProc) RecordingDone()

func (*MessageProc) ReportDriverLap

func (p *MessageProc) ReportDriverLap(carIdx int, twm TimeWithMarker)

type Options

type Options struct {
	StatePublishInterval    time.Duration
	SpeedmapPublishInterval time.Duration
	CarDataPublishInterval  time.Duration
	ChunkSize               int     // speedmap chunk size
	SpeedmapSpeedThreshold  float64 // speedmap speed threshold
	MaxSpeed                float64 // speeds above this value (km/h) are not processed
	GlobalProcessingData    *GlobalProcessingData
	RecordingDoneChannel    chan struct{}
}

type OptionsFunc

type OptionsFunc func(*Options)

functional options pattern for Options

func WithCarDataPublishInterval

func WithCarDataPublishInterval(d time.Duration) OptionsFunc

func WithChunkSize

func WithChunkSize(i int) OptionsFunc

func WithGlobalProcessingData

func WithGlobalProcessingData(gpd *GlobalProcessingData) OptionsFunc

func WithMaxSpeed added in v0.10.0

func WithMaxSpeed(f float64) OptionsFunc

func WithRecordingDoneChannel

func WithRecordingDoneChannel(c chan struct{}) OptionsFunc

func WithSpeedmapPublishInterval

func WithSpeedmapPublishInterval(d time.Duration) OptionsFunc

func WithSpeedmapSpeedThreshold added in v0.10.0

func WithSpeedmapSpeedThreshold(f float64) OptionsFunc

func WithStatePublishInterval

func WithStatePublishInterval(d time.Duration) OptionsFunc

type PitBoundaryData

type PitBoundaryData struct {
	// contains filtered or unexported fields
}

type PitBoundaryProc

type PitBoundaryProc struct {
	// contains filtered or unexported fields
}

func NewPitBoundaryProc

func NewPitBoundaryProc() *PitBoundaryProc

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor(
	api *irsdk.Irsdk,
	stateOutput chan model.StateData,
	speedmapOutput chan model.SpeedmapData,
	cardataOutput chan model.CarData,
	extraInfoOutput chan model.ExtraInfo,
	options ...OptionsFunc,
) *Processor

func (*Processor) Process

func (p *Processor) Process()

type RaceCooldown

type RaceCooldown struct{}

func (*RaceCooldown) Enter

func (rc *RaceCooldown) Enter()

func (*RaceCooldown) Exit

func (rc *RaceCooldown) Exit()

func (*RaceCooldown) Update

func (rc *RaceCooldown) Update(rp *RaceProc)

type RaceDone

type RaceDone struct{}

func (*RaceDone) Enter

func (rd *RaceDone) Enter()

func (*RaceDone) Exit

func (rd *RaceDone) Exit()

func (*RaceDone) Update

func (rd *RaceDone) Update(rp *RaceProc)

type RaceFinishing

type RaceFinishing struct{}

func (*RaceFinishing) Enter

func (rf *RaceFinishing) Enter()

func (*RaceFinishing) Exit

func (rf *RaceFinishing) Exit()

func (*RaceFinishing) Update

func (rf *RaceFinishing) Update(rp *RaceProc)

type RaceInvalid

type RaceInvalid struct{}

func (*RaceInvalid) Enter

func (ri *RaceInvalid) Enter()

func (*RaceInvalid) Exit

func (ri *RaceInvalid) Exit()

func (*RaceInvalid) Update

func (ri *RaceInvalid) Update(rp *RaceProc)

type RaceProc

type RaceProc struct {
	RaceDoneCallback func()
	// contains filtered or unexported fields
}

func NewRaceProc

func NewRaceProc(
	api *irsdk.Irsdk,
	carProc *CarProc,
	messageProc *MessageProc,
	raceDoneCallback func(),
) *RaceProc

func (*RaceProc) Process

func (rp *RaceProc) Process()

type RaceRun

type RaceRun struct{}

func (*RaceRun) Enter

func (rr *RaceRun) Enter()

func (*RaceRun) Exit

func (rr *RaceRun) Exit()

func (*RaceRun) Update

func (rr *RaceRun) Update(rp *RaceProc)

as long as we don't detect the checkered flag we stay in this state

type ReportTimingStatus

type ReportTimingStatus func(twm TimeWithMarker)

type SectionTiming

type SectionTiming struct {
	// contains filtered or unexported fields
}

type SessionProc

type SessionProc struct {
	// contains filtered or unexported fields
}

func NewSessionProc

func NewSessionProc(api *irsdk.Irsdk) *SessionProc

func (*SessionProc) CreateOutput

func (s *SessionProc) CreateOutput() GenericMessage

func (*SessionProc) CreatePayload

func (s *SessionProc) CreatePayload() []interface{}

type SpeedmapProc

type SpeedmapProc struct {
	// contains filtered or unexported fields
}

func NewSpeedmapProc

func NewSpeedmapProc(
	api *irsdk.Irsdk,
	chunkSize int,
	gpd *GlobalProcessingData,
) *SpeedmapProc

func (*SpeedmapProc) ComputeDeltaTime

func (s *SpeedmapProc) ComputeDeltaTime(
	carClassId int, trackPosCarInFront, trackPosCurrentCar float64,
) float64

func (*SpeedmapProc) CreateOutput

func (s *SpeedmapProc) CreateOutput() map[string]*model.ClassSpeedmapData

func (*SpeedmapProc) CreatePayload

func (s *SpeedmapProc) CreatePayload() model.SpeedmapPayload

func (*SpeedmapProc) Process

func (s *SpeedmapProc) Process(carData *CarData, carClassId, carId int)

func (*SpeedmapProc) SetLeaderTrackPos

func (s *SpeedmapProc) SetLeaderTrackPos(trackPos float64)

type TimeWithMarker

type TimeWithMarker struct {
	// contains filtered or unexported fields
}

func (*TimeWithMarker) String

func (t *TimeWithMarker) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL