Extend data in the schedule box

This commit is contained in:
2026-05-04 21:49:59 +01:00
parent 1c4c7ccabc
commit 6a857c2d64
3 changed files with 407 additions and 298 deletions

View File

@@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import type { ApiTrainsTrainByHeadcode } from '@owlboard/owlboard-ts'; import type { ApiPisObject, ApiTrainsTrainByHeadcode } from '@owlboard/owlboard-ts';
import { OwlClient, ApiError, ValidationError } from '$lib/owlClient'; import { OwlClient, ApiError, ValidationError } from '$lib/owlClient';
import { slide } from 'svelte/transition'; import { slide } from 'svelte/transition';
import { quintOut } from 'svelte/easing'; import { quintOut } from 'svelte/easing';
@@ -46,6 +46,51 @@
} }
const estClass = (act, est) => (!act && est ? 'est' : 'act'); const estClass = (act, est) => (!act && est ? 'est' : 'act');
const activityMap: Record<string, string> = {
'-D': 'Vehicles detatched',
'-T': 'Vehicles attached & detached',
'-U': 'Vehicles attached',
AE: 'Assist locomotive attached',
C: 'Traincrew change only',
D: 'Set down only',
E: 'Stops for examination',
K: 'Passenger count point',
KC: 'Ticket collection point',
KE: 'Ticket examination point',
KF: 'First class ticket examination point',
KS: 'Selective ticket examination point',
L: 'Locomotive changed',
N: 'Unadvertised stop',
OP: 'Operational stop only',
OR: 'Locomotive attached on rear',
R: 'Request stop only',
RM: 'Train changes direction',
RR: 'Locomotive run round',
S: 'Staff only stop',
TW: 'Stops for token/staff/tablet only',
U: 'Pick up only',
W: 'Watering coaches',
X: 'Passes another train'
};
const activityRegex = new RegExp(
Object.keys(activityMap)
.sort((a, b) => b.length - a.length) // Longest codes first
.map((key) => key.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')) // Escape special chars
.join('|'),
'g'
);
const getRelevantActivities = (act: string) => {
if (!act) return [];
// Find all matches in the string
const matches = act.match(activityRegex) || [];
// Map to labels and remove duplicates
return [...new Set(matches)].map((code) => activityMap[code]);
};
</script> </script>
<div class="train-service"> <div class="train-service">
@@ -68,7 +113,7 @@
{service.dt} {service.dt}
</div> </div>
<div class="arrow" class:expanded={isExpanded}> <div class="arrow" class:expanded={isExpanded}>
<IconChevronDownFilled color={"var(--color-title)"} size={25} /> <IconChevronDownFilled color={'var(--color-title)'} size={25} />
</div> </div>
</div> </div>
</button> </button>
@@ -86,7 +131,6 @@
{#if details.header.cl} {#if details.header.cl}
{details.header.cn ? ' near ' : ' at '} {details.header.cn ? ' near ' : ' at '}
<TiplocConverter code={details.header.cl} /> <TiplocConverter code={details.header.cl} />
<!-- CONSIDER WRAPPING IN A COMPONENT THAT CONVERTS TO THE LOCATION NAME RATHER THAN TIPLOC -->
{/if} {/if}
</span> </span>
{/if} {/if}
@@ -101,9 +145,14 @@
{/if} {/if}
</span> </span>
{/if} {/if}
{#if details.pis}
<div class="pis-detail"> <div class="pis-detail">
<!-- PIS Data Here --> {details.pis.code}
</div> </div>
{/if}
</div>
<div class="color-key">
<p class="tpl-stop">Times in yellow are estimates</p>
</div> </div>
<div class="schedule-table-container"> <div class="schedule-table-container">
<table class="schedule-table"> <table class="schedule-table">
@@ -117,30 +166,33 @@
<th>Location</th> <th>Location</th>
<th>Plat</th> <th>Plat</th>
<th>Sch</th> <th>Sch</th>
<th><span class="est">Est</span>/Act</th> <th>Act</th>
<th>Sch</th> <th>Sch</th>
<th><span class="est">Est</span>/Act</th> <th>Act</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody>
{#each details.locations as loc} {#each details.locations as loc}
<tbody class="location-group">
<tr class:pass-loc={loc.r === 'PASS'} class:can-loc={loc.can}> <tr class:pass-loc={loc.r === 'PASS'} class:can-loc={loc.can}>
<td class="tpl-cell" class:tpl-stop={loc.r != 'PASS'}>{loc.t}</td> <td class="tpl-cell" class:tpl-stop={loc.r != 'PASS'}>
<td class="plat-cell" class:plat-change={loc.pc}>{loc.p}</td> {loc.t}
</td>
<td class="plat-cell cell-divider-right" class:plat-change={loc.pc}>{loc.p}</td>
{#if loc.r == 'PASS'} {#if loc.r == 'PASS'}
<td class="time-cell" colspan="2">Pass</td> <td class="time-cell cell-divider-right" colspan="2">Pass</td>
<td class="time-cell">{formatUkTime(loc.wtp)}</td> <td class="time-cell">{formatUkTime(loc.wtp)}</td>
<td class="time-cell {estClass(loc.atp, loc.etp)}" <td class="time-cell {estClass(loc.atp, loc.etp)}"
>{formatUkTime(loc.atp || loc.etp || '--')}</td >{formatUkTime(loc.atp || loc.etp || '--')}</td
> >
{:else} {:else}
<td class="time-cell">{formatUkTime(loc.pta || loc.wta || '--')}</td> <td class="time-cell">{formatUkTime(loc.pta || loc.wta || '--')}</td>
<td class="time-cell {estClass(loc.ata, loc.eta)}" <td class="time-cell cell-divider-right {estClass(loc.ata, loc.eta)}"
>{formatUkTime(loc.ata || loc.eta || '--')}</td >{formatUkTime(loc.ata || loc.eta || '--')}</td
> >
<td class="time-cell">{formatUkTime(loc.ptd || loc.wtd || '--')}</td> <td class="time-cell">{formatUkTime(loc.ptd || loc.wtd || '--')}</td>
<td class="time-cell {estClass(loc.atd, loc.etd)}" <td class="time-cell cell-divider-right {estClass(loc.atd, loc.etd)}"
>{formatUkTime(loc.atd || loc.etd || '--')}</td >{formatUkTime(loc.atd || loc.etd || '--')}</td
> >
{/if} {/if}
@@ -149,8 +201,19 @@
<td class="delay-{delay.type}">{delay.val}</td> <td class="delay-{delay.type}">{delay.val}</td>
{/if} {/if}
</tr> </tr>
{#if loc.act && getRelevantActivities(loc.act).length > 0}
<tr class="activity-row">
<td colspan="7">
<div class="activity-container">
{#each getRelevantActivities(loc.act) as note}
<span class="activity-tag">{note}</span>
{/each} {/each}
</tbody> </div>
</td>
</tr>
{/if}
</tbody>{/each}
</table> </table>
</div> </div>
</div> </div>
@@ -167,7 +230,7 @@
max-width: 460px; max-width: 460px;
border-radius: 12px; border-radius: 12px;
box-shadow: var(--shadow-std); box-shadow: var(--shadow-std);
overflow: hidden; overflow: visible;
font-family: 'URW Gothic', sans-serif; font-family: 'URW Gothic', sans-serif;
transition: 0.2s all; transition: 0.2s all;
filter: brightness(1.1); filter: brightness(1.1);
@@ -288,27 +351,66 @@
/* /*
Schedule Table Schedule Table
*/ */
.color-key,
.color-key p {
text-align: center;
width: 100%;
padding: 0 0 0.2rem 0;
margin: 0;
}
.schedule-table-container { .schedule-table-container {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: 100%; width: 100%;
padding-bottom: 0.1rem;
} }
.schedule-table { .schedule-table {
width: 95%; width: 95%;
border-collapse: collapse;
font-family: 'URW Gothic', 'Inter', sans-serif; font-family: 'URW Gothic', 'Inter', sans-serif;
font-variant-numeric: tabular-nums; font-variant-numeric: tabular-nums;
padding-bottom: 1rem;
font-size: 0.8rem; font-size: 0.8rem;
letter-spacing: -0.02ch; letter-spacing: -0.02ch;
transition: all 0.5s; transition: all 0.5s;
font-weight: 500; font-weight: 500;
} }
.location-group:nth-of-type(even) {
background-color: rgba(255, 255, 255, 0.04);
}
.cell-divider-right {
border-right: 1px solid rgba(255, 255, 255, 0.1);
}
th, th,
td { td {
text-align: center; text-align: center;
padding: 6px 4px;
}
.activity-row td {
padding: 0 0 10px 0;
text-align: left;
font-size: 0.75rem;
letter-spacing: 0.01em;
}
.activity-container {
display: flex;
flex-wrap: wrap;
gap: 6px;
padding: 0 12px;
}
.activity-tag {
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.05);
padding: 2px 6px;
border-radius: 4px;
} }
.tpl-cell { .tpl-cell {
@@ -324,33 +426,28 @@
animation: fast-pulse 2s ease-out infinite; animation: fast-pulse 2s ease-out infinite;
} }
.pass-loc { .pass-loc td {
color: var(--color-title); color: var(--color-title);
font-style: oblique; font-style: oblique;
opacity: 0.5;
} }
.can-loc { .can-loc {
text-decoration: line-through; text-decoration: line-through;
} }
.est { .est {
color: var(--location-yellow); color: var(--location-yellow);
opacity: 0.5; font-style: oblique;
font-style: italic;
} }
.act { td.delay-late {
color: white;
}
.delay-late {
color: var(--delay-orange); color: var(--delay-orange);
font-weight: 600; font-weight: 600;
animation: pulse 2s ease-out infinite; animation: pulse 2s ease-out infinite;
} }
.delay-early { td.delay-early {
color: var(--early-blue); color: var(--early-blue);
font-weight: 600; font-weight: 600;
animation: pulse 2s ease-out infinite; animation: pulse 2s ease-out infinite;
@@ -394,6 +491,9 @@
.location-summary { .location-summary {
font-size: 0.9rem; font-size: 0.9rem;
} }
.activity-row td {
font-size: 0.8rem;
}
} }
@media (min-width: 340px) { @media (min-width: 340px) {
@@ -412,6 +512,9 @@
.schedule-table { .schedule-table {
font-size: 0.99rem; font-size: 0.99rem;
} }
.activity-row td {
font-size: 0.9rem;
}
} }
@media (min-width: 420px) { @media (min-width: 420px) {
@@ -424,6 +527,8 @@
KEYFRAMES KEYFRAMES
*/ */
@keyframes load-spin { @keyframes load-spin {
to { transform: rotate(360deg); } to {
transform: rotate(360deg);
}
} }
</style> </style>

View File

@@ -153,7 +153,8 @@
/* Pulse Animations */ /* Pulse Animations */
@keyframes pulse { @keyframes pulse {
0%, 100% { 0%,
100% {
opacity: 1; opacity: 1;
} }
50% { 50% {
@@ -162,15 +163,17 @@
} }
@keyframes fast-pulse { @keyframes fast-pulse {
0%, 50%, 100% { 0%,
50%,
100% {
opacity: 1; opacity: 1;
} }
25%, 75% { 25%,
75% {
opacity: 0; opacity: 0;
} }
} }
body { body {
margin: 0; margin: 0;
padding: 0; padding: 0;

View File

@@ -23,20 +23,21 @@ export function formatUkTime(dateStr: string | Date | undefined): string {
* @param 'Schedule Location' object * @param 'Schedule Location' object
* @returns Delay string for departure boards * @returns Delay string for departure boards
*/ */
export function calculateDelay(loc: ApiTrainsTrainDetails.ServiceLocation): {val: string, type: string} { export function calculateDelay(loc: ApiTrainsTrainDetails.ServiceLocation): {
val: string;
type: string;
} {
const pairs = [ const pairs = [
{ actual: loc.atd, sched: loc.ptd ?? loc.wtd }, { actual: loc.atd, sched: loc.ptd ?? loc.wtd },
{ actual: loc.ata, sched: loc.pta ?? loc.wta }, { actual: loc.ata, sched: loc.pta ?? loc.wta },
{ actual: loc.atp, sched: loc.wtp } { actual: loc.atp, sched: loc.wtp }
]; ];
const match = pairs.find(p => p.actual && p.sched); const match = pairs.find((p) => p.actual && p.sched);
if (!match || !match.actual || !match.sched) return { val: '', type: 'none' }; if (!match || !match.actual || !match.sched) return { val: '', type: 'none' };
const diffMinutes = Math.round( const diffMinutes = Math.round((Date.parse(match.actual) - Date.parse(match.sched)) / 60000);
(Date.parse(match.actual) - Date.parse(match.sched)) / 60000
);
if (diffMinutes === 0) return { val: 'RT', type: 'ontime' }; if (diffMinutes === 0) return { val: 'RT', type: 'ontime' };