robschmitt / motogp-analysis-parser
Parses the lap-by-lap Analysis PDFs published for MotoGP sessions into structured data.
Package info
github.com/robschmitt/motogp-analysis-parser
pkg:composer/robschmitt/motogp-analysis-parser
Requires
- php: ^8.2
- spatie/pdf-to-text: ^1.54
Requires (Dev)
- phpunit/phpunit: ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP library that turns the Analysis PDF published after each MotoGP session into structured data: every rider, every run with its tyres, and every lap with its four sector times and top speed.
It was written for MotoTiming.live, where it parsed 1,098 sessions from 2020 to 2026.
It isn’t affiliated with MotoGP or MSEG.
Requirements
- PHP 8.2 or later
pdftotextfrom Poppler (brew install poppleron a Mac,apt install poppler-utilson Debian or Ubuntu)
Installation
composer require robschmitt/motogp-analysis-parser
Usage
use RobSchmitt\MotoGpAnalysis\AnalysisParser; use RobSchmitt\MotoGpAnalysis\PdfTextExtractor; $pdf = file_get_contents('https://resources.motogp.com/files/results/2026/VAL/MotoGP/RAC/Analysis.pdf'); file_put_contents('/tmp/analysis.pdf', $pdf); $text = (new PdfTextExtractor())->extract('/tmp/analysis.pdf'); $riders = (new AnalysisParser())->parse($text);
If pdftotext isn’t on your PATH, pass its location: new PdfTextExtractor('/opt/homebrew/bin/pdftotext').
What you get back
An array of riders, in the order they appear in the PDF:
{
"name": "Marco BEZZECCHI",
"manufacturer": null,
"country": null,
"position": "1st",
"number": 72,
"team": null,
"total_runs": 1,
"runs": [
{
"run": 1,
"front_tyre_compound": "Slick-Soft",
"front_tyre_age": "New Tyre",
"rear_tyre_compound": "Slick-Medium",
"rear_tyre_age": "New Tyre",
"laps": [
{
"lap": 1,
"lap_time": 91.525,
"cancelled": false,
"pit_lane": false,
"unfinished": false,
"t1": 19.498,
"t2": 25.838,
"t3": 22.193,
"t4": 23.996,
"speed": 334.3
}
]
}
]
}
- Lap and sector times are in seconds, and speed is in km/h. Any of them can be
nullwhen the PDF leaves it blank. cancelledis a lap cancelled for an infringement (marked*in the PDF),pit_lanea lap that ended in the pit lane (markedP), andunfinisheda lap the rider didn’t complete.- Tyre compounds and ages are the PDF’s own wording.
Two things the parser leaves to you
Team, manufacturer and country are always null. The parser reads only each rider’s name, number and position. MotoTiming filled in the rest from the session’s classification, matched on rider number.
A rider’s number can come back as 0. On some pages the column break falls between a rider’s position and their number. The parser still finds the rider and their laps, and sets the number to 0 and the position to null. MotoTiming matched these riders to the classification by surname.
Tests
composer install
composer test
The tests include seven real sessions in tests/fixtures/analysis: the text of each PDF beside the riders, runs and laps it should produce. They’re there to catch a change that breaks parsing of a real page. The expected files also hold team, manufacturer and country, filled in by MotoTiming; the tests don’t check those.
tests/fixtures/split holds the 2021 Austrian GP race as pdftotext 24.02 prints it, with some lap lines split across two lines, to check the extractor puts them back together.
Licence
MIT. See LICENSE.