Moved GTFS struct back to structs, refresh works now.
This commit is contained in:
+11
-26
@@ -1,35 +1,15 @@
|
||||
mod loader;
|
||||
mod utils;
|
||||
pub mod structs;
|
||||
use chrono::{DateTime, Local};
|
||||
use log::{debug, info, warn};
|
||||
use sdl3::libc::stpncpy;
|
||||
use chrono::{DateTime, Local, NaiveTime, Timelike};
|
||||
use log::{debug};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fs::File,
|
||||
};
|
||||
use gtfs_structures::{Agency, Calendar, CalendarDate, Exception, RawStopTime, RawTrip, Route, Stop};
|
||||
use gtfs_structures::{Exception, RawTrip};
|
||||
|
||||
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Preferences}};
|
||||
|
||||
// The main GTFS struct. This is similar to (but not exactly) gtfs-structures::Gtfs because we don't need everything
|
||||
#[derive(Debug)]
|
||||
pub struct Gtfs {
|
||||
/// All agencies. They can not be read by `agency_id`, as it is not a required field
|
||||
pub agencies: Vec<Agency>,
|
||||
/// All Calendar by `service_id`
|
||||
pub calendar: HashMap<String, Calendar>,
|
||||
/// All calendar dates grouped by service_id
|
||||
pub calendar_dates: HashMap<String, Vec<CalendarDate>>,
|
||||
/// All routes by `route_id`
|
||||
pub routes: HashMap<String, Route>,
|
||||
/// All stop by `stop_id`.
|
||||
pub stops: HashMap<String, Stop>,
|
||||
/// All trips by trip_id
|
||||
pub trips: HashMap<String, RawTrip>,
|
||||
/// Stop times for the chosen stops and the chosen routes
|
||||
pub stop_times: HashMap<(String, u32), RawStopTime>,
|
||||
}
|
||||
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences}};
|
||||
|
||||
|
||||
impl Gtfs {
|
||||
@@ -77,7 +57,12 @@ impl Gtfs {
|
||||
|
||||
// Finally, find the arrivals for the active trips on the chosen stops
|
||||
let mut arrivals: Vec<Arrival> = Vec::new();
|
||||
let current_timestamp = target_datetime.timestamp();
|
||||
|
||||
// Stop times are parsed as the number of seconds since midnight on the current day
|
||||
let current_timestamp = target_datetime.time().hour() * 3600
|
||||
+ target_datetime.time().minute() * 60
|
||||
+ target_datetime.time().second();
|
||||
|
||||
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();
|
||||
@@ -86,7 +71,7 @@ impl Gtfs {
|
||||
let arrival: Arrival = Arrival {
|
||||
route: self.routes.get(&self.trips.get(&stop_time.trip_id).unwrap().route_id).unwrap(),
|
||||
stop: self.stops.get(&stop_time.stop_id).unwrap(),
|
||||
departure_time: stop_timestamp
|
||||
departure_time: NaiveTime::from_num_seconds_from_midnight_opt(stop_timestamp, 0).unwrap()
|
||||
};
|
||||
arrivals.push(arrival);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user