-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
393 lines (320 loc) · 11.1 KB
/
index.html
File metadata and controls
393 lines (320 loc) · 11.1 KB
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!DOCTYPE html>
<html lang="de">
<head>
<title>GT7 Real-time Dashboard</title>
<meta charset="utf-8">
</head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#laps_left_in_race {
font-size: 12em;
font-weight: bolder;
}
#fuel_needed_to_finish_race {
font-size: 6em;
font-weight: bolder;
}
.titles {
font-size: 2em;
}
table {
border-collapse: collapse;
width: 100%;
<!-- font-family: Arial, sans-serif; -->
font-size: 14px;
}
th, td {
border: 1px solid white;
text-align: center;
}
.tirerow {
border: 0;
}
body {
font-family: Arial, serif;
background-color: #222;
color: #ddd;
margin: 0;
padding: 0;
/*border-top: 40px solid white;*/
border-left: 40px solid white;
border-right: 40px solid white;
/*border-bottom: 20px solid white;*/
}
a {
color: #6cf;
}
a:hover {
color: #9cf;
}
body {
text-align: center;
}
.row {
display: flex;
align-items: center;
}
.column {
width: 33.33%;
padding: 10px;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
.stats_container {
display: flex;
}
.stats_column {
flex: 1;
margin-right: 20px; /* Optional: Abstand zwischen den Spalten */
}
/* Letzter Element in der ersten Spalte */
.stats_column:first-child {
margin-right: 0;
}
/* Stelle sicher, dass die divs sich gegenseitig in der Höhe anpassen */
.stats_container > div {
display: flex;
flex-direction: column;
}
/* Stelle sicher, dass die Inhalte der divs die verfügbare Höhe ausfüllen */
.stats_container > div > * {
flex: 1;
}
.tire-container {
display: flex;
justify-content: space-between;
align-items: center;
width: 100px; /* Adjust width as needed */
height: 200px; /* Adjust height as needed */
/*border: 1px solid black; !* Just for visualization *!*/
padding: 5px;
box-sizing: border-box;
}
.tire {
width: 150px;
height: 300px;
border-radius: 1px;
cursor: pointer; /* Make it look clickable */
}
.tire-text {
font-family: Arial, sans-serif;
font-size: 40px;
fill: white;
}
#map-container > svg {
width: 10em;
display: block;
margin: auto;
}
</style>
<body>
<div class="alert_stripe" id="alert_stripe_top"></div>
<div class="row">
<div class="column titles">
Remaining
</div>
<div class="column" id="laps_left_in_race"></div>
<div class="column titles">
Laps
</div>
</div>
<div class="row">
<div class="column titles">
Remaining fuel
</div>
<div class="column" id="fuel_needed_to_finish_race"></div>
<div class="column titles">
needed
</div>
</div>
<div class="row">
<div class="column titles">
</div>
<div class="column" id="tires"></div>
<div class="column titles">
</div>
</div>
<div class="stats_container">
<div class="stats_column">
<b>Fuel to be refilled to complete the race</b>
<div id="fuel_div"></div>
<b>Next mandatory pit stop in lap</b>
<div id="next_pit_stop"></div>
<!-- <b>Fuel needed to finish the race</b>-->
<!-- <div id="fuel_needed_to_finish_race"></div>-->
<b>Speed</b>
<div id="speed"></div>
<b>Fuel remaining</b>
<div id="fuel_left"></div>
<b>Fuel consumption last lap</b>
<div id="fuel_consumption_last_lap"></div>
<b>Average fuel consumption per lap</b>
<div id="fuel_consumption_avg"></div>
<b>Fuel consumption per minute</b>
<div id="fuel_consumption_per_minute"></div>
</div>
<div class="stats_column">
<b>Race duration</b>
<div id="race_time_in_minutes"></div>
<b>Elapsed race time</b>
<div id="time_since_start"></div>
<b>Proportional lap progress</b>
<div id="current_lap_progress_adjusted"></div>
<b>Lap time deviation</b>
<div id="lap_time_deviation"></div>
<b>Race type</b>
<div id="end_of_race_type"></div>
<b>Package ID</b>
<div id="package_id"></div>
</div>
<div class="tire-container">
<svg class="tire" viewBox="0 0 100 150">
<rect class="tire-rect" x="10" y="10" width="80" height="130" rx="15" />
<text class="tire-text" x="50" y="80" text-anchor="middle"></text>
</svg>
<svg class="tire" viewBox="0 0 100 150">
<rect class="tire-rect" x="10" y="10" width="80" height="130" rx="15" />
<text class="tire-text" x="50" y="80" text-anchor="middle"></text>
</svg>
</div>
<div class="tire-container">
<svg class="tire" viewBox="0 0 100 150">
<rect class="tire-rect" x="10" y="10" width="80" height="130" rx="15" />
<text class="tire-text" x="50" y="80" text-anchor="middle"></text>
</svg>
<svg class="tire" viewBox="0 0 100 150">
<rect class="tire-rect" x="10" y="10" width="80" height="130" rx="15" />
<text class="tire-text" x="50" y="80" text-anchor="middle"></text>
</svg>
</div>
<div id="map-container">
</div>
</div>
<p>
<a href="/static?min=120">120 min</a>
<a href="/static?min=60">60 min</a>
<a href="/static?min=20">20 min</a>
<a href="/static?min=10">10 min</a>
</p>
<div id="prerenderedhtml">
<div id="laps"></div>
</div>
<div id="error_message_container">
<div id="error_message"></div>
</div>
<script>
const dashboard = document.getElementById('dashboard');
const realtimesocket = new WebSocket('ws://localhost:9100/realtimews');
const heavysocket = new WebSocket('ws://localhost:9100/heavyws');
heavysocket.addEventListener('message', (event) => {
const data = JSON.parse(event.data);
debugger;
var laps_div = document.getElementById('laps')
laps_div.innerHTML = "";
// FIXME: Use innerhtml directly
laps_div.insertAdjacentHTML('beforeend', data.formatted_laps);
var map_div = document.getElementById('map-container')
map_div.innerHTML = data.lap_svg;
})
realtimesocket.addEventListener('message', (event) => {
const data = JSON.parse(event.data);
fuel_left.textContent = data.fuel_left + '%';
speed.textContent = data.speed + ' km/h';
package_id.textContent = data.package_id;
fuel_consumption_avg.textContent = data.fuel_consumption_avg
if (data.fuel_div > 0) {
document.body.style.background = "#011e5e";
} else {
document.body.style.background = "#033b00"
}
// console.log(data.lowest_tire_temp)
if (data.lowest_tire_temp < 0) {
document.body.style.borderColor = 'red';
} else {
document.body.style.borderColor = 'transparent';
}
time_since_start.textContent = data.time_since_start;
race_time_in_minutes.textContent = data.race_time_in_minutes + " min";
fuel_div.textContent = data.fuel_div + '%';
laps_left_in_race.textContent = data.laps_left_in_race;
fuel_consumption_last_lap.textContent = data.fuel_consumption_last_lap
fuel_needed_to_finish_race.textContent = data.fuel_needed_to_finish_race + " %";
end_of_race_type.textContent = data.end_of_race_type;
fuel_consumption_per_minute.textContent = data.fuel_consumption_per_minute;
next_pit_stop.textContent = data.next_pit_stop;
current_lap_progress_adjusted.textContent = data.current_lap_progress_adjusted;
tires.textContent = data.tires;
lap_time_deviation.textContent = data.lap_time_deviation;
topAlertStripeColor = "none";
if (!data.valid_state) {
document.body.style.background = "#947b00";
// fuel_div.textContent = "-";
// fuel_consumption_last_lap.textContent = "-";
// fuel_needed_to_finish_race.textContent = "-";
// laps_left_in_race.textContent = "-";
}
if (data.rising_trailbreaking) {
document.body.style.background = "red";
}
else if (data.tcs_active) {
document.body.style.background = "lightblue";
} else {
alert_stripe_top.textContent = "";
}
error_message.textContent = data.error_message;
var map = document.querySelectorAll("#map-container > svg")
var oldcircle = document.querySelectorAll("#map-container > svg > circle")
for (let i = 0; i < oldcircle.length; i++) {
oldcircle[i].remove()
}
if (map.length > 0) {
// container = document.getElementById( 'cont' );
var svgns = "http://www.w3.org/2000/svg";
var circle = document.createElementNS(svgns, 'circle');
circle.setAttributeNS(null, 'cx', data.position.x);
circle.setAttributeNS(null, 'cy', data.position.y);
circle.setAttributeNS(null, 'r', 15);
circle.setAttributeNS(null, 'style', 'fill: red; stroke: black; stroke-width: 1px;' );
// debugger;
map[0].appendChild(circle);
}
const tireIcons = document.querySelectorAll('.tire');
// Example temperatures in Celsius
var temperatures = data.tire_temperatures;
function changeTemperature(index, newTemperature) {
const tireText = document.querySelectorAll('.tire-text')[index];
tireText.textContent = newTemperature + '°';
}
tireIcons.forEach((tire, index) => {
const temperature = temperatures[index];
const color = temperatureColor(temperature);
changeTemperature(index,temperature);
tire.setAttribute('fill', color);
});
function temperatureColor(temperature) {
// Clamp temperature between 0 and 130
temperature = Math.max(0, Math.min(130, temperature));
// Define RGB values for blue, green, and red
const blue = [0, 0, 255]; // Full blue
const green = [0, 255, 0]; // Full green
const red = [255, 0, 0]; // Full red
let color = [];
if (temperature <= 70) {
// Interpolate between blue and green
const ratio = temperature / 70;
color = blue.map((value, index) => Math.round(value + ratio * (green[index] - value)));
} else {
// Interpolate between green and red
const ratio = (temperature - 70) / 30;
color = green.map((value, index) => Math.round(value + ratio * (red[index] - value)));
}
// Convert RGB array to CSS color format (rgb(r, g, b))
return `rgb(${color[0]}, ${color[1]}, ${color[2]})`;
}
});
</script>
</body>
</html>