Skip to content

Commit 757f32e

Browse files
committed
Time fuelling area transit separately.
1 parent 91d130c commit 757f32e

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

src/messages/PitMessage.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,42 @@ export const PitMessage = (se, oldCar, newCar, cache) => {
2121

2222
const driverText = driver ? ` (${driver})` : '';
2323

24+
if (oldState !== 'FUEL' && newState === 'FUEL') {
25+
cache['PitMessage'][carNum].lastFuelIn = cache.lastUpdated;
26+
}
27+
28+
if (oldState === 'FUEL' && newState !== 'FUEL') {
29+
cache['PitMessage'][carNum].lastFuelOut = cache.lastUpdated;
30+
}
31+
32+
if (oldState !== 'PIT' && newState === 'PIT') {
33+
cache['PitMessage'][carNum].lastPitIn = cache.lastUpdated;
34+
}
35+
36+
if (oldState === 'PIT' && newState !== 'PIT') {
37+
cache['PitMessage'][carNum].lastPitOut = cache.lastUpdated;
38+
}
39+
2440
if ((oldState !== 'RUN' && oldState !== 'STOP' && newState === 'OUT') || ((oldState === 'PIT' || oldState === 'FUEL') && newState === 'RUN')) {
25-
const lastPitIn = cache['PitMessage'][carNum].lastPitIn;
41+
const { lastFuelIn, lastFuelOut, lastPitIn, lastPitOut } = cache['PitMessage'][carNum];
2642
let pitTimeMsg = '';
27-
if (Number.isInteger(lastPitIn)) {
28-
const pitTime = cache.lastUpdated - lastPitIn;
29-
pitTimeMsg = `(pit time: ${timeInSeconds(pitTime, 0)})`;
30-
delete cache['PitMessage'][carNum].lastPitIn;
43+
if (Number.isInteger(lastPitIn) && Number.isInteger(lastPitOut)) {
44+
const pitTime = lastPitOut - lastPitIn;
45+
46+
const fuelTime = (lastFuelOut || 0) - (lastFuelIn || 0);
47+
if (fuelTime > 0) {
48+
pitTimeMsg = `(total pit time: ${timeInSeconds(pitTime + fuelTime, 0)}, ${timeInSeconds(fuelTime, 0)} fuel)`;
49+
}
50+
else {
51+
pitTimeMsg = `(pit time: ${timeInSeconds(pitTime, 0)})`;
52+
}
53+
54+
delete cache['PitMessage'][carNum];
3155
}
3256
return new Message(clazz, `#${carNum}${driverText} has left the pits ${pitTimeMsg}`.trim(), 'out', carNum);
3357
}
3458
else if (newState === 'PIT') {
35-
if (oldState !== 'FUEL') {
36-
cache['PitMessage'][carNum].lastPitIn = cache.lastUpdated;
37-
}
3859
return new Message(clazz, `#${carNum}${driverText} has entered the pits`, 'pit', carNum);
3960
}
40-
else if (newState === 'FUEL' && oldState !== 'PIT') {
41-
cache['PitMessage'][carNum].lastPitIn = cache.lastUpdated;
42-
}
4361
}
4462
};

src/messages/__tests__/PitMessage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ it('calculates a total pit time if both pit-in and pit-out have been seen and ca
6565
expect(outMsgs[0][2]).toEqual('#1 (John Hindhaugh) has left the pits (pit time: 2:03)');
6666
});
6767

68-
it('calculates a total pit time if both pit-in and pit-out have been seen and car comes in via fuelling area', () => {
68+
it('calculates total pit time and fuel time if both pit-in and pit-out have been seen and car comes in via fuelling area', () => {
6969
const oldCars = [['1', 'RUN', 'LMP1', 'John Hindhaugh'], ['2', 'RUN', 'LMP1', 'Eve Hewitt']];
7070
const pitInCars = [['1', 'PIT', 'LMP1', 'John Hindhaugh'], ['2', 'RUN', 'LMP1', 'Eve Hewitt']];
7171
const pitFuelCars = [['1', 'FUEL', 'LMP1', 'John Hindhaugh'], ['2', 'RUN', 'LMP1', 'Eve Hewitt']];
@@ -78,5 +78,5 @@ it('calculates a total pit time if both pit-in and pit-out have been seen and ca
7878
const outMsgs = generator.generate({ colSpec }, { cars: pitInCars, lastUpdated: 0 }, { cars: pitOutCars, lastUpdated: 123 });
7979

8080
expect(outMsgs.length).toEqual(1);
81-
expect(outMsgs[0][2]).toEqual('#1 (John Hindhaugh) has left the pits (pit time: 2:03)');
81+
expect(outMsgs[0][2]).toEqual('#1 (John Hindhaugh) has left the pits (total pit time: 2:03, 1:02 fuel)');
8282
});

0 commit comments

Comments
 (0)