-
Notifications
You must be signed in to change notification settings - Fork 1
/
goals-in-a-month.py
47 lines (40 loc) · 1.95 KB
/
goals-in-a-month.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import query_profiler as qp
# I couldn't find out a way to make this one quicker
attempts = [
{"query": '''MATCH (player:Player)-[:scored_in]->game<-[:in_month]-month, player-[:played]->stats-[:in]->game
WHERE player.name = "Michu"
WITH DISTINCT month, stats
WITH month, SUM(stats.goals) AS totalGoals
ORDER BY month.position
RETURN month.name, totalGoals'''},
{"query": '''MATCH (player:Player)-[:played]->stats-[:in]->game
WHERE player.name = "Michu"
WITH player, stats, game
MATCH (player)-[:scored_in]->(game)<-[:in_month]-(month)
WITH DISTINCT stats, month
WITH month, SUM(stats.goals) AS totalGoals
ORDER BY month.position
RETURN month.name, totalGoals'''},
{"query": '''MATCH (player:Player)-[:played]->stats-[:in]->game
WHERE player.name = "Michu"
WITH player, stats, game
MATCH (player)-[:scored_in]->(game)<-[:in_month]-(month)
WITH month, COLLECT(DISTINCT stats) AS allTheGames
ORDER BY month.position
RETURN month.name, REDUCE(total = 0, g in allTheGames | total + g.goals) AS totalGoals'''},
{"query": '''MATCH (player:Player)-[:played]->stats-[:in]->game
WHERE player.name = "Michu" AND stats.goals > 0
WITH player, game, stats
MATCH game<-[:in_month]-month
WITH month, SUM(stats.goals) AS totalGoals
ORDER BY month.position
RETURN month.name, totalGoals'''},
{"query": '''MATCH (player:Player)-[:played]->stats-[:in]->game
WHERE player.name = "Michu" AND stats.goals > 0
WITH player, game, stats.goals AS goals
MATCH game<-[:in_month]-month
WITH month, SUM(goals) AS totalGoals
ORDER BY month.position
RETURN month.name, totalGoals'''},
]
qp.profile(attempts, iterations=100, runs=3)