-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
355 lines (304 loc) · 15.4 KB
/
index.html
File metadata and controls
355 lines (304 loc) · 15.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>RoadToStrategy - Calculator</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background: #0b0b0d; color: #eee; }
h1 { text-align: center; }
label { display: block; margin-top: 10px; }
input, select { margin-top: 5px; padding: 6px; width: 260px; }
input[type="number"] { -moz-appearance:textfield; }
button { margin-top: 15px; padding: 10px 20px; cursor: pointer; }
table { border-collapse: collapse; margin-top: 20px; width: 100%; background: #121216; }
th, td { border: 1px solid #333; padding: 8px; text-align: center; }
th { background: #1b1b1f; }
.stint-row { background: #19191d; font-style: italic; }
.info-row { background: #101014; font-size: 12px; font-style: italic; color:#ccc; }
.highlight-row { background: #25254a; font-size: 14px; font-weight: bold; color:#fff; }
.controls { display:flex; gap:20px; flex-wrap:wrap; }
.control { min-width:260px; }
.warning { color: #ffd1a8; }
.btn-step { background:#222; color:#fff; border:none; cursor:pointer; padding:2px 6px; margin:0 2px; }
.endurance-panel { background:#19191d; padding:12px; margin-top:12px; }
.drivers-grid { display:grid; grid-template-columns: repeat(2,1fr); gap:10px; }
.driver-input { background:#121216; padding:8px; }
.driver-label { font-size:13px; margin-bottom:6px; display:block; }
.driver-warning { color:#ffd1a8; margin-left:6px; font-weight:bold; }
.driver-select { width:160px; padding:6px; }
</style>
</head>
<body>
<h1>RoadToStrategy - Interactive Strategy Calculator</h1>
<div class="controls">
<div class="control">
<label>Max Fuel per Lap (L): <input id="fuelPerLap" type="number" step="0.01" value="2.70"></label>
<label>Average Lap Time (sec): <input id="avgLapTime" type="number" value="90"></label>
<label>Race Duration (hours): <input id="raceDuration" type="number" step="0.1" value="1.0"></label>
</div>
<div class="control">
<label>Tank Capacity (L): <input id="tankCapacity" type="number" value="100"></label>
<label>Pit Stop Time (sec): <input id="pitTime" type="number" value="25"></label>
<label>Stint Timer Limit (minutes): <input id="stintTimer" type="number" value="65"></label>
</div>
<div class="control">
<label>Formation Lap:
<select id="formationLap">
<option value="none">None</option>
<option value="short">Short</option>
<option value="full">Full</option>
</select>
</label>
<label>Race Start Time (HH:MM): <input id="raceStartTime" type="time" value="12:00"></label>
<button onclick="calculateStrategy()">Calculate</button>
</div>
</div>
<!-- Endurance Mode -->
<div style="margin-top:12px;">
<label>
<input type="checkbox" id="enduranceMode" onchange="toggleEndurance(this.checked)">
Enable Endurance Mode (assign drivers)
</label>
<div id="endurancePanel" class="endurance-panel" style="display:none;">
<div class="warning">Enter up to 8 drivers (Name + Avg Lap Time in sec).</div>
<div class="drivers-grid" id="driversGrid"></div>
<div style="margin-top:10px;">
<button onclick="calculateStrategy()">Recalculate with Endurance</button>
</div>
</div>
</div>
<div id="results"></div>
<script>
const DRIVER_COUNT = 8;
let manualAdjustments = {};
let assignments = {};
let stintTimerSecGlobal = 0;
let globalMaxFuelPerLap = 0;
let globalFormationLaps = 0;
let globalFormationTime = 0;
function fmtTime(date) {
return date.getHours().toString().padStart(2,'0') + ':' +
date.getMinutes().toString().padStart(2,'0') + ':' +
date.getSeconds().toString().padStart(2,'0');
}
function fmtHMS(totalSec) {
let h = Math.floor(totalSec / 3600);
let m = Math.floor((totalSec % 3600) / 60);
let s = Math.floor(totalSec % 60);
return `${h.toString().padStart(2,'0')}:${m.toString().padStart(2,'0')}:${s.toString().padStart(2,'0')}`;
}
function toSeconds(val){ return Math.max(0, Number(val) || 0); }
// Driver inputs
function createDriverInputs(){
const grid = document.getElementById('driversGrid');
grid.innerHTML = '';
for(let i=1;i<=DRIVER_COUNT;i++){
const div = document.createElement('div');
div.className = 'driver-input';
div.innerHTML = `
<label class="driver-label">Driver ${i}</label>
<input id="driverName-${i}" placeholder="Name" type="text">
<input id="driverLap-${i}" placeholder="Avg Lap (sec)" type="number" style="margin-top:6px;">
`;
grid.appendChild(div);
}
}
createDriverInputs();
function toggleEndurance(on){
const panel = document.getElementById('endurancePanel');
panel.style.display = on ? 'block' : 'none';
if(!on){ assignments = {}; }
}
function getDrivers(){
const drivers = [];
for(let i=1;i<=DRIVER_COUNT;i++){
const name = (document.getElementById(`driverName-${i}`)?.value || '').trim();
const lap = parseFloat(document.getElementById(`driverLap-${i}`)?.value);
drivers.push({
index: i,
name: name || `Driver ${i}`,
avgLap: isNaN(lap) ? null : Number(lap)
});
}
return drivers;
}
// Simulation
function simulateGreedy(opts) {
const { raceStart, raceEndTime, avgLapTime, tankCapacity, maxFuelPerLap,
pitTime, stintTimerSec, formationLaps, formationTime,
fuelFactor, strategy, drivers } = opts;
let rows = [];
let pitstops = 0;
let currentTime = new Date(raceStart.getTime() + formationTime * 1000);
let lapsCompleted = 0;
let stintIndex = 0;
let finished = false;
if (!assignments[strategy]) assignments[strategy] = {};
if (!manualAdjustments[strategy]) manualAdjustments[strategy] = {};
while (!finished) {
stintIndex++;
let assignedDriverIndex = assignments[strategy][stintIndex];
let lapSecondsForStint = avgLapTime;
if (assignedDriverIndex) {
const drv = drivers.find(d => d.index === assignedDriverIndex);
if (drv && drv.avgLap) lapSecondsForStint = drv.avgLap;
}
let margin = (strategy === "safe" ? 30 : 0); // 30s Sicherheitsreserve nur bei Safe
let maxPossible = Math.min(
Math.floor((stintTimerSec - (stintIndex === 1 ? formationTime : 0) - margin) / lapSecondsForStint),
Math.floor(tankCapacity / (maxFuelPerLap * fuelFactor))
);
if (maxPossible < 1) maxPossible = 1;
let lapsThisStint = maxPossible;
if (manualAdjustments[strategy][stintIndex]) {
lapsThisStint = manualAdjustments[strategy][stintIndex] - lapsCompleted;
if (lapsThisStint < 1) lapsThisStint = 1;
}
let stintSeconds = lapsThisStint * lapSecondsForStint;
if (stintIndex === 1) stintSeconds += formationTime;
let stintEndTime = new Date(currentTime.getTime() + stintSeconds * 1000);
let willFinish = false;
if (stintEndTime > raceEndTime) {
const lapsUntilEnd = Math.floor((raceEndTime - currentTime) / (lapSecondsForStint * 1000)) + 1;
lapsThisStint = Math.max(1, Math.min(lapsThisStint, lapsUntilEnd));
stintSeconds = lapsThisStint * lapSecondsForStint + (stintIndex === 1 ? formationTime : 0);
stintEndTime = new Date(currentTime.getTime() + stintSeconds * 1000);
willFinish = true;
}
const fuelThisStint = (lapsThisStint * maxFuelPerLap * fuelFactor) + (stintIndex === 1 ? formationLaps * maxFuelPerLap : 0);
rows.push({
stintIndex,
lapsEnd: lapsCompleted + lapsThisStint,
stintEndTime,
fuelThisStint,
lapsThisStint,
stintSeconds,
remark: willFinish ? 'Finished' : `+ Pitstop (+${pitTime}s)`,
assignedDriverIndex,
finished: willFinish
});
lapsCompleted += lapsThisStint;
if (willFinish) {
finished = true;
break;
}
pitstops++;
currentTime = new Date(stintEndTime.getTime() + pitTime * 1000);
}
const totalTime = (rows.length > 0) ? (rows[rows.length-1].stintEndTime - raceStart)/1000 : 0;
return { rows, pitstops, totalTime };
}
// Rendering
function renderPlan(title, plan, strategy, maxFuelPerLap, drivers) {
let html = `<h2>${title}</h2>`;
html += `<table><tr><th>Stop #</th><th>In lap</th><th>Adjust</th><th>Time</th><th>Fuel Stint</th><th>Laps</th><th>Duration</th><th>Driver</th><th>Remark</th></tr>`;
// Start Fuel Zeile
const firstStint = plan.rows[0];
if (firstStint) {
const startFuel = firstStint.fuelThisStint;
html += `<tr class='highlight-row'><td colspan='9'>🚦 Start Fuel: ${startFuel.toFixed(1)} L (inkl. Formation Lap), Max Fuel/Lap = ${globalMaxFuelPerLap.toFixed(2)} L</td></tr>`;
}
plan.rows.forEach((r, idx)=>{
if (r.finished) {
html += `<tr class='highlight-row'><td colspan='9'>🏁 Finished after lap ${r.lapsEnd} at ${fmtTime(r.stintEndTime)}</td></tr>`;
} else {
let selectId = `${strategy}-driver-${r.stintIndex}`;
let assigned = assignments[strategy][r.stintIndex];
let selectHtml = `<select id="${selectId}" class="driver-select" onchange="assignDriver('${strategy}',${r.stintIndex}, this.value)"><option value="">—</option>`;
drivers.forEach(d=>{
const isSelected = (assigned && Number(assigned) === d.index) ? ' selected' : '';
selectHtml += `<option value="${d.index}"${isSelected}>${d.name}${d.avgLap ? ' ('+d.avgLap+'s)':''}</option>`;
});
selectHtml += `</select>`;
const warningMark = assigned ? '' : `<span class="driver-warning">⚠️</span>`;
let stintWarn = "";
if (r.stintSeconds > stintTimerSecGlobal) {
stintWarn = " ⛔";
} else if (stintTimerSecGlobal - r.stintSeconds < 60) {
stintWarn = " ⚠️";
}
// Fuel für nächsten Stint (falls vorhanden)
let fuelNext = (idx+1 < plan.rows.length) ? plan.rows[idx+1].fuelThisStint.toFixed(1) : "—";
html+=`<tr><td>${r.stintIndex}</td>`+
`<td id='${strategy}-lapsEnd-${r.stintIndex}'>${r.lapsEnd}</td>`+
`<td><button class='btn-step' onclick='adjustLaps("${strategy}",${r.stintIndex},1)'>▲</button><button class='btn-step' onclick='adjustLaps("${strategy}",${r.stintIndex},-1)'>▼</button></td>`+
`<td>${fmtTime(r.stintEndTime)}</td><td>${fuelNext}</td><td>${r.lapsThisStint}</td><td>${fmtHMS(r.stintSeconds)}</td>`+
`<td>${selectHtml} ${warningMark}</td><td>${r.remark}${stintWarn}</td></tr>`;
html += `<tr class='info-row'><td colspan='9'>Stint ${r.stintIndex} info → Max Fuel/Lap = ${globalMaxFuelPerLap.toFixed(2)} L</td></tr>`;
}
});
html += `<tr class='stint-row'><td colspan='9'>Summary: Stints = ${plan.rows.length}, Pitstops = ${plan.pitstops}, Total time = ${fmtHMS(plan.totalTime)}</td></tr>`;
html += `</table>`;
return html;
}
function calculateStrategy() {
const maxFuelPerLap = parseFloat(document.getElementById('fuelPerLap').value);
const avgLapTimeInput = toSeconds(document.getElementById('avgLapTime').value);
const raceDuration = parseFloat(document.getElementById('raceDuration').value);
const tankCapacity = parseFloat(document.getElementById('tankCapacity').value);
const pitTime = parseFloat(document.getElementById('pitTime').value);
const stintTimer = parseFloat(document.getElementById('stintTimer').value);
const formationLap = document.getElementById('formationLap').value;
const raceStartTime = document.getElementById('raceStartTime').value;
let raceStart = new Date();
if (raceStartTime) {
const [hh, mm] = raceStartTime.split(":").map(x=>parseInt(x,10));
raceStart.setHours(hh,mm,0,0);
}
const raceEndTime = new Date(raceStart.getTime()+raceDuration*3600*1000);
const formationLaps = (formationLap==='full')?1:(formationLap==='short')?0.5:0;
const formationTime = formationLaps * avgLapTimeInput * 1.05; // +5% länger
stintTimerSecGlobal = stintTimer*60;
globalMaxFuelPerLap = maxFuelPerLap;
globalFormationLaps = formationLaps;
globalFormationTime = formationTime;
const drivers = getDrivers();
const commonOpts = {
raceStart,
raceEndTime,
avgLapTime: avgLapTimeInput,
tankCapacity,
maxFuelPerLap,
pitTime,
stintTimerSec: stintTimerSecGlobal,
formationLaps,
formationTime
};
const simple = simulateGreedy({...commonOpts, fuelFactor:1, strategy:'simple', drivers});
const alt = simulateGreedy({...commonOpts, fuelFactor:0.98, strategy:'alt', drivers});
const safe = simulateGreedy({...commonOpts, fuelFactor:1, strategy:'safe', drivers});
let html = "";
html += renderPlan('Basic strategy', simple, 'simple', maxFuelPerLap, drivers);
html += renderPlan('Alternative strategy', alt, 'alt', maxFuelPerLap, drivers);
html += renderPlan('Safe strategy', safe, 'safe', maxFuelPerLap, drivers);
document.getElementById('results').innerHTML = html;
}
function adjustLaps(strategy,stintIndex,delta){
if (!manualAdjustments[strategy]) manualAdjustments[strategy]={};
const cell = document.getElementById(`${strategy}-lapsEnd-${stintIndex}`);
const currentVal = parseInt(cell ? cell.innerText : '0',10) || 0;
manualAdjustments[strategy][stintIndex] = currentVal + delta;
calculateStrategy();
}
function assignDriver(strategy, stintIndex, driverValue){
const strategies = ['simple','alt','safe'];
const val = driverValue ? Number(driverValue) : null;
strategies.forEach(s=>{
if (!assignments[s]) assignments[s] = {};
assignments[s][stintIndex] = val;
});
calculateStrategy();
}
calculateStrategy();
</script>
</body>
<footer style="background-color:#050535; color:#eee; padding:20px; text-align:center; font-family:Arial, sans-serif;">
<div style="display:flex; align-items:center; justify-content:center; gap:15px; flex-wrap:wrap;">
<img src="profilbild.png" alt="Profilbild" style="width:80px; height:80px; border-radius:50%; object-fit:cover; border:2px solid #fff;">
<div style="max-width:400px; text-align:left;">
<p style="margin:0 0 10px 0;">Hi, I share my passion for simracing and real motorsport on TikTok. I am working day by day to work one day in the motorsport paddock. Follow my journey and have a good race with hopefully the right strategy ;)</p>
<a href="https://www.tiktok.com/@roadtopaddock2" target="_blank" style="display:inline-block; background-color:#25F4EE; color:#000; padding:5px 10px; border-radius:5px; text-decoration:none; font-weight:bold; transition:0.2s;">Follow me on TikTok</a>
</div>
</div>
</footer>
</html>