Moved GTFS struct back to structs, refresh works now.
This commit is contained in:
parent
4d272c31c5
commit
ca0003edfd
|
|
@ -9,7 +9,7 @@ use std::{
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
use crate::gtfs::{
|
use crate::gtfs::{
|
||||||
Gtfs,
|
structs::Gtfs,
|
||||||
utils::{route_ids_from_numbers, stop_ids_from_codes},
|
utils::{route_ids_from_numbers, stop_ids_from_codes},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,15 @@
|
||||||
mod loader;
|
mod loader;
|
||||||
mod utils;
|
mod utils;
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
use chrono::{DateTime, Local};
|
use chrono::{DateTime, Local, NaiveTime, Timelike};
|
||||||
use log::{debug, info, warn};
|
use log::{debug};
|
||||||
use sdl3::libc::stpncpy;
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fs::File,
|
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}};
|
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, 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>,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
impl Gtfs {
|
impl Gtfs {
|
||||||
|
|
@ -77,7 +57,12 @@ impl Gtfs {
|
||||||
|
|
||||||
// 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();
|
||||||
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() {
|
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();
|
||||||
|
|
@ -86,7 +71,7 @@ impl Gtfs {
|
||||||
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(),
|
||||||
stop: self.stops.get(&stop_time.stop_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);
|
arrivals.push(arrival);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::collections::{HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use gtfs_structures::{Route, Stop};
|
use chrono::NaiveTime;
|
||||||
|
use gtfs_structures::{Agency, Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop};
|
||||||
|
|
||||||
// This is to store the preferences for the GTFS(-R) side of the code.
|
// This is to store the preferences for the GTFS(-R) side of the code.
|
||||||
pub struct Preferences {
|
pub struct Preferences {
|
||||||
|
|
@ -8,10 +9,31 @@ pub struct Preferences {
|
||||||
pub stop_codes: HashSet<String>,
|
pub stop_codes: HashSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
||||||
pub struct Arrival<'a> {
|
pub struct Arrival<'a> {
|
||||||
pub route: &'a Route,
|
pub route: &'a Route,
|
||||||
pub stop: &'a Stop,
|
pub stop: &'a Stop,
|
||||||
pub departure_time: u32,
|
pub departure_time: NaiveTime,
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ use chrono::{DateTime, Local};
|
||||||
use sdl3::{event::Event, libc::statx_timestamp};
|
use sdl3::{event::Event, libc::statx_timestamp};
|
||||||
use log::{Level, Metadata, Record, debug, error, info, warn};
|
use log::{Level, Metadata, Record, debug, error, info, warn};
|
||||||
|
|
||||||
use crate::{gtfs::Gtfs, renderer::Screen};
|
use crate::{gtfs::structs::Gtfs, renderer::Screen};
|
||||||
|
|
||||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue