From 5539c8521d246222601a9ca642365dc393aaf632 Mon Sep 17 00:00:00 2001 From: Nicholas Orlowsky Date: Mon, 6 Oct 2025 21:25:15 -0400 Subject: [PATCH] add load time and autofocus --- api/assets/style.css | 4 ++ api/src/database.rs | 2 +- api/src/templates.rs | 22 ++++++++- api/templates/layout.html | 12 +++++ api/templates/route.html | 29 ++++++++++- data_loader/src/fetchers/septa.rs | 6 +-- data_loader/src/septa/direction.rs | 5 +- data_loader/src/septa/route.rs | 67 +++++++++++++++++++++++++- data_loader/src/septa/stop_schedule.rs | 9 ++++ libseptastic/src/route.rs | 8 +++ 10 files changed, 153 insertions(+), 11 deletions(-) diff --git a/api/assets/style.css b/api/assets/style.css index 951d28e..0cb61b6 100644 --- a/api/assets/style.css +++ b/api/assets/style.css @@ -29,6 +29,10 @@ body { max-width: 750px; } +.next-col { + background-color: #55ff55 !important; +} + a { text-decoration: none; color: #114488; diff --git a/api/src/database.rs b/api/src/database.rs index 65ce830..a9792af 100644 --- a/api/src/database.rs +++ b/api/src/database.rs @@ -134,7 +134,7 @@ pub async fn get_schedule_by_route_id( AND septa_schedule_days.service_id = septa_stop_schedules.service_id WHERE - septa_stop_schedules.route_id = $1 + septa_stop_schedules.route_id = $1 OR septa_stop_schedules.route_id = 'B2' ;"#, id.clone(), schedule_day_str.clone() diff --git a/api/src/templates.rs b/api/src/templates.rs index eb39747..842d100 100644 --- a/api/src/templates.rs +++ b/api/src/templates.rs @@ -2,6 +2,7 @@ use libseptastic::{direction::Direction, stop_schedule::{Trip, TripTracking}}; use std::{cmp::Ordering, collections::BTreeMap}; use serde::{Serialize}; use libseptastic::stop_schedule::TripTracking::Tracked; +use chrono::Timelike; #[derive(askama::Template)] #[template(path = "layout.html")] @@ -49,9 +50,11 @@ pub struct TimetableDirection { pub direction: Direction, pub trip_ids: Vec, pub tracking_data: Vec, - pub rows: Vec + pub rows: Vec, + pub next_id: Option } + pub fn build_timetables( directions: Vec, trips: Vec, @@ -59,6 +62,12 @@ pub fn build_timetables( let mut results = Vec::new(); for direction in directions { + let now = chrono::Local::now(); + let naive_time = now.time(); + let seconds_since_midnight = naive_time.num_seconds_from_midnight(); + + let mut next_id: Option = None; + let mut direction_trips: Vec<&Trip> = trips .iter() .filter(|trip| trip.direction_id == direction.direction_id) @@ -72,6 +81,14 @@ pub fn build_timetables( .unwrap_or(i64::MAX) }); + for trip in direction_trips.clone() { + if let Some(last) = trip.schedule.last() { + if next_id == None && i64::from(seconds_since_midnight) < last.arrival_time { + next_id = Some(last.trip_id.clone()); + } + } + } + let trip_ids: Vec = direction_trips .iter() .map(|t| t.trip_id.clone()) @@ -120,7 +137,8 @@ pub fn build_timetables( direction: direction.clone(), trip_ids, rows, - tracking_data: live_trips + tracking_data: live_trips , + next_id }); } diff --git a/api/templates/layout.html b/api/templates/layout.html index 2b74790..47a57f4 100644 --- a/api/templates/layout.html +++ b/api/templates/layout.html @@ -18,6 +18,17 @@ +