Skip to content

Instantly share code, notes, and snippets.

@oliverfoggin
Forked from abd2017/Neo4jF1.adoc
Last active August 29, 2015 13:57
Show Gist options
  • Save oliverfoggin/9559095 to your computer and use it in GitHub Desktop.
Save oliverfoggin/9559095 to your computer and use it in GitHub Desktop.

Roller Derby MMR test doc

As a roller derby ref I love looking at the stats.

I put this together to teach myself Neo4j a bit but also to get some decent stats out of a practise game.

Node Types

  • Skater: All of the skaters

    • Properties: Name and number.

  • Team: The two teams

    • Properties: Name.

  • Jam: Each individual Jam

    • Properties: Number.

  • Penalty Type: The penalty types received during the game

    • Properties: Name

  • Penalty: The penalties received

Relations

  • (Skater)-[:BELONGS_TO]→(Team)

  • (Skater)-[:JAMMED_IN {points:number, lead:boolean}]→(Jam)

  • (Skater)-[:RECEIVED]→(Penalty)

  • (Penalty)-[:IS_A]→(PenaltyType)

  • (Penalty)-[:HAPPENED_DURING]→(Jam)

  • (Skater)-[:JAMMED_WITH]→(Skater)

//skaters
CREATE (s0:Skater { name:"Frodo Bashins", number:"0" }),
(s7:Skater { name:"Ella Storey", number:"7" }),
(s86:Skater { name:"Terri Sudron", number:"86" }),
(s87:Skater { name:"Lolly Go-Sprightly", number:"87" }),
(s10:Skater { name:"Nomi-Wan Kenobi", number:"10" }),
(s1605:Skater { name:"Gunpowder Dot", number:"1605" }),
(s1up:Skater { name:"The Little Grr-maid", number:"1UP" }),
(s22:Skater { name:"Swede Dreams", number:"22" }),
(s28:Skater { name:"Darcey Hustle", number:"28" }),
(s55:Skater { name:"Moose", number:"55" }),
(s69:Skater { name:"Dynamite Stix", number:"69" }),
(s81:Skater { name:"Bounking Betty", number:"81" }),
(s16:Skater { name:"Grindin Nemo", number:"17" }),
(s57:Skater { name:"Lexi Palmer", number:"57" }),
(s13:Skater { name:"Ruby Bruiseday", number:"13" }),
(sno1:Skater { name:"Public Emily", number:"NO1" }),
(s31:Skater { name:"Killennium Falcon", number:"31" }),
(s47:Skater { name:"O'Cruel", number:"47" }),
(s14:Skater { name:"Mead", number:"14" }),
(s21:Skater { name:"Hulk Grogan", number:"21" }),
(s26:Skater { name:"Kim Cognito", number:"26" }),
//jams
(j1:Jam {number:1}),
(j2:Jam {number:2}),
(j3:Jam {number:3}),
(j4:Jam {number:4}),
(j5:Jam {number:5}),
(j6:Jam {number:6}),
(j7:Jam {number:7}),
(j8:Jam {number:8}),
(j9:Jam {number:9}),
(j10:Jam {number:10}),
(j11:Jam {number:11}),
(j12:Jam {number:12}),
(j13:Jam {number:13}),
(j14:Jam {number:14}),
(j15:Jam {number:15}),
(j16:Jam {number:16}),
(j17:Jam {number:17}),
//teams
(teamWhite:Team {name:"White"}),
(teamBlack:Team {name:"Black"}),
//(skater)-[:BELONGS_TO]->(team)
//black
(s81)-[:BELONGS_TO]->(teamBlack),
(s13)-[:BELONGS_TO]->(teamBlack),
(s57)-[:BELONGS_TO]->(teamBlack),
(s86)-[:BELONGS_TO]->(teamBlack),
(s28)-[:BELONGS_TO]->(teamBlack),
(s31)-[:BELONGS_TO]->(teamBlack),
(s1up)-[:BELONGS_TO]->(teamBlack),
(s14)-[:BELONGS_TO]->(teamBlack),
(s0)-[:BELONGS_TO]->(teamBlack),
//white
(s21)-[:BELONGS_TO]->(teamWhite),
(s69)-[:BELONGS_TO]->(teamWhite),
(s16)-[:BELONGS_TO]->(teamWhite),
(s87)-[:BELONGS_TO]->(teamWhite),
(s22)-[:BELONGS_TO]->(teamWhite),
(s1605)-[:BELONGS_TO]->(teamWhite),
(s26)-[:BELONGS_TO]->(teamWhite),
(s47)-[:BELONGS_TO]->(teamWhite),
//(skater)-[:JAMMED_IN {lead:boolean}]->(jam),
//white
(s87)-[:JAMMED_IN {lead:FALSE, points:0}]->(j1),
(s69)-[:JAMMED_IN {lead:FALSE, points:0}]->(j2),
(s87)-[:JAMMED_IN {lead:FALSE, points:2}]->(j3),
(s47)-[:JAMMED_IN {lead:FALSE, points:0}]->(j4),
(s87)-[:JAMMED_IN {lead:TRUE, points:8}]->(j5),
(s47)-[:JAMMED_IN {lead:FALSE, points:0}]->(j6),
(s47)-[:JAMMED_IN {lead:FALSE, points:0}]->(j7),
(s47)-[:JAMMED_IN {lead:FALSE, points:0}]->(j8),
(s87)-[:JAMMED_IN {lead:TRUE, points:3}]->(j9),
(s22)-[:JAMMED_IN {lead:TRUE, points:1}]->(j10),
(s87)-[:JAMMED_IN {lead:TRUE, points:4}]->(j11),
(s47)-[:JAMMED_IN {lead:TRUE, points:0}]->(j12),
(s87)-[:JAMMED_IN {lead:FALSE, points:0}]->(j13),
(s47)-[:JAMMED_IN {lead:FALSE, points:0}]->(j14),
(s87)-[:JAMMED_IN {lead:TRUE, points:3}]->(j15),
(s47)-[:JAMMED_IN {lead:TRUE, points:5}]->(j16),
(s87)-[:JAMMED_IN {lead:TRUE, points:4}]->(j17),
//black,
(s86)-[:JAMMED_IN {lead:TRUE, points:3}]->(j1),
(s86)-[:JAMMED_IN {lead:TRUE, points:9}]->(j2),
(s0)-[:JAMMED_IN {lead:TRUE, points:2}]->(j3),
(s86)-[:JAMMED_IN {lead:TRUE, points:5}]->(j4),
(s13)-[:JAMMED_IN {lead:FALSE, points:0}]->(j5),
(s1up)-[:JAMMED_IN {lead:TRUE, points:15}]->(j6),
(s14)-[:JAMMED_IN {lead:TRUE, points:12}]->(j7),
(s57)-[:JAMMED_IN {lead:TRUE, points:10}]->(j8),
(s0)-[:JAMMED_IN {lead:FALSE, points:0}]->(j9),
(s86)-[:JAMMED_IN {lead:FALSE, points:2}]->(j10),
(s31)-[:JAMMED_IN {lead:FALSE, points:0}]->(j11),
(s57)-[:JAMMED_IN {lead:FALSE, points:1}]->(j12),
(s13)-[:JAMMED_IN {lead:TRUE, points:2}]->(j13),
(s0)-[:JAMMED_IN {lead:TRUE, points:13}]->(j14),
(s86)-[:JAMMED_IN {lead:FALSE, points:0}]->(j15),
(s1up)-[:JAMMED_IN {lead:FALSE, points:0}]->(j16),
(s14)-[:JAMMED_IN {lead:FALSE, points:0}]->(j17),
//penalties
//types,
(cutTrack:PenaltyType {name:"Cut Track"}),
(lowBlock:PenaltyType {name:"Low Block"}),
(backBlock:PenaltyType {name:"Back Block"}),
(forearms:PenaltyType {name:"Forearms"}),
(oobBlock:PenaltyType {name:"Out-of-bounds Block"}),
(skatingOOB:PenaltyType {name:"Skating Out-of-bounds"}),
//penalties
//(skater)-[:RECEIVED]->(penalty)
//(penalty)-[:IS_A]->(penaltyType)
//(penalty)-[:HAPPENED_DURING]->(jam)
(s57)-[:RECEIVED]->(penalty1:Penalty)-[:IS_A]->(cutTrack),
(penalty1)-[:HAPPENED_DURING]->(j3),
(s57)-[:RECEIVED]->(penalty2:Penalty)-[:IS_A]->(lowBlock),
(penalty2)-[:HAPPENED_DURING]->(j14),
(s57)-[:RECEIVED]->(penalty3:Penalty)-[:IS_A]->(cutTrack),
(penalty3)-[:HAPPENED_DURING]->(j17),
(s86)-[:RECEIVED]->(penalty4:Penalty)-[:IS_A]->(backBlock),
(penalty4)-[:HAPPENED_DURING]->(j7),
(s1up)-[:RECEIVED]->(penalty5:Penalty)-[:IS_A]->(cutTrack),
(penalty5)-[:HAPPENED_DURING]->(j16),
(s21)-[:RECEIVED]->(penalty6:Penalty)-[:IS_A]->(oobBlock),
(penalty6)-[:HAPPENED_DURING]->(j7),
(s69)-[:RECEIVED]->(penalty7:Penalty)-[:IS_A]->(skatingOOB),
(penalty7)-[:HAPPENED_DURING]->(j6),
(s47)-[:RECEIVED]->(penalty8:Penalty)-[:IS_A]->(lowBlock),
(penalty8)-[:HAPPENED_DURING]->(j1),
(s47)-[:RECEIVED]->(penalty9:Penalty)-[:IS_A]->(cutTrack),
(penalty9)-[:HAPPENED_DURING]->(j6),
(s47)-[:RECEIVED]->(penalty10:Penalty)-[:IS_A]->(lowBlock),
(penalty10)-[:HAPPENED_DURING]->(j6),
(s47)-[:RECEIVED]->(penalty11:Penalty)-[:IS_A]->(cutTrack),
(penalty11)-[:HAPPENED_DURING]->(j7),
(s47)-[:RECEIVED]->(penalty12:Penalty)-[:IS_A]->(forearms),
(penalty12)-[:HAPPENED_DURING]->(j14),
//(skater)-[:BLOCKED_IN]->(jam)
//white
(s21)-[:BLOCKED_IN]->(j1),
(s69)-[:BLOCKED_IN]->(j1),
(s22)-[:BLOCKED_IN]->(j1),
(s1605)-[:BLOCKED_IN]->(j1),
(s47)-[:BLOCKED_IN]->(j2),
(s26)-[:BLOCKED_IN]->(j2),
(s1605)-[:BLOCKED_IN]->(j2),
(s21)-[:BLOCKED_IN]->(j2),
(s21)-[:BLOCKED_IN]->(j3),
(s26)-[:BLOCKED_IN]->(j3),
(s22)-[:BLOCKED_IN]->(j3),
(s69)-[:BLOCKED_IN]->(j3),
(s1605)-[:BLOCKED_IN]->(j4),
(s69)-[:BLOCKED_IN]->(j4),
(s22)-[:BLOCKED_IN]->(j4),
(s87)-[:BLOCKED_IN]->(j4),
(s47)-[:BLOCKED_IN]->(j5),
(s1605)-[:BLOCKED_IN]->(j5),
(s21)-[:BLOCKED_IN]->(j5),
(s26)-[:BLOCKED_IN]->(j5),
(s1605)-[:BLOCKED_IN]->(j6),
(s22)-[:BLOCKED_IN]->(j6),
(s69)-[:BLOCKED_IN]->(j6),
(s87)-[:BLOCKED_IN]->(j6),
(s22)-[:BLOCKED_IN]->(j7),
(s21)-[:BLOCKED_IN]->(j7),
(s69)-[:BLOCKED_IN]->(j7),
(s87)-[:BLOCKED_IN]->(j7),
(s1605)-[:BLOCKED_IN]->(j8),
(s22)-[:BLOCKED_IN]->(j8),
(s26)-[:BLOCKED_IN]->(j8),
(s16)-[:BLOCKED_IN]->(j8),
(s1605)-[:BLOCKED_IN]->(j9),
(s21)-[:BLOCKED_IN]->(j9),
(s69)-[:BLOCKED_IN]->(j9),
(s26)-[:BLOCKED_IN]->(j9),
(s21)-[:BLOCKED_IN]->(j10),
(s69)-[:BLOCKED_IN]->(j10),
(s87)-[:BLOCKED_IN]->(j10),
(s26)-[:BLOCKED_IN]->(j10),
(s22)-[:BLOCKED_IN]->(j11),
(s21)-[:BLOCKED_IN]->(j11),
(s47)-[:BLOCKED_IN]->(j11),
(s16)-[:BLOCKED_IN]->(j11),
(s1605)-[:BLOCKED_IN]->(j12),
(s69)-[:BLOCKED_IN]->(j12),
(s87)-[:BLOCKED_IN]->(j12),
(s26)-[:BLOCKED_IN]->(j12),
(s22)-[:BLOCKED_IN]->(j13),
(s21)-[:BLOCKED_IN]->(j13),
(s47)-[:BLOCKED_IN]->(j13),
(s16)-[:BLOCKED_IN]->(j13),
(s1605)-[:BLOCKED_IN]->(j14),
(s69)-[:BLOCKED_IN]->(j14),
(s26)-[:BLOCKED_IN]->(j14),
(s16)-[:BLOCKED_IN]->(j14),
(s1605)-[:BLOCKED_IN]->(j15),
(s21)-[:BLOCKED_IN]->(j15),
(s69)-[:BLOCKED_IN]->(j15),
(s26)-[:BLOCKED_IN]->(j15),
(s1605)-[:BLOCKED_IN]->(j16),
(s22)-[:BLOCKED_IN]->(j16),
(s69)-[:BLOCKED_IN]->(j16),
(s26)-[:BLOCKED_IN]->(j16),
(s1605)-[:BLOCKED_IN]->(j17),
(s21)-[:BLOCKED_IN]->(j17),
(s47)-[:BLOCKED_IN]->(j17),
(s16)-[:BLOCKED_IN]->(j17),
//black
(s81)-[:BLOCKED_IN]->(j1),
(s13)-[:BLOCKED_IN]->(j1),
(s57)-[:BLOCKED_IN]->(j1),
(s1up)-[:BLOCKED_IN]->(j1),
(s81)-[:BLOCKED_IN]->(j2),
(s57)-[:BLOCKED_IN]->(j2),
(s28)-[:BLOCKED_IN]->(j2),
(s1up)-[:BLOCKED_IN]->(j2),
(s13)-[:BLOCKED_IN]->(j3),
(s57)-[:BLOCKED_IN]->(j3),
(s31)-[:BLOCKED_IN]->(j3),
(s14)-[:BLOCKED_IN]->(j3),
(s81)-[:BLOCKED_IN]->(j4),
(s28)-[:BLOCKED_IN]->(j4),
(s1up)-[:BLOCKED_IN]->(j4),
(s0)-[:BLOCKED_IN]->(j4),
(s57)-[:BLOCKED_IN]->(j5),
(s28)-[:BLOCKED_IN]->(j5),
(s31)-[:BLOCKED_IN]->(j5),
(s1up)-[:BLOCKED_IN]->(j5),
(s81)-[:BLOCKED_IN]->(j6),
(s86)-[:BLOCKED_IN]->(j6),
(s31)-[:BLOCKED_IN]->(j6),
(s0)-[:BLOCKED_IN]->(j6),
(s13)-[:BLOCKED_IN]->(j7),
(s57)-[:BLOCKED_IN]->(j7),
(s14)-[:BLOCKED_IN]->(j7),
(s0)-[:BLOCKED_IN]->(j7),
(s81)-[:BLOCKED_IN]->(j8),
(s86)-[:BLOCKED_IN]->(j8),
(s28)-[:BLOCKED_IN]->(j8),
(s31)-[:BLOCKED_IN]->(j8),
(s81)-[:BLOCKED_IN]->(j9),
(s13)-[:BLOCKED_IN]->(j9),
(s28)-[:BLOCKED_IN]->(j9),
(s31)-[:BLOCKED_IN]->(j9),
(s81)-[:BLOCKED_IN]->(j10),
(s57)-[:BLOCKED_IN]->(j10),
(s1up)-[:BLOCKED_IN]->(j10),
(s0)-[:BLOCKED_IN]->(j10),
(s13)-[:BLOCKED_IN]->(j11),
(s28)-[:BLOCKED_IN]->(j11),
(s1up)-[:BLOCKED_IN]->(j11),
(s14)-[:BLOCKED_IN]->(j11),
(s81)-[:BLOCKED_IN]->(j12),
(s86)-[:BLOCKED_IN]->(j12),
(s1up)-[:BLOCKED_IN]->(j12),
(s0)-[:BLOCKED_IN]->(j12),
(s81)-[:BLOCKED_IN]->(j13),
(s86)-[:BLOCKED_IN]->(j13),
(s28)-[:BLOCKED_IN]->(j13),
(s31)-[:BLOCKED_IN]->(j13),
(s13)-[:BLOCKED_IN]->(j14),
(s57)-[:BLOCKED_IN]->(j14),
(s31)-[:BLOCKED_IN]->(j14),
(s14)-[:BLOCKED_IN]->(j14),
(s81)-[:BLOCKED_IN]->(j15),
(s57)-[:BLOCKED_IN]->(j15),
(s28)-[:BLOCKED_IN]->(j15),
(s1up)-[:BLOCKED_IN]->(j15),
(s13)-[:BLOCKED_IN]->(j16),
(s28)-[:BLOCKED_IN]->(j16),
(s31)-[:BLOCKED_IN]->(j16),
(s0)-[:BLOCKED_IN]->(j16),
(s81)-[:BLOCKED_IN]->(j17),
(s13)-[:BLOCKED_IN]->(j17),
(s57)-[:BLOCKED_IN]->(j17),
(s86)-[:BLOCKED_IN]->(j17)

