Added an obscene amount of debug logging.

This commit is contained in:
Nahuel Lofeudo 2026-04-29 21:32:18 +01:00
parent ca6857dda9
commit 4d272c31c5
4 changed files with 50 additions and 7 deletions

View File

@ -9,6 +9,7 @@ sdl3 = {version = "0.17", features = ["ttf"]}
serde = "1.0" serde = "1.0"
gtfs-structures = "0.47" gtfs-structures = "0.47"
chrono = "*" chrono = "*"
log = "*"
zip = "8.3" zip = "8.3"
csv = "1.4" csv = "1.4"

View File

@ -1,3 +1,4 @@
use log::{debug, info, warn};
use gtfs_structures::{Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop}; use gtfs_structures::{Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use std::{ use std::{
@ -152,6 +153,7 @@ pub fn load_gtfs(
|c: &Calendar| String::from(&c.id), |c: &Calendar| String::from(&c.id),
LoadAll {}, LoadAll {},
); );
debug!("Loaded {} calendar entries", gtfs.calendar.keys().len());
// Calendar Dates // Calendar Dates
load_vector_map( load_vector_map(
@ -161,6 +163,7 @@ pub fn load_gtfs(
|d: &CalendarDate| String::from(&d.service_id), |d: &CalendarDate| String::from(&d.service_id),
LoadAll {}, LoadAll {},
); );
debug!("Loaded {} calendar date keys", gtfs.calendar_dates.keys().len());
// Routes // Routes
load_map( load_map(
@ -172,6 +175,8 @@ pub fn load_gtfs(
routes: &route_numbers, routes: &route_numbers,
}, },
); );
debug!("Loaded {} routes", gtfs.routes.keys().len());
// Stops // Stops
load_map( load_map(
@ -181,6 +186,8 @@ pub fn load_gtfs(
|s: &Stop| String::from(&s.id), |s: &Stop| String::from(&s.id),
LoadStops { stops: &stop_codes }, LoadStops { stops: &stop_codes },
); );
debug!("Loaded {} stop entries", gtfs.stops.keys().len());
let route_ids = route_ids_from_numbers(&gtfs, &route_numbers); let route_ids = route_ids_from_numbers(&gtfs, &route_numbers);
// Trips // Trips
@ -193,6 +200,8 @@ pub fn load_gtfs(
route_ids: &route_ids, route_ids: &route_ids,
}, },
); );
debug!("Loaded {} trip entries", gtfs.trips.keys().len());
// Load stop times for the chosen routes and stops // Load stop times for the chosen routes and stops
let stop_ids = stop_ids_from_codes(&gtfs, &stop_codes); let stop_ids = stop_ids_from_codes(&gtfs, &stop_codes);
@ -207,4 +216,6 @@ pub fn load_gtfs(
stop_ids: &stop_ids, stop_ids: &stop_ids,
}, },
); );
debug!("Loaded {} stop time entries", gtfs.stop_times.keys().len());
} }

View File

