Added an obscene amount of debug logging.
This commit is contained in:
parent
ca6857dda9
commit
4d272c31c5
|
|
@ -9,6 +9,7 @@ sdl3 = {version = "0.17", features = ["ttf"]}
|
|||
serde = "1.0"
|
||||
gtfs-structures = "0.47"
|
||||
chrono = "*"
|
||||
log = "*"
|
||||
zip = "8.3"
|
||||
csv = "1.4"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use log::{debug, info, warn};
|
||||
use gtfs_structures::{Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::{
|
||||
|
|
@ -152,6 +153,7 @@ pub fn load_gtfs(
|
|||
|c: &Calendar| String::from(&c.id),
|
||||
LoadAll {},
|
||||
);
|
||||
debug!("Loaded {} calendar entries", gtfs.calendar.keys().len());
|
||||
|
||||
// Calendar Dates
|
||||
load_vector_map(
|
||||
|
|
@ -161,6 +163,7 @@ pub fn load_gtfs(
|
|||
|d: &CalendarDate| String::from(&d.service_id),
|
||||
LoadAll {},
|
||||
);
|
||||
debug!("Loaded {} calendar date keys", gtfs.calendar_dates.keys().len());
|
||||
|
||||
// Routes
|
||||
load_map(
|
||||
|
|
@ -172,6 +175,8 @@ pub fn load_gtfs(
|
|||
routes: &route_numbers,
|
||||
},
|
||||
);
|
||||
debug!("Loaded {} routes", gtfs.routes.keys().len());
|
||||
|
||||
|
||||
// Stops
|
||||
load_map(
|
||||
|
|
@ -181,6 +186,8 @@ pub fn load_gtfs(
|
|||
|s: &Stop| String::from(&s.id),
|
||||
LoadStops { stops: &stop_codes },
|
||||
);
|
||||
debug!("Loaded {} stop entries", gtfs.stops.keys().len());
|
||||
|
||||
|
||||
let route_ids = route_ids_from_numbers(>fs, &route_numbers);
|
||||
// Trips
|
||||
|
|
@ -193,6 +200,8 @@ pub fn load_gtfs(
|
|||
route_ids: &route_ids,
|
||||
},
|
||||
);
|
||||
debug!("Loaded {} trip entries", gtfs.trips.keys().len());
|
||||
|
||||
|
||||
// Load stop times for the chosen routes and stops
|
||||
let stop_ids = stop_ids_from_codes(>fs, &stop_codes);
|
||||
|
|
@ -207,4 +216,6 @@ pub fn load_gtfs(
|
|||
stop_ids: &stop_ids,
|
||||
},
|
||||
);
|
||||
debug!("Loaded {} stop time entries", gtfs.stop_times.keys().len());
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ mod loader;
|
|||
mod utils;
|
||||
pub mod structs;
|
||||
use chrono::{DateTime, Local};
|
||||
use log::{debug, info, warn};
|
||||
use sdl3::libc::stpncpy;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fs::File,
|
||||
|
|
@ -45,6 +47,7 @@ impl Gtfs {
|
|||
active_service_ids.insert(id.to_string());
|
||||
}
|
||||
}
|
||||
debug!("Found {} services active today", active_service_ids.len());
|
||||
|
||||
// Are there any exceptions for the calendars above?
|
||||
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
|
||||
let mut trips: HashMap<&String, &RawTrip> = HashMap::new();
|
||||
|
|
@ -69,6 +73,7 @@ impl Gtfs {
|
|||
trips.insert(&trip.id, trip);
|
||||
}
|
||||
}
|
||||
debug!("Found {} trips", trips.len());
|
||||
|
||||
// Finally, find the arrivals for the active trips on the chosen stops
|
||||
let mut arrivals: Vec<Arrival> = Vec::new();
|
||||
|
|
@ -76,6 +81,7 @@ impl Gtfs {
|
|||
for (_id, stop_time) in self.stop_times.iter() {
|
||||
if trips.contains_key(&stop_time.trip_id) {
|
||||
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() {
|
||||
let arrival: Arrival = Arrival {
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
38
src/main.rs
38
src/main.rs
|
|
@ -2,7 +2,8 @@ mod gtfs;
|
|||
mod renderer;
|
||||
use std::{collections::HashSet, process, time::SystemTime};
|
||||
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};
|
||||
|
||||
|
|
@ -12,12 +13,33 @@ fn refresh_schedule(gtfs: &Gtfs) {
|
|||
let current_timestamp = SystemTime::now();
|
||||
let datetime: DateTime<Local> = current_timestamp.clone().into();
|
||||
let next_arrivals = gtfs.get_next_arrivals_for(&datetime);
|
||||
print!("Next arrivals: {:#?}", next_arrivals);
|
||||
debug!("Next arrivals: {:#?}", next_arrivals);
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
route_numbers: HashSet::from([String::from("15A"), String::from("F1"), String::from("F2"), String::from("F3")]),
|
||||
stop_codes: HashSet::from([String::from("1117")])
|
||||
|
|
@ -30,20 +52,22 @@ fn main() {
|
|||
};
|
||||
|
||||
// Init GTFS static info
|
||||
println!("Loading GTFS data...");
|
||||
info!("Loading GTFS data...");
|
||||
let gtfs = Gtfs::load(SRC_FILE, >fs_prefs);
|
||||
|
||||
// Init screen
|
||||
println!("Initializing screen...");
|
||||
let screen = Screen::init(&screen_prefs);
|
||||
println!("Startup done.");
|
||||
//println!("Initializing screen...");
|
||||
//let screen = Screen::init(&screen_prefs);
|
||||
//println!("Startup done.");
|
||||
|
||||
// Start an asynchronous refresh thread
|
||||
//let _update_thread = thread::Builder::new().name("updater".to_string()).spawn(move || { refresh_schedule(>fs) });
|
||||
|
||||
refresh_schedule(>fs);
|
||||
debug!("Refresh done.");
|
||||
|
||||
// Main event loop
|
||||
/*
|
||||
let mut event_pump = screen.get_context().event_pump().unwrap();
|
||||
loop {
|
||||
let event = event_pump.wait_event();
|
||||
|
|
@ -61,5 +85,5 @@ fn main() {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue