Skip to content

Commit

Permalink
Arrival and departure delay amounts
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed May 11, 2024
1 parent 66cfd9a commit be41c75
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 40 deletions.
111 changes: 111 additions & 0 deletions src/components/DelayDiff.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<script lang="ts">
import { _ } from 'svelte-i18n';
import { locale, locales } from 'svelte-i18n';
export let diff: number;
let textclass: string = '';
let h: number = 0;
let m: number = 0;
let s: number = 0;
let this_locale: string | null |undefined = null;
function locale_hour_marking(l: string | null | undefined) {
if (typeof l == "string") {
if (l == "zh" || l == "zh-CH") {
return "小时"
}
if (l == "zh-TW") {
return "小時"
}
if (l.startsWith("ko")) {
return "시간"
}
}
return "h";
}
function locale_min_marking(l: string | null | undefined) {
if (typeof l == "string") {
if (l == "zh" || l == "zh-CH") {
return ""
}
if (l == "zh-TW") {
return ""
}
if (l.startsWith("ko")) {
return ""
}
}
return "m";
}
function locale_s_marking(l: string | null | undefined) {
if (typeof l == "string") {
if (l == "zh" || l == "zh-CH") {
return ""
}
if (l == "zh-TW") {
return ""
}
if (l.startsWith("ko")) {
return ""
}
}
return "s";
}
locale.subscribe((x) => this_locale = x);
$: if (diff) {
if (diff < 60) {
textclass = 'text-yellow-600 text-yellow-400';
}
if (diff > 60) {
textclass = 'text-red-700 text-red-400';
}
let remainder = Math.abs(diff);
h = Math.floor(remainder / 3600);
remainder = remainder - h * 3600;
m = Math.floor(remainder / 60);
remainder = remainder - m * 60;
s = remainder;
}
</script>