Score by Team

First query, who won?

MATCH (team:Team)<--(Skater)-[r:JAMMED_IN]-()
RETURN team.name AS Name, SUM(r.points) AS Score
ORDER BY Score DESC

Points by jammer

Who was the highest scoring jammer

MATCH (jammer:Skater)-[r:JAMMED_IN]->(), (jammer)-->(team:Team)
RETURN jammer.name AS Name, team.name as Team, SUM(r.points) AS Score
ORDER BY Score DESC

Create partnerships between jammers and blockers

Create partnerships between jammers and their blockers and store the total scores.

MATCH (jammer:Skater)-[r:JAMMED_IN]->(jam)<-[:BLOCKED_IN]-(blocker:Skater)
CREATE UNIQUE (jammer)-[p:JAMMED_WITH { score:0 }]->(blocker)
SET p.score = p.score + r.points

Report the highest scoring partnerships

Which jammers and blocker were most effective together…​ or something.

MATCH (jammer:Skater)-[p:JAMMED_WITH]->(blocker:Skater)
RETURN jammer.name AS Jammer, blocker.name AS Blocker, p.score AS Score
ORDER BY p.score DESC

Penalties by type

Which skaters are getting which penalties?

MATCH (penaltyType:PenaltyType)<--(penalty:Penalty)<--(skater:Skater)
RETURN skater.name AS Skater, penaltyType.name AS Penalty, COUNT(penaltyType) AS Count

Penalties

How many penalties in total? Did anyone foul out?

MATCH (penalty:Penalty)<--(skater:Skater)
RETURN skater.name AS Skater, COUNT(penalty) AS Count
ORDER BY Count DESC

That’s it.

Just messing around to see what I can do and it’s late now so leaving it here. Might mess around a bit tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment