ibt

package module
v0.0.0-...-5f50fa1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

ibt

iRacing Telemetry parsing and processing library

ibt logo

Go Reference Go Report Card codecov

Install

go get github.com/teamjorge/ibt

Overview

ibt is a package from parsing iRacing telemetry files. An ibt file is created when you enter the car and ends when you exit the car. By default, you can find these files in your iRacing/telemetry/[car]/ directory. These files are binary for the most part, with the exception of the session data.

This package will not parse real-time telemetry as that requires opening a memory-mapped file and CGO. A planned real-time parsing package leverage ibt will be available in the future.

Features

  • Easy to use telemetry tick processing interface.
  • Quick parsing of file metadata.
  • Grouping of ibt files into the sessions where they originate from.
  • Great test coverage and code documentation.
  • Freedom to use it your own way. Most functions/methods has been made public.

Examples

The Examples directory houses all of the available examples.

To try these examples locally, please clone to repository:

git clone https://github.com/teamjorge/ibt
#or
git clone git@github.com:teamjorge/ibt.git

Please have a look at the instructions in the examples README for details on how to run each example.

Documentation

Index

Constants

View Source
const (
	// Number of times the setup has been modified
	UPDATE_COUNT_FIELD_NAME string = "UpdateCount"
)

Variables

This section is empty.

Functions

func CloseAllStubs

func CloseAllStubs(groups []StubGroup) error

func DiscardSetupItems

func DiscardSetupItems[k comparable](setupItems map[CarSetupKey]k, filters ...SetupFilter) map[CarSetupKey]k

DiscardSetupItems removes the given categories, subcategories, and/or items.

func FilterSetupItems

func FilterSetupItems[k comparable](setupItems map[CarSetupKey]k, filters ...SetupFilter) map[CarSetupKey]k

FilterSetupItems for only the given categories, subcategories, and items.

func GetTickValue

func GetTickValue[T TickValueType](tick Tick, key string) (T, error)

GetTickValue will retrieve and type assert the given variable.

func Process

func Process(ctx context.Context, stubs StubGroup, processors ...Processor) error

Types

type CarSetup

type CarSetup struct {
	Name   string
	Update int
	Values CarSetupDetails
}

CarSetup is the overarching structure to represent the setup of a car.

func ParseCarSetup

func ParseCarSetup(sessionInfo *headers.Session) *CarSetup

ParseCarSetup from the given session info

type CarSetupComparison

type CarSetupComparison map[CarSetupKey]*CarSetupComparisonItem

CarSetupComparison is the overarching structure for storing the difference between two CarSetups.

func CompareSetups

func CompareSetups(s1, s2 *CarSetup) CarSetupComparison

CompareSetups will compare the differences between the two given setups

func (CarSetupComparison) Differences

Differences between the two CarSetups that were compared

type CarSetupComparisonItem

type CarSetupComparisonItem struct {
	I1 *CarSetupItem
	I2 *CarSetupItem

	NumericalDifferences []float64
	RawDifference        string
	// contains filtered or unexported fields
}

CarSetupComparisonItem is the comparison of a single item from the two compared setups

func CompareSetupItemParsedValue

func CompareSetupItemParsedValue(i1, i2 *CarSetupItem) CarSetupComparisonItem

CompareSetupItemParsedValue compares the parsed values of each setup item.

If a parsed item is not found in one or either of the items, the raw value comparison will be the only populated field

type CarSetupDetails

type CarSetupDetails map[CarSetupKey]*CarSetupItem

CarSetupDetails is the structure for storing the individual items that make up a car setup.

Example: The front right tyre pressure for the given setup will be 128 PSI.

func (CarSetupDetails) Add

func (s CarSetupDetails) Add(category, subcategory, itemName string, value *CarSetupItem)

Add a new setup item for the specified category and subcategory

type CarSetupItem

type CarSetupItem struct {
	RawValue string
	Parsed   []CarSetupItemParsedValue
}

CarSetupItem is the raw and parsed values of a single car setup item.

func (*CarSetupItem) IsParsed

func (c *CarSetupItem) IsParsed() bool

IsParsed determines if the given CarSetupItem has any parsed numerical values

type CarSetupItemParsedValue

type CarSetupItemParsedValue struct {
	NumericalValue  float64
	NumericalSign   int
	MeasurementUnit string
}

CarSetupItemParsedValue is a detailed numerical value of a single car setup item.

Parsed items will refer only to numerical values. Additionally, the sign of the numeric value will be preserved for cases where + / - is applicable. For example, some cars might have +3 clicks of wing, rather than just 3 clicks.

func ParseSetupItem

func ParseSetupItem(input string) []CarSetupItemParsedValue

ParseSetupItem attempts to parse a numerical value from the given setup item.

This function returns a slice due to some setup items consisting of multiple values.

For example: Tire pressures will contain 3 independent values for inner, outer, and carcass temperatures.

type CarSetupKey

type CarSetupKey string

CarSetupKey refers to the map key used when storing CarSetupItems.

A CarSetupKey should ideally be created using the NewCarSetupKey function. This eliminates any risk with deconstructing it to find specific values, such as category, subcategory, and item name.

This key consists of the category, subcategory and item name.

For example:

Category |    SubCategory  |  Item Name

DriveBrake|BrakeSystemConfig|BaseBrakeBias

func NewCarSetupKey

func NewCarSetupKey(category, subcategory, itemName string) CarSetupKey

NewCarSetupKey initialises a new CarSetupKey value

func (CarSetupKey) Category

func (csk CarSetupKey) Category() string

Category part of the given CarSetupKey

func (CarSetupKey) ItemName

func (csk CarSetupKey) ItemName() string

ItemName part of the given CarSetupKey

func (CarSetupKey) SubCategory