<span class={textclass}>
<span>
{'('}
{#if diff < 0}
{$_('early')}
{/if}

{#if diff > 0}
{$_('late')}
{/if}

{#if diff == 0}
{$_('ontime')}
{/if}
</span>

{#if h > 0}
{h}{locale_hour_marking(this_locale)}
{/if}
{#if h > 0 || m > 0}
{m}
{locale_min_marking(this_locale)}
{/if}
{#if Math.abs(diff) > 0}
{s}{locale_s_marking(this_locale)}
{/if}
{')'}
</span>
100 changes: 69 additions & 31 deletions src/components/SingleTripInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { _ } from 'svelte-i18n';
import RouteIcon from './RouteIcon.svelte';
import { lightenColour } from './lightenDarkColour';
import DelayDiff from './DelayDiff.svelte';
import {
fixHeadsignIcon,
fixHeadsignText,
Expand All @@ -27,7 +28,7 @@
export let darkMode: boolean = false;
async function fetch_trip_selected() {
console.log('t-s', trip_selected)
console.log('t-s', trip_selected);
let url = new URL(
`https://birch.catenarymaps.org/get_trip_information/${trip_selected.chateau_id}/`
Expand Down Expand Up @@ -61,14 +62,23 @@
timezones.push(stoptime.timezone);
}
let stoptime_to_use = { ...stoptime, strike_departure: false, strike_arrival: false };
let stoptime_to_use = {
...stoptime,
strike_departure: false,
strike_arrival: false,
rt_arrival_diff: null,
rt_departure_diff: null
};
if (stoptime_to_use.rt_arrival?.time) {
stoptime_to_use.rt_arrival_time = stoptime_to_use.rt_arrival?.time;
stoptime_to_use.strike_arrival = true;
if (stoptime_to_use.scheduled_arrival_time_unix_seconds) {
if (stoptime_to_use.scheduled_arrival_time_unix_seconds > stoptime_to_use.rt_departure?.time) {
if (
stoptime_to_use.scheduled_arrival_time_unix_seconds >
stoptime_to_use.rt_departure?.time
) {
stoptime_to_use.rt_arrival_time = stoptime_to_use.rt_departure?.time;
stoptime_to_use.strike_arrival = true;
Expand All @@ -81,22 +91,44 @@
stoptime_to_use.strike_departure = true;
}
//prevents departure prior to arrival
//prevents departure prior to arrival
if (stoptime_to_use.scheduled_departure_time_unix_seconds) {
if (stoptime_to_use.rt_arrival?.time) {
if (
stoptime_to_use.scheduled_departure_time_unix_seconds < stoptime_to_use.rt_arrival?.time) {
if (
stoptime_to_use.scheduled_departure_time_unix_seconds <
stoptime_to_use.rt_arrival?.time
) {
stoptime_to_use.rt_departure_time = stoptime_to_use.rt_arrival?.time;
stoptime_to_use.strike_departure = true;
}
}
}
if (typeof stoptime_to_use.rt_departure_time == 'number') {
if (stoptime_to_use.scheduled_departure_time_unix_seconds) {
stoptime_to_use.rt_departure_diff =
stoptime_to_use.rt_departure_time -
stoptime_to_use.scheduled_departure_time_unix_seconds;
}
}
if (typeof stoptime_to_use.rt_arrival_time == 'number') {
if (stoptime_to_use.scheduled_arrival_time_unix_seconds) {
stoptime_to_use.rt_arrival_diff =
stoptime_to_use.rt_arrival_time -
stoptime_to_use.scheduled_arrival_time_unix_seconds;
}
}
stoptimes_cleaned.push(stoptime_to_use);
index = index + 1;
});
if (trip_selected.chateau_id == 'irvine~ca~us') {
stoptimes_cleaned.sort((a, b) => a.rt_arrival_time - b.rt_arrival_time);
}
stoptimes_cleaned_dataset = stoptimes_cleaned;
console.log('stoptimes_cleaned_dataset', stoptimes_cleaned_dataset);
Expand Down Expand Up @@ -127,15 +159,9 @@
<div
class="border-t w-full border-slate-200 dark:border-slate-700 py-3 flex flex-col gap-y-2"
>
<div
class="h-5 w-1/2 bg-slate-400 dark:bg-slate-800 rounded-lg animate-pulse"
></div>
<div
class="h-3 w-1/4 bg-slate-400 dark:bg-slate-800 rounded-lg animate-pulse"
></div>
<div
class="h-3 w-2/5 bg-slate-400 dark:bg-slate-800 rounded-lg animate-pulse"
></div>
<div class="h-5 w-1/2 bg-slate-400 dark:bg-slate-800 rounded-lg animate-pulse"></div>
<div class="h-3 w-1/4 bg-slate-400 dark:bg-slate-800 rounded-lg animate-pulse"></div>
<div class="h-3 w-2/5 bg-slate-400 dark:bg-slate-800 rounded-lg animate-pulse"></div>
</div>
{/each}
{:else}
Expand Down Expand Up @@ -191,8 +217,8 @@
{/if}
</span>
{/if}
{#if trip_data.trip_headsign}
<!--{#if fixRouteIcon(trip_selected.chateau_id, trip_data.route_id)}
{#if trip_data.trip_headsign}
<!--{#if fixRouteIcon(trip_selected.chateau_id, trip_data.route_id)}
<img
alt={trip_data.route_id}
class="inline w-5 h-auto mr-0.5 align-middle"
Expand All @@ -209,7 +235,11 @@
{/if}
{/if}-->
<p class="text-lg font-semibold mt-0 lg:mt-1">
{""} {fixHeadsignText(trip_data.trip_headsign, trip_data.route_short_name || trip_data.route_long_name)}
{''}
{fixHeadsignText(
trip_data.trip_headsign,
trip_data.route_short_name || trip_data.route_long_name
)}
{#if fixHeadsignIcon(trip_data.trip_headsign)}
<span class="material-symbols-outlined text-lg align-bottom"
>{fixHeadsignIcon(trip_data.trip_headsign)}</span
Expand Down Expand Up @@ -249,15 +279,21 @@
</div>
<div class="mr-2"></div>

<div class="w-full border-t border-slate-500 py-2 pr-1 lg:pr-2">
<p class=""><span class="font-bold">{fixStationName(stoptime.name)}</span></p>
<div class="w-full border-t border-slate-500 py-1 pr-1 lg:pr-2">
<p class=""><span class="font-bold dark:text-gray-100">{fixStationName(stoptime.name)}</span></p>

{#if stoptime.schedule_relationship == 1}
<p class='text-red-700 dark:text-red-300'>{$_("cancelled")}</p>
{/if}
{#if stoptime.schedule_relationship == 1}
<p class="text-red-700 dark:text-red-300">{$_('cancelled')}</p>
{/if}

<div class="flex flex-row">
<p class="text-sm">{$_('arrival')}</p>
<p class="text-sm text-gray-900 dark:text-gray-200">{$_('arrival')}</p>

{#if stoptime.rt_arrival_diff != null}
<span class="text-sm ml-1 text-gray-900 dark:text-gray-200">
<DelayDiff diff={stoptime.rt_arrival_diff} />
</span>
{/if}
<div class="ml-auto text-sm">
<div class="text-sm">
<p>
Expand Down Expand Up @@ -286,7 +322,12 @@
</div>

<div class="flex flex-row">
<p class="text-sm">{$_('departure')}</p>
<p class="text-sm text-gray-900 dark:text-gray-200">{$_('departure')}</p>
{#if stoptime.rt_departure_diff != null}
<span class="text-sm ml-1 text-gray-900 dark:text-gray-200">
<DelayDiff diff={stoptime.rt_departure_diff} /></span
>
{/if}
<div class="ml-auto text-sm">
<div class="text-sm">
<p>
Expand Down Expand Up @@ -314,12 +355,9 @@
</div>
</div>
</div>

{#if timezones.length > 1}
<p class="text-sm">
Tz: {stoptime.timezone || trip_data.timezone}
</p>
{/if}
<!--<p class="text-sm">
index of stop seq: {stoptime.gtfs_stop_sequence}
</p>-->
</div>
</div>
{/each}
Expand Down
3 changes: 2 additions & 1 deletion src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
"cancelled": "Abgesagt",
"skipped": "Überspringen",
"early": "Anfang",
"late": "Späte"
"late": "Späte",
"ontime": "Pünktlich"
}
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
"cancelled": "Cancelled",
"early": "Early",
"late": "Late",
"skipped": "Skipped"
"skipped": "Skipped",
"ontime": "On time"
}
3 changes: 2 additions & 1 deletion src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
"cancelled": "Cancelado",
"skipped": "Iginoré",
"early": "Temprano",
"late": "Tarde"
"late": "Tarde",
"ontime": "A tiempo"
}
3 changes: 2 additions & 1 deletion src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@
"cancelled": "Annulé",
"skipped": "Iginoré",
"early": "Tôt",
"late": "Tard"
"late": "Tard",
"ontime": "À temps"
}
3 changes: 2 additions & 1 deletion src/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
"cancelled": "취소된",
"skipped": "건너뛰",
"early": "초반",
"late": "늦게"
"late": "늦게",
"ontime": "정시에"
}
7 changes: 4 additions & 3 deletions src/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@
"cancelled": "取消",
"skipped": "跳過",
"early": "",
"late": ""
"timezone": "時區"
"late": "",
"timezone": "時區",
"arrival": "抵達",
"departure": "離站",
"itemsselected": "選定項目"
"itemsselected": "選定項目",
"ontime": "準時"
}
3 changes: 2 additions & 1 deletion src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@
"cancelled": "取消",
"skipped": "跳过",
"early": "",
"late": ""
"late": "",
"ontime": "准时"
}

0 comments on commit be41c75

Please sign in to comment.