Further Staff LDB Work
This commit is contained in:
parent
c4841f6090
commit
31f6113292
@ -59,15 +59,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseDateTime(input) {
|
|
||||||
const dt = new Date(input);
|
|
||||||
const output = dt.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})
|
|
||||||
if (output !== "Invalid Date") {
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
return '-'
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getReasonCodeData(code) {
|
async function getReasonCodeData(code) {
|
||||||
const url = `https://owlboard.info/api/v2/ref/reasonCode/${code}`
|
const url = `https://owlboard.info/api/v2/ref/reasonCode/${code}`
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
@ -76,32 +67,99 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function generateServiceData(service) {
|
async function generateServiceData(service) {
|
||||||
|
const timeDetails = await parseTimes(service);
|
||||||
let serviceData = {
|
let serviceData = {
|
||||||
to: await parseLocation(),
|
from: await parseLocation(service.origin),
|
||||||
from: await parseLocation(),
|
to: await parseLocation(service.destination),
|
||||||
length: await getTrainLength(service),
|
length: await getTrainLength(service),
|
||||||
platform: await parsePlatform(),
|
platform: await parsePlatform(service?.platform),
|
||||||
|
platformHidden: service?.platformIsHidden === "true",
|
||||||
|
schArr: timeDetails.schArr,
|
||||||
|
expArr: timeDetails.expArr,
|
||||||
|
schDep: timeDetails.schDep,
|
||||||
|
expDep: timeDetails.expDep,
|
||||||
|
isEarlyArr: timeDetails.earArr,
|
||||||
|
isLateArr: timeDetails.delArr,
|
||||||
|
isEarlyDep: timeDetails.earDep,
|
||||||
|
isLateDep: timeDetails.delDep,
|
||||||
|
isCancelledDep: false,
|
||||||
|
isCancelled: Boolean(service?.isCancelled),
|
||||||
|
isDelayed: service?.arrivalType === "Delayed",
|
||||||
|
isArrDelayed: service?.arrivalType === "Delayed",
|
||||||
|
isDepDelayed: service?.departureType === "Delayed",
|
||||||
|
isEarly: false,
|
||||||
|
isNonPublic: false
|
||||||
}
|
}
|
||||||
return serviceData;
|
return serviceData;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTrainLength(service) {
|
async function getTrainLength(service) {
|
||||||
return;
|
if (service?.length) {
|
||||||
|
return parseInt(service?.length);
|
||||||
|
} else if (service?.formation?.coaches) {
|
||||||
|
return service.formation.coaches.coach.length
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parseLocation(location) {
|
async function parseLocation(location) {
|
||||||
return;
|
if (!Array.isArray(location.location)) {
|
||||||
|
//console.log(location.location?.tiploc)
|
||||||
|
return location.location?.tiploc
|
||||||
|
}
|
||||||
|
let locations = [];
|
||||||
|
for (const singleLocation of location?.location) {
|
||||||
|
locations.push(singleLocation?.tiploc)
|
||||||
|
}
|
||||||
|
return locations.join(' & ');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function parsePlatform(platform) {
|
async function parsePlatform(platform) {
|
||||||
if (platform === "TBC") {
|
if (platform === "TBC") {
|
||||||
return '-'
|
return '-'
|
||||||
}
|
}
|
||||||
return platform;
|
return {
|
||||||
|
number: platform,
|
||||||
|
isHidden: false // Not Implemented
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTime(service){
|
function parseTimes(service){
|
||||||
return
|
let schArr = new Date(service?.sta);
|
||||||
|
let expArr = new Date(service?.eta || service?.ata);
|
||||||
|
let schDep = new Date(service?.std);
|
||||||
|
let expDep = new Date(service?.etd || service?.atd);
|
||||||
|
let isEarlyArr = false, isDelayedArr = false
|
||||||
|
let isEarlyDep = false, isDelayedDep = false
|
||||||
|
if (expArr < schArr) {
|
||||||
|
isEarlyArr = true;
|
||||||
|
} else if (expArr > schArr) {
|
||||||
|
isDelayedArr = true; // Only if the delay is more than 60 seconds.
|
||||||
|
}
|
||||||
|
if (expDep < schDep) {
|
||||||
|
isEarlyDep = true; // Only if the delay is more than 60 seconds.
|
||||||
|
} else if (expDep > schDep) {
|
||||||
|
isDelayedDep = true;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
schArr: parseIndividualTime(schArr),
|
||||||
|
expArr: parseIndividualTime(expArr),
|
||||||
|
schDep: parseIndividualTime(schDep),
|
||||||
|
expDep: parseIndividualTime(expDep),
|
||||||
|
earArr: isEarlyArr,
|
||||||
|
delArr: isDelayedArr,
|
||||||
|
earDep: isEarlyDep,
|
||||||
|
delDep: isDelayedDep
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIndividualTime(input) {
|
||||||
|
const dt = new Date(input);
|
||||||
|
const output = dt.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'})
|
||||||
|
if (output !== "Invalid Date") {
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
return '-'
|
||||||
}
|
}
|
||||||
|
|
||||||
function processNrcc(messages) { // Remove newlines and then <p> tags from input and append to array
|
function processNrcc(messages) { // Remove newlines and then <p> tags from input and append to array
|
||||||
@ -131,7 +189,7 @@
|
|||||||
<AlertBar {alerts} />
|
<AlertBar {alerts} />
|
||||||
{/if}
|
{/if}
|
||||||
<table>
|
<table>
|
||||||
<tr><td colspan="8">Updated: {dataAge.toLocaleTimeString()} - Staff Boards under development</td></tr>
|
<tr><td colspan="8" id="timestamp">Updated: {dataAge.toLocaleTimeString()} - Staff Boards under development</td></tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="id">ID</th>
|
<th class="id">ID</th>
|
||||||
<th class="from">From</th>
|
<th class="from">From</th>
|
||||||
@ -155,18 +213,18 @@
|
|||||||
relevant BOOLs like isCancelled, isEarly, isLate, isNonPassenger and calculate train length
|
relevant BOOLs like isCancelled, isEarly, isLate, isNonPassenger and calculate train length
|
||||||
where 'length' is not provided but 'formation' is. -->
|
where 'length' is not provided but 'formation' is. -->
|
||||||
<tr>
|
<tr>
|
||||||
<th class="id id-data data">{service.trainid}</th>
|
<td class="id id-data data">{service.trainid}</td>
|
||||||
<th class="from from-data data">{service.origin.location.tiploc}</th> <!-- From and To fields are arrays if more than one origin/destination is served -->
|
<td class="from from-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.from}</td>
|
||||||
<th class="to to-data data">{service.destination.location.tiploc}</th>
|
<td class="to to-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.to}</td>
|
||||||
<th class="plat plat-data data">{service.platform || '-'}</th>
|
<td class="plat plat-data data {serviceStats.isCancelled && 'can-dat'} {serviceStats.platformHidden && 'hidden'}">{serviceStats.platform.number}</td>
|
||||||
<th class="time time-data data">{parseDateTime(service.sta)}</th>
|
<td class="time time-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.schArr}</td>
|
||||||
<th class="time time-data data">{parseDateTime(service.ata || service.eta)}</th>
|
<td class="time time-data data {serviceStats.isArrDelayed && 'late'} {serviceStats.isEarlyArr && 'early'} {serviceStats.isLateArr && 'late'}">{serviceStats.isArrDelayed ? 'LATE' : serviceStats.expArr}</td>
|
||||||
<th class="time time-data data">{parseDateTime(service.std)}</th>
|
<td class="time time-data data {serviceStats.isCancelled && 'can-dat'}">{serviceStats.schDep}</td>
|
||||||
<th class="time time-data data">{parseDateTime(service.atd || service.etd)}</th>
|
<td class="time time-data data {serviceStats.isDepDelayed && 'late'} {serviceStats.isEarlyDep && 'early'} {serviceStats.isLateDep && 'late'}">{serviceStats.isDepDelayed ? 'LATE' : serviceStats.expDep}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="text-row">
|
<tr class="text-row">
|
||||||
<td colspan="8" class="text-data">
|
<td colspan="8" class="text-data">
|
||||||
{service.operator} {#if service.length} - {service.length} carriages{/if}
|
{service.operator} {#if serviceStats.length} | {serviceStats.length} carriages{/if}
|
||||||
<br>
|
<br>
|
||||||
{#if service.isCancelled}
|
{#if service.isCancelled}
|
||||||
{#await getReasonCodeData(service.cancelReason)}
|
{#await getReasonCodeData(service.cancelReason)}
|
||||||
@ -176,8 +234,20 @@
|
|||||||
<br>
|
<br>
|
||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if service?.delayReason}
|
||||||
|
{#await getReasonCodeData(service.delayReason)}
|
||||||
|
This train has been delayed
|
||||||
|
{:then reasonCode}
|
||||||
|
{reasonCode[0].lateReason}
|
||||||
|
<br>
|
||||||
|
{/await}
|
||||||
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{:catch}
|
||||||
|
<tr>
|
||||||
|
<td colspan="8">Unable to load service</td>
|
||||||
|
</tr>
|
||||||
{/await}
|
{/await}
|
||||||
{/each}
|
{/each}
|
||||||
</table>
|
</table>
|
||||||
@ -187,9 +257,7 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
#timestamp {
|
#timestamp {
|
||||||
text-align: centre;
|
color: var(--second-text-color);
|
||||||
margin: auto;
|
|
||||||
width: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
@ -226,15 +294,24 @@
|
|||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.can-dat {
|
||||||
|
color: grey;
|
||||||
|
text-decoration: line-through;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
|
||||||
.can-time {
|
.can-time {
|
||||||
animation: pulse-cancel 1.5s linear infinite;
|
animation: pulse-cancel 1.5s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
.early-time {
|
.early {
|
||||||
animation: pulse-early 1.5s linear infinite;
|
animation: pulse-early 1.5s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
.late-time {
|
.late {
|
||||||
animation: pulse-late 1.5s linear infinite;
|
animation: pulse-late 1.5s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user