@ -2,6 +2,8 @@ mod loader;
mod utils; mod utils;
pub mod structs; pub mod structs;
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use log::{debug, info, warn};
use sdl3::libc::stpncpy;
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
fs::File, fs::File,
@ -45,6 +47,7 @@ impl Gtfs {
active_service_ids.insert(id.to_string()); active_service_ids.insert(id.to_string());
} }
} }
debug!("Found {} services active today", active_service_ids.len());
// Are there any exceptions for the calendars above? // Are there any exceptions for the calendars above?
for (_calendar_id, exceptions) in self.calendar_dates.iter() { for (_calendar_id, exceptions) in self.calendar_dates.iter() {
@ -61,6 +64,7 @@ impl Gtfs {
} }
} }
} }
debug!("After exceptions, there are now {} services active", active_service_ids.len());
// Find the trips happening on these calendars // Find the trips happening on these calendars
let mut trips: HashMap<&String, &RawTrip> = HashMap::new(); let mut trips: HashMap<&String, &RawTrip> = HashMap::new();
@ -69,6 +73,7 @@ impl Gtfs {
trips.insert(&trip.id, trip); trips.insert(&trip.id, trip);
} }
} }
debug!("Found {} trips", trips.len());
// Finally, find the arrivals for the active trips on the chosen stops // Finally, find the arrivals for the active trips on the chosen stops
let mut arrivals: Vec<Arrival> = Vec::new(); let mut arrivals: Vec<Arrival> = Vec::new();
@ -76,6 +81,7 @@ impl Gtfs {
for (_id, stop_time) in self.stop_times.iter() { for (_id, stop_time) in self.stop_times.iter() {
if trips.contains_key(&stop_time.trip_id) { if trips.contains_key(&stop_time.trip_id) {
let stop_timestamp = stop_time.departure_time.or(stop_time.arrival_time).unwrap(); let stop_timestamp = stop_time.departure_time.or(stop_time.arrival_time).unwrap();
debug!("Stop timestamp {} current timestamp {}", stop_timestamp, current_timestamp);
if current_timestamp < stop_timestamp.into() { if current_timestamp < stop_timestamp.into() {
let arrival: Arrival = Arrival { let arrival: Arrival = Arrival {
route: self.routes.get(&self.trips.get(&stop_time.trip_id).unwrap().route_id).unwrap(), route: self.routes.get(&self.trips.get(&stop_time.trip_id).unwrap().route_id).unwrap(),
@ -86,6 +92,7 @@ impl Gtfs {
} }
} }
} }
debug!("Found {} arrivals", arrivals.len());
return Box::from(arrivals); return Box::from(arrivals);
} }

View File

@ -2,7 +2,8 @@ mod gtfs;
mod renderer; mod renderer;
use std::{collections::HashSet, process, time::SystemTime}; use std::{collections::HashSet, process, time::SystemTime};
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use sdl3::event::Event; use sdl3::{event::Event, libc::statx_timestamp};
use log::{Level, Metadata, Record, debug, error, info, warn};
use crate::{gtfs::Gtfs, renderer::Screen}; use crate::{gtfs::Gtfs, renderer::Screen};
@ -12,12 +13,33 @@ fn refresh_schedule(gtfs: &Gtfs) {
let current_timestamp = SystemTime::now(); let current_timestamp = SystemTime::now();
let datetime: DateTime<Local> = current_timestamp.clone().into(); let datetime: DateTime<Local> = current_timestamp.clone().into();
let next_arrivals = gtfs.get_next_arrivals_for(&datetime); let next_arrivals = gtfs.get_next_arrivals_for(&datetime);
print!("Next arrivals: {:#?}", next_arrivals); debug!("Next arrivals: {:#?}", next_arrivals);
} }
fn main() { fn main() {
// Initialize logger
static MY_LOGGER: MyLogger = MyLogger;
struct MyLogger;
impl log::Log for MyLogger {
fn enabled(&self, _metadata: &Metadata) -> bool {
true
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
let timestamp = chrono::DateTime::<Local>::from(SystemTime::now()).format("%Y%m%d:%H%M%S");
println!("{} - {} - {}", timestamp, record.level(), record.args());
}
}
fn flush(&self) {}
}
log::set_logger(&MY_LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Trace);
let gtfs_prefs = gtfs::structs::Preferences { let gtfs_prefs = gtfs::structs::Preferences {
route_numbers: HashSet::from([String::from("15A"), String::from("F1"), String::from("F2"), String::from("F3")]), route_numbers: HashSet::from([String::from("15A"), String::from("F1"), String::from("F2"), String::from("F3")]),
stop_codes: HashSet::from([String::from("1117")]) stop_codes: HashSet::from([String::from("1117")])
@ -30,20 +52,22 @@ fn main() {
}; };
// Init GTFS static info // Init GTFS static info
println!("Loading GTFS data..."); info!("Loading GTFS data...");
let gtfs = Gtfs::load(SRC_FILE, &gtfs_prefs); let gtfs = Gtfs::load(SRC_FILE, &gtfs_prefs);
// Init screen // Init screen
println!("Initializing screen..."); //println!("Initializing screen...");
let screen = Screen::init(&screen_prefs); //let screen = Screen::init(&screen_prefs);
println!("Startup done."); //println!("Startup done.");
// Start an asynchronous refresh thread // Start an asynchronous refresh thread
//let _update_thread = thread::Builder::new().name("updater".to_string()).spawn(move || { refresh_schedule(&gtfs) }); //let _update_thread = thread::Builder::new().name("updater".to_string()).spawn(move || { refresh_schedule(&gtfs) });
refresh_schedule(&gtfs); refresh_schedule(&gtfs);
debug!("Refresh done.");
// Main event loop // Main event loop
/*
let mut event_pump = screen.get_context().event_pump().unwrap(); let mut event_pump = screen.get_context().event_pump().unwrap();
loop { loop {
let event = event_pump.wait_event(); let event = event_pump.wait_event();
@ -61,5 +85,5 @@ fn main() {
_ => {} _ => {}
} }
} } */
} }