MotoGp Graph Gist
These queries are my first attempts at Cypher and using Neo4j, I am just begining my journey so if you can identify ways to improve the queries then please post a comment to help me improve.
OK with that out of the way where did I begin? I love bike racing and thought the interrelated domains of championships, circuits, riders and teams would be a great place to start. I thought it would be cool to come up with a model that allowed to me to extrapolate bizarre facts from this years MotoGP championship (just in case anyone asked me to commentate on a upcoming race).
What sort of facts would I want to dazzle people with?
-
What is the total race distance for the year?
-
Which is the longest race?
-
When they arrive at Sachsenring what is the total race distance left this season?
-
When they leave Silverstone how many right turns have they raced around?
With this as an initial target I could begin by creating the following model and queries:

What is the total race distance for the year?
MATCH (r:Race)-[:HELD_AT]->(c:Circuit)
RETURN sum(r.laps * c.length) AS TotalRaceDistance
Which is the longest race?
MATCH (r:Race)-[:HELD_AT]->(c:Circuit)
RETURN c.name AS LongestRace
ORDER BY r.laps * c.length DESC
LIMIT 1
When they leave Sachsenring what is the total race distance left this season?
MATCH (c1:Circuit)<-[:HELD_AT]-(r:Race)-[:AFTER*1..10]->()-[:HELD_AT]->(c2:Circuit)
WHERE c2.name = 'Sachsenring'
RETURN SUM(r.laps * c1.length) + "km" AS RaceDistanceRemaining
When they leave Silverstone how many right turns have they raced around?
MATCH(c1:Circuit)<-[HELD_AT]-(r1:Race)<-[:AFTER]-(r2:Circuit)
WHERE c1.name = 'Silverstone'
WITH r2
MATCH (r2)<-[:BEFORE*]-(r3)-[:HELD_AT]->(c3)
RETURN SUM(r3.laps * c3.right) AS TotalRightTurns
Not bad but not the most exciting model! So lets throw caution to the wind, add in some riders, teams and bikes with some data for the first five places in each race so far and see what we can figure out from there.

Now I’d like to be able to derive from the results data available which manufacturer produces the best bike for going left. I’d like to perform some function of points allocation based on race results and number of left turns per race. Unfortunately I’ve run out of time, this is where I’ve got too.
MATCH (b)<-[:RUN]-()<-[:RIDES_FOR]-()<-[]-(r:Race)-[:HELD_AT]->(c:Circuit)
WITH b, c
RETURN c.name, c.left, COLLECT(b.manufacturer)
ORDER BY c.left DESC
If you can help I’d very much appreciate some pointers and advice. I’m enjoying my first steps with Neo4j and Graph Gists are an excellent way to get started without requiring the boilerplate setup that can be off putting.
There’s a huge amount of statistics out there for motogp and I’ll be taking this further as I continue to learn Neo4j.
Thanks for reading this far!
Is this page helpful?