func (csk CarSetupKey) SubCategory() string

SubCategory part of the given CarSetupKey

type CarSetupKeys

type CarSetupKeys []CarSetupKey

CarSetupKeys are multiple CarSetupKey values

This structure primarily exists for sorting purposes

func (CarSetupKeys) Len

func (a CarSetupKeys) Len() int

func (CarSetupKeys) Less

func (a CarSetupKeys) Less(i, j int) bool

func (CarSetupKeys) Swap

func (a CarSetupKeys) Swap(i, j int)

type Parser

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

Parser is used to iterate and process telemetry variables for a given ibt file and it's headers.

func NewParser

func NewParser(reader headers.Reader, header *headers.Header, whitelist ...string) *Parser

NewParser creates a new parser from a given ibt file, it's headers, and a variable whitelist.

reader - Opened ibt file.

header - Parsed headers of ibt file.

whitelist - Variables to process. For example, "gear", "speed", "rpm" etc. If no values or a single value of "*" is received, all variables will be processed.

func (*Parser) Next

func (p *Parser) Next() (Tick, bool)

Next parses and returns the next tick of telemetry variables and whether it can be called again.

A return of false will indicate that the buffer has reached the end. If the buffer has reached the end and Next() is called again, a nil and false will be returned. Additionally, a check can be done to check if the returned Tick is nil to determine if the EOF was reached.

Should expected variable values be missing, please ensure that they are added to the Parser whitelist.

func (*Parser) ParseAt

func (p *Parser) ParseAt(offset int) Tick

ParseAt the given buffer offset and return a processed tick.

ParseAt is useful if a specific offset is known. An example would be the telemetry variable buffers that are provided during live telemetry parsing.

When nil is returned, the buffer has reached EOF.

func (*Parser) Seek

func (p *Parser) Seek(iter int)

Seek the parser to a specific tick within the ibt file.

func (*Parser) UpdateWhitelist

func (p *Parser) UpdateWhitelist(whitelist ...string)

UpdateWhitelist replaces the current whitelist with the given fields

type Processor

type Processor interface {
	Process(input Tick, hasNext bool, session *headers.Session) error
	Whitelist() []string
}

type SetupFilter

type SetupFilter struct {
	Category    string
	SubCategory string
	ItemName    string
}

SetupFilter is used to filter a CarSetup or CarSetupComparison for specific categories, subcategories and/or items.

Prefixes can be used instead of specifying full categories, subcategories, and/or item names.

Fields that are not populated will be ignored during equality checks.

func (SetupFilter) Compare

func (s SetupFilter) Compare(key CarSetupKey) bool

Compare determines if SetupFilter contains all of the populated filter fields

type Stub

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

Stub represents the headers and filename parsed from an ibt file.

Stubs are used for initial parsing of ibt files and their metadata. This can be useful to make decisions regarding which files should have their telemetry parsed.

func (Stub) CarSetup

func (stub Stub) CarSetup() *CarSetup

CarSetup for the given stub

func (*Stub) Close

func (stub *Stub) Close() error

Close the stub reader

func (*Stub) DriverIdx

func (stub *Stub) DriverIdx() int

DriverIdx is the index of the current driver.

This value is useful when parsing telemetry or session info where the index of the driver is required.

func (*Stub) Filename

func (stub *Stub) Filename() string

Filename where the stub originated from

func (*Stub) Headers

func (stub *Stub) Headers() *headers.Header

Headers that were parsed when the stub was created

func (*Stub) Open

func (stub *Stub) Open() (err error)

Open the underlying ibt file for reading

func (*Stub) Time

func (stub *Stub) Time() time.Time

Time when the stub was created

type StubGroup

type StubGroup []Stub

StubGroup is a grouping of stubs.

This group is not necessarily part of the same session, but can be grouped with Group().

func ParseStubs

func ParseStubs(files ...string) (StubGroup, error)

ParseStubs will create a stub for each of the given files by parsing their headers.

func (StubGroup) Close

func (sg StubGroup) Close() error

Close the reader for every stub in the group

func (StubGroup) Group

func (stubs StubGroup) Group() []StubGroup

Group stubs together by their iRacing session.

The process for grouping is slightly different for official and test sessions. Official sessions can utilise the SubSessionID, whereas Test sessions use the ResultsPosition field to determine the start/end of a session.

func (StubGroup) Len

func (a StubGroup) Len() int

func (StubGroup) Less

func (a StubGroup) Less(i, j int) bool

func (StubGroup) Swap

func (a StubGroup) Swap(i, j int)

type StubGroupGrouping

type StubGroupGrouping []StubGroup

StubGroupGrouping is just a group of StubGroups.

func (StubGroupGrouping) Len

func (a StubGroupGrouping) Len() int

func (StubGroupGrouping) Less

func (a StubGroupGrouping) Less(i, j int) bool

func (StubGroupGrouping) Swap

func (a StubGroupGrouping) Swap(i, j int)

type Tick

type Tick map[string]interface{}

Tick is a single instance of telemetry data

func (Tick) Filter

func (t Tick) Filter(whitelist ...string) Tick

Filter the tick for only the given whitelisted fields

type TickValueType

type TickValueType interface {
	uint8 | []uint8 | bool | []bool | int | []int | string | []string | float32 | []float32 | float64 | []float64
}

TickValueType is an interface containing all possible types for the value of a telemetry variable

Directories

Path Synopsis
Package headers provides the utilities for parsing and interacting with the ibt header objects.
Package headers provides the utilities for parsing and interacting with the ibt header objects.
fifo
Package fifo provides FIFO (First In, First Out) fixed-size storage structures.
Package fifo provides FIFO (First In, First Out) fixed-size storage structures.

Jump to

Keyboard shortcuts

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