More work on staff version

This commit is contained in:
Fred Boniface 2023-07-07 11:15:49 +01:00
parent 31f6113292
commit 039b57efe7
2 changed files with 64 additions and 27 deletions

View File

@ -1,6 +1,11 @@
module.exports = { module.exports = {
root: true, root: true,
extends: ['eslint:recommended', 'plugin:svelte/recommended', 'prettier'], extends: ['eslint:recommended', 'plugin:svelte/recommended', 'prettier'],
overrides: [
{
"files": ["**/*.svelte"]
}
],
parserOptions: { parserOptions: {
sourceType: 'module', sourceType: 'module',
ecmaVersion: 2020, ecmaVersion: 2020,
@ -10,5 +15,8 @@ module.exports = {
browser: true, browser: true,
es2017: true, es2017: true,
node: true node: true
},
rules: {
indent: ['error', 2, {SwitchCase: 2}],
} }
}; };

View File

@ -72,7 +72,7 @@
from: await parseLocation(service.origin), from: await parseLocation(service.origin),
to: await parseLocation(service.destination), to: await parseLocation(service.destination),
length: await getTrainLength(service), length: await getTrainLength(service),
platform: await parsePlatform(service?.platform), platform: await parsePlatform(service?.platform || "undefined"),
platformHidden: service?.platformIsHidden === "true", platformHidden: service?.platformIsHidden === "true",
schArr: timeDetails.schArr, schArr: timeDetails.schArr,
expArr: timeDetails.expArr, expArr: timeDetails.expArr,
@ -115,12 +115,14 @@
} }
async function parsePlatform(platform) { async function parsePlatform(platform) {
if (platform === "TBC") { if (!platform) {
return '-'
}
if (platform === "TBC" || platform == "undefined") {
return '-' return '-'
} }
return { return {
number: platform, number: platform
isHidden: false // Not Implemented
} }
} }
@ -129,23 +131,50 @@
let expArr = new Date(service?.eta || service?.ata); let expArr = new Date(service?.eta || service?.ata);
let schDep = new Date(service?.std); let schDep = new Date(service?.std);
let expDep = new Date(service?.etd || service?.atd); let expDep = new Date(service?.etd || service?.atd);
let isEarlyArr = false, isDelayedArr = false let isEarlyArr = false, isDelayedArr = false, isArr = false
let isEarlyDep = false, isDelayedDep = false let isEarlyDep = false, isDelayedDep = false, isDep = false
if (expArr < schArr) { const timeDifferenceThreshold = 60 * 1000; // 60 seconds in milliseconds
if (expArr - schArr < -timeDifferenceThreshold) {
isEarlyArr = true; isEarlyArr = true;
} else if (expArr > schArr) { isArr = true;
isDelayedArr = true; // Only if the delay is more than 60 seconds. } else if (expArr - schArr > timeDifferenceThreshold) {
isDelayedArr = true;
isArr = true;
} }
if (expDep < schDep) {
isEarlyDep = true; // Only if the delay is more than 60 seconds. if (expDep - schDep < -timeDifferenceThreshold) {
} else if (expDep > schDep) { isEarlyDep = true;
isDep = true;
} else if (expDep - schDep > timeDifferenceThreshold) {
isDelayedDep = true; isDelayedDep = true;
isDep = true;
}
let parsedExpArr;
if (expArr instanceof Date && !isNaN(expArr)) {
if (!isEarlyArr && !isDelayedArr) {
parsedExpArr = 'RT';
} else {
parsedExpArr = parseIndividualTime(expArr);
}
} else {
parsedExpArr = '-';
}
let parsedExpDep;
if (expDep instanceof Date && !isNaN(expDep)) {
if (!isEarlyDep && !isDelayedDep) {
parsedExpDep = 'RT';
} else {
parsedExpDep = parseIndividualTime(expDep);
}
} else {
parsedExpDep = '-';
} }
return { return {
schArr: parseIndividualTime(schArr), schArr: parseIndividualTime(schArr),
expArr: parseIndividualTime(expArr), expArr: parsedExpArr,
schDep: parseIndividualTime(schDep), schDep: parseIndividualTime(schDep),
expDep: parseIndividualTime(expDep), expDep: parsedExpDep,
earArr: isEarlyArr, earArr: isEarlyArr,
delArr: isDelayedArr, delArr: isDelayedArr,
earDep: isEarlyDep, earDep: isEarlyDep,
@ -216,7 +245,7 @@
<td class="id id-data data">{service.trainid}</td> <td class="id id-data data">{service.trainid}</td>
<td class="from from-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.from}</td> <td class="from from-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.from}</td>
<td class="to to-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.to}</td> <td class="to to-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.to}</td>
<td class="plat plat-data data {serviceStats.isCancelled && 'can-dat'} {serviceStats.platformHidden && 'hidden'}">{serviceStats.platform.number}</td> <td class="plat plat-data data {serviceStats.isCancelled && 'can-dat'} {serviceStats.platformHidden && 'hidden'}">{serviceStats.platform.number || '-'}</td>
<td class="time time-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.schArr}</td> <td class="time time-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.schArr}</td>
<td class="time time-data data {serviceStats.isArrDelayed && 'late'} {serviceStats.isEarlyArr && 'early'} {serviceStats.isLateArr && 'late'}">{serviceStats.isArrDelayed ? 'LATE' : serviceStats.expArr}</td> <td class="time time-data data {serviceStats.isArrDelayed && 'late'} {serviceStats.isEarlyArr && 'early'} {serviceStats.isLateArr && 'late'}">{serviceStats.isArrDelayed ? 'LATE' : serviceStats.expArr}</td>
<td class="time time-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.schDep}</td> <td class="time time-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.schDep}</td>