From cef6faa05f20861161546aa202630b3286841ce3 Mon Sep 17 00:00:00 2001 From: Nahuel Lofeudo Date: Tue, 19 May 2026 08:37:30 +0100 Subject: [PATCH] Fixed arrival time. --- Cargo.toml | 2 +- src/gtfs/mod.rs | 3 ++- src/gtfs/structs.rs | 2 +- src/main.rs | 8 +++++--- src/renderer/mod.rs | 7 +++++-- src/renderer/structs.rs | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47d00c4..15f60ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ zip = "8.3" csv = "1.4" [profile.dev] -opt-level = 1 +opt-level = 0 [profile.release] opt-level = 3 diff --git a/src/gtfs/mod.rs b/src/gtfs/mod.rs index ccf0660..6dce226 100644 --- a/src/gtfs/mod.rs +++ b/src/gtfs/mod.rs @@ -74,12 +74,13 @@ impl Gtfs { stop: self.stops.get(&stop_time.stop_id)?, stop_time: stop_time, trip: &trip, - departure_time: NaiveTime::from_num_seconds_from_midnight_opt(stop_timestamp, 0).unwrap() + departure_time: stop_timestamp.into() }; arrivals.push(arrival); } } } + arrivals.sort(); debug!("Found {} arrivals", arrivals.len()); return Some(arrivals); diff --git a/src/gtfs/structs.rs b/src/gtfs/structs.rs index f33ce5f..330c310 100644 --- a/src/gtfs/structs.rs +++ b/src/gtfs/structs.rs @@ -32,7 +32,7 @@ pub struct Gtfs { #[derive(Debug)] pub struct Arrival<'a> { - pub departure_time: NaiveTime, + pub departure_time: i64, pub route: &'a Route, pub stop: &'a Stop, pub stop_time: &'a RawStopTime, diff --git a/src/main.rs b/src/main.rs index ee7cc16..172c5e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ mod gtfs; mod renderer; use std::{collections::HashSet, ops::Add, os::unix::process::ExitStatusExt, process, thread::Builder, time::SystemTime}; -use chrono::{DateTime, Duration, Local, NaiveTime}; +use chrono::{DateTime, Duration, Local, NaiveTime, Timelike}; use log::{Metadata, Record, debug, error, info}; use sdl3::event::Event; use crate::{gtfs::structs::{Arrival, Gtfs}, renderer::structs::{DisplayData, DisplayEntry, Screen}}; @@ -31,20 +31,22 @@ fn refresh_schedule<'a>(gtfs: &'a Gtfs, screen : &mut Screen<'a>) -> Option::new(), status: None }; display_data.lines.extend(next_arrivals.iter().map(|arrival| -> DisplayEntry { + DisplayEntry { destination: arrival.stop_time.stop_headsign.clone() .or(arrival.trip.trip_headsign.clone() .or(Option::Some(String::from("Unknown") ))).unwrap(), route: arrival.route.short_name.clone().or(arrival.route.long_name.clone()).unwrap(), - due_in: (arrival.departure_time - current_time).num_minutes().try_into().unwrap() + due_in: (arrival.departure_time - current_time) / 60, } })); diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 8d1f15a..7f5fb23 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -38,12 +38,15 @@ impl Screen<'_> { pub fn update_information(&mut self, display_data: &DisplayData) { self.do_clear(); + + // TODO: Add header + let num_arrivals: i32 = min(if display_data.status.is_some() {LINE_COUNT - 1} else {LINE_COUNT}, display_data.lines.len().try_into().unwrap()); for line in 0..num_arrivals { // Compose a line of text with all the information let entry = display_data.lines.get(line as usize).unwrap(); - let line: u32 = line.try_into().unwrap(); - let due_in_mins = (entry.due_in / 60) as i32; + let line: u32 = (line + 1).try_into().unwrap(); + let due_in_mins = entry.due_in as i32; let arrival_color: Color = self.color_for(due_in_mins); self.color = COLOR_LCD_AMBER; diff --git a/src/renderer/structs.rs b/src/renderer/structs.rs index d15ebd8..5132c32 100644 --- a/src/renderer/structs.rs +++ b/src/renderer/structs.rs @@ -18,7 +18,7 @@ pub struct Prefs { pub struct DisplayEntry { pub route: String, pub destination: String, - pub due_in: i32, + pub due_in: i64, } pub struct DisplayData {