-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
228 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.telem | ||
todo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# ibt | ||
|
||
IRacing Telemetry parsing and processing library | ||
iRacing Telemetry parsing and processing library | ||
|
||
![ibt logo](assets/ibt_mascot.png) | ||
|
||
|
||
<!-- [![](https://img.shields.io/github/actions/workflow/status/spf13/cobra/test.yml?branch=main&longCache=true&label=Test&logo=github%20actions&logoColor=fff)](https://github.com/spf13/cobra/actions?query=workflow%3ATest) --> | ||
[![Go Reference](https://pkg.go.dev/badge/github.com/teamjorge/ibt.svg)](https://pkg.go.dev/github.com/teamjorge/ibt) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/teamjorge/ibt)](https://goreportcard.com/report/github.com/teamjorge/ibt) | ||
[![codecov](https://codecov.io/gh/teamjorge/ibt/branch/main/graph/badge.svg?token=08QVKSEPXT)](https://codecov.io/gh/teamjorge/ibt) | ||
|
@@ -13,12 +14,11 @@ | |
|
||
`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. | ||
`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 does not (yet) parse real-time as that requires opening a memory-mapped file and CGO. A planned real-time parsing package utilising this one will be available at some point. | ||
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 | ||
|
||
|
@@ -28,3 +28,27 @@ This package does not (yet) parse real-time as that requires opening a memory-ma | |
* Great test coverage and code documentation. | ||
* Freedom to use it your own way. Most of what is needed are public functions/methods. | ||
|
||
## Examples | ||
|
||
Please see the `examples` folder for detailed usage instructions. | ||
|
||
To try the examples locally, please clone to repository: | ||
|
||
```shell | ||
git clone https://github.com/teamjorge/ibt | ||
#or | ||
git clone [email protected]:teamjorge/ibt.git | ||
|
||
cd ibt | ||
``` | ||
|
||
To run the example which summarises the track temperature per lap: | ||
|
||
```shell | ||
go run examples/track_temp/main.go | ||
|
||
# Or to run it with your own telemetry files | ||
|
||
go run examples/track_temp/main.go /path/to/telem/files/*ibt | ||
``` | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
|
||
"github.com/teamjorge/ibt" | ||
"github.com/teamjorge/ibt/headers" | ||
"github.com/teamjorge/ibt/utilities" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
// Use the default testing file if no ibt files were provided | ||
// Provided files can use wildcards, for example ./telemetry/*.ibt | ||
var filePattern string | ||
if flag.Arg(0) == "" { | ||
filePattern = ".testing/valid_test_file.ibt" | ||
} else { | ||
filePattern = flag.Arg(0) | ||
} | ||
|
||
// Find all files for parsing in case it had included a wildcard | ||
files, err := filepath.Glob(filePattern) | ||
if err != nil { | ||
log.Fatalf("could not glob the given input files: %v", err) | ||
} | ||
|
||
// Parse the files into stubs | ||
stubs, err := ibt.ParseStubs(files...) | ||
if err != nil { | ||
log.Fatalf("failed to parse stubs for %v. error - %v", files, err) | ||
} | ||
|
||
// Group the stubs into iRacing sessions | ||
stubGroups := stubs.Group() | ||
|
||
for _, stubGroup := range stubGroups { | ||
for _, stub := range stubGroup { | ||
stubFile, err := os.Open(stub.Filename()) | ||
if err != nil { | ||
log.Fatalf("failed to open stub file %s for reading: %v", stub.Filename(), err) | ||
} | ||
|
||
// Create the instance(s) of your processor(s) | ||
processor := NewTrackTempProcessor() | ||
|
||
// Process the available telemetry for the ibt file. This is currently only utilising the Track Temp processor, | ||
// but can include as many as you want. | ||
if err := ibt.Process(stubFile, *stub.Headers(), processor); err != nil { | ||
log.Fatalf("failed to process telemetry for stub %s: %v", stub.Filename(), err) | ||
} | ||
|
||
// Print the summarised track temperature | ||
processor.Print() | ||
} | ||
} | ||
|
||
} | ||
|
||
type TrackTempProcessor struct { | ||
tempMap map[int]float32 | ||
} | ||
|
||
func NewTrackTempProcessor() *TrackTempProcessor { | ||
t := new(TrackTempProcessor) | ||
|
||
t.tempMap = make(map[int]float32) | ||
|
||
return t | ||
} | ||
|
||
// Display name of the processor | ||
func (t *TrackTempProcessor) Name() string { return "Track Temp" } | ||
|
||
// Method used for processing every tick of telemetry | ||
func (t *TrackTempProcessor) Process(input map[string]headers.VarHeader, hasNext bool, session *headers.Session) error { | ||
TrackTempProcessor := input["TrackTempCrew"].Value.(float32) | ||
lap := input["Lap"].Value.(int) | ||
|
||
t.tempMap[lap] = TrackTempProcessor | ||
|
||
return nil | ||
} | ||
|
||
// Utility function for create a result that can be joined with other processors. | ||
// | ||
// This will convert the results to map[int]interface{}, where the keys will refer to laps. | ||
// Result is not yet required by any interfaces, but is useful when using multiple processors | ||
// that summarise telemetry based by lap. | ||
func (t *TrackTempProcessor) Result() map[int]interface{} { | ||
return utilities.CreateGenericMap(t.tempMap) | ||
} | ||
|
||
// Columns required for the processor | ||
func (t *TrackTempProcessor) Whitelist() []string { return []string{"Lap", "TrackTempCrew"} } | ||
|
||
// Print the summarised Track Temperature | ||
func (t *TrackTempProcessor) Print() { | ||
fmt.Println("Track Temp:") | ||
laps := maps.Keys(t.tempMap) | ||
sort.Ints(laps) | ||
|
||
for _, lap := range laps { | ||
fmt.Printf("%03d - %.3f\n", lap, t.tempMap[lap]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters