-
Notifications
You must be signed in to change notification settings - Fork 0
/
formula1_dashboard.pp
310 lines (278 loc) · 6.09 KB
/
formula1_dashboard.pp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
dashboard "formula1_dashboard" {
title = "Formula 1 Dashboard"
documentation = file("./docs/formula1_dashboard.md")
container {
title = "Overview"
card {
query = query.formula1_races_count
width = 3
type = "info"
}
card {
query = query.formula1_drivers_count
width = 3
type = "info"
}
card {
query = query.formula1_costructors_count
width = 3
type = "info"
}
card {
query = query.formula1_seasons_count
width = 3
type = "info"
}
}
container {
title = "Team Performance Analysis"
chart {
title = "Team Standings by Conference"
query = query.formula1_team_standings_by_conference
type = "pie"
width = 6
}
chart {
title = "Points Per Race by Team"
query = query.formula1_points_per_race_by_team
type = "pie"
width = 6
}
}
container {
title = "Driver Statistics and Achievements"
chart {
title = "Top Scorers of the Season"
query = query.formula1_top_scorers_of_season
type = "column"
width = 6
axes {
x {
title {
value = "Driver"
}
}
y {
title {
value = "Average Points per Race"
}
}
}
}
chart {
title = "Driver Efficiency Rating (PER)"
query = query.formula1_driver_efficiency_rating
type = "bar"
width = 6
axes {
x {
title {
value = "Efficiency Rating"
}
}
y {
title {
value = "Driver"
}
}
}
}
}
container {
title = "Race Highlights and Trends"
chart {
title = "Race Scores Over Time"
query = query.formula1_race_scores_over_time
type = "line"
width = 6
axes {
x {
title {
value = "Race Dates"
}
}
y {
title {
value = "Scores"
}
}
}
}
chart {
title = "Average Attendance per Race"
query = query.formula1_average_attendance_per_game
type = "line"
width = 6
axes {
x {
title {
value = "Race Dates"
}
}
y {
title {
value = "Average Attendance"
}
}
}
}
}
container {
title = "Additional Insights"
chart {
title = "Distribution of Drivers by Nationality"
query = query.formula1_driver_nationality_distribution
type = "donut"
width = 6
}
chart {
title = "Distribution of Circuits by Location"
query = query.formula1_circuit_location_distribution
type = "donut"
width = 6
}
}
}
# Card Queries
query "formula1_races_count" {
sql = <<-EOQ
select
count(*) as "Total Races"
from
races;
EOQ
}
query "formula1_drivers_count" {
sql = <<-EOQ
select
count(distinct driverId) as "Total Drivers"
from
drivers;
EOQ
}
query "formula1_costructors_count" {
sql = <<-EOQ
select
count(distinct constructorId) as "Total Constructors"
from
constructors;
EOQ
}
query "formula1_seasons_count" {
sql = <<-EOQ
select
count(*) as "Total Seasons"
from
seasons;
EOQ
}
# Chart Queries
query "formula1_team_standings_by_conference" {
sql = <<-EOQ
select
constructors.name as "team",
count(case when position = 1 then 1 end) as "wins",
count(case when position > 1 then 1 end) as "losses"
from
constructor_standings
join constructors on constructor_standings.constructorId = constructors.constructorId
group by
constructor_standings.constructorId
order by
"wins" desc;
EOQ
}
query "formula1_points_per_race_by_team" {
sql = <<-EOQ
select constructors.name as "team",
avg(constructor_standings.points) as "average_points"
from
constructor_standings
join constructors on constructor_standings.constructorId = constructors.constructorId
group by
constructor_standings.constructorId
order by
"average_points" desc;
EOQ
}
query "formula1_top_scorers_of_season" {
sql = <<-EOQ
select concat(forename, ' ', surname) as "player",
avg(points) as "average_points_per_game"
from
driver_standings
join drivers on driver_standings.driverId = drivers.driverId
group by
driver_standings.driverId
order by
"average_points_per_game" desc
limit 5;
EOQ
}
query "formula1_driver_efficiency_rating" {
sql = <<-EOQ
select concat(forename, ' ', surname) as "player",
avg(driver_standings.points) / avg(laptimes.milliseconds) as "efficiency_rating"
from
driver_standings
join drivers on driver_standings.driverId = drivers.driverId
join laptimes on driver_standings.raceId = laptimes.raceId and driver_standings.driverId = laptimes.driverId
group by
driver_standings.driverId
order by
"efficiency_rating" desc
limit 5;
EOQ
}
query "formula1_race_scores_over_time" {
sql = <<-EOQ
select date as "date",
avg(points) as "average_scores"
from
races
join results on races.raceId = results.raceId
group by
date;
EOQ
}
query "formula1_average_attendance_per_game" {
sql = <<-EOQ
select date as "game",
avg(total_results) as "average_attendance"
from (
select
r.date, count(*) as total_results
from
races r
join results rs on r.raceId = rs.raceId
group by
r.date
) as attendance_counts
group by
date;
EOQ
}
query "formula1_driver_nationality_distribution" {
sql = <<-EOQ
select nationality as "nationality",
count(*) as "driver_count"
from
drivers
group by
nationality
order by
"driver_count" desc;
EOQ
}
query "formula1_circuit_location_distribution" {
sql = <<-EOQ
select location as "location",
count(*) as "circuit_count"
from
circuits
group by
location
order by
"circuit_count" desc;
EOQ
}