demo-42.torkerun.json
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.
Saving
Section titled “Saving”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 JSONtry data.write(to: url)val run = session.recording(device = Build.MODEL, app = "MyApp 1.0")val json = run.encode() // the torke.run JSONfile.writeText(json)A quarter-mile run weighs about 200 KB. Use the .torkerun.json extension.
Analyzing again
Section titled “Analyzing again”let run = try TorkeRun.decode(data)let result = run.analyze() // the times againlet start = run.startLocation // where it launchedval run = TorkeRun.decode(json)val result = run.analyze() // the times againval start = run.startLocation // where it launchedReplaying
Section titled “Replaying”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 possiblesession.start(with: RecordedRunProvider(run, speed: 1)) // in real time, for a demoval session = RunSession()session.arm()session.run(RecordedRunProvider(run)) // as fast as possiblesession.start(RecordedRunProvider(run, speed = 1.0), scope) // in real time, for a demoAutomated tests
Section titled “Automated tests”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)}@Test fun demoRun() = runTest { val session = RunSession() session.arm() session.run(RecordedRunProvider.demo()) val r = session.snapshot.value.result!! assertEquals(12.826, r.quarterMile!!, 0.001)}Reference files
Section titled “Reference files”The repositories ship sample runs in Fixtures/. Both platforms read them in their tests and must get the same numbers:
launch.torkerun.json
rolling / braking
phase2-expected.json
Every field is described in torke.run format.