Skip to content

Recorded runs

Every run can be saved with all its raw samples (accelerometer and GPS) plus the result. With that you can compute the times again whenever you want: on another phone, on your server or in an automated test.

When finished arrives, ask the session for the recording and turn it into JSON:

let run = session.recording(device: "iPhone16,1", app: "MyApp 1.0")
let data = try run.encoded() // the torke.run JSON
try data.write(to: url)

A quarter-mile run weighs about 200 KB. Use the .torkerun.json extension.

let run = try TorkeRun.decode(data)
let result = run.analyze() // the times again
let start = run.startLocation // where it launched

RecordedRunProvider feeds a recorded run to a session as if it were the sensors. It’s for tests, demos and reproducing a bug someone reported.

let session = RunSession()
session.arm()
await session.run(with: RecordedRunProvider(run)) // as fast as possible
session.start(with: RecordedRunProvider(run, speed: 1)) // in real time, for a demo

The simulated run (RecordedRunProvider.demo()) always gives the same numbers. Use it to pin your app’s behavior:

func testDemoRun() async throws {
let session = RunSession()
session.arm()
await session.run(with: RecordedRunProvider.demo())
let r = try XCTUnwrap(session.snapshot.result)
XCTAssertEqual(r.quarterMile!, 12.826, accuracy: 0.001)
}

The repositories ship sample runs in Fixtures/. Both platforms read them in their tests and must get the same numbers:

demo-42.torkerun.json

The simulated car. Times equal to half a millisecond.

launch.torkerun.json

A launch with altitudes, weather and a 4-link.

rolling / braking

A 60–130 km/h rolling run and a 100–0 stop.

phase2-expected.json

The expected results for weather, suspension, quality and power.

Every field is described in torke.run format.