Made GFS code into an ADT
This commit is contained in:
parent
4d527a9ada
commit
707aecdba7
|
|
@ -8,7 +8,7 @@ use std::{
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
|
|
||||||
use crate::gtfs::{
|
use crate::gtfs::{
|
||||||
structs::Gtfs,
|
Gtfs,
|
||||||
utils::{route_ids_from_numbers, stop_ids_from_codes},
|
utils::{route_ids_from_numbers, stop_ids_from_codes},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,31 +5,57 @@ use std::{
|
||||||
collections::{HashMap},
|
collections::{HashMap},
|
||||||
fs::File,
|
fs::File,
|
||||||
};
|
};
|
||||||
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences}};
|
use gtfs_structures::{Agency, Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop, TimepointType};
|
||||||
|
|
||||||
pub fn _get_next_stops(_gtfs: &Gtfs) -> Vec<Arrival<'_>> {
|
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Preferences}};
|
||||||
let arrivals = Vec::<Arrival>::new();
|
|
||||||
|
// 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 {
|
||||||
|
|
||||||
|
pub fn _get_next_stops(&self) -> Vec<Arrival<'_>> {
|
||||||
|
let arrivals = Vec::<Arrival>::new();
|
||||||
|
|
||||||
return arrivals;
|
return arrivals;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load a GTFS structure from a zip file
|
/// Load a GTFS structure from a zip file
|
||||||
pub fn load(src_file: &str, prefs: &Preferences) -> Gtfs {
|
pub fn load(src_file: &str, prefs: &Preferences) -> Gtfs {
|
||||||
// Open zip file
|
// Open zip file
|
||||||
let mut zip_reader = zip::ZipArchive::new(File::open(src_file).unwrap()).unwrap();
|
let mut zip_reader = zip::ZipArchive::new(File::open(src_file).unwrap()).unwrap();
|
||||||
|
|
||||||
let mut gtfs: Gtfs = Gtfs {
|
let mut gtfs: Gtfs = Gtfs {
|
||||||
agencies: Vec::new(),
|
agencies: Vec::new(),
|
||||||
calendar: HashMap::new(),
|
calendar: HashMap::new(),
|
||||||
calendar_dates: HashMap::new(),
|
calendar_dates: HashMap::new(),
|
||||||
routes: HashMap::new(),
|
routes: HashMap::new(),
|
||||||
stops: HashMap::new(),
|
stops: HashMap::new(),
|
||||||
trips: HashMap::new(),
|
trips: HashMap::new(),
|
||||||
stop_times: HashMap::new(),
|
stop_times: HashMap::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
load_gtfs(&mut gtfs, &mut zip_reader, &prefs.route_numbers, &prefs.stop_codes);
|
load_gtfs(&mut gtfs, &mut zip_reader, &prefs.route_numbers, &prefs.stop_codes);
|
||||||
|
|
||||||
return gtfs;
|
return gtfs;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashSet};
|
||||||
|
|
||||||
use gtfs_structures::{Agency, Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop, TimepointType};
|
use gtfs_structures::{TimepointType, 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 {
|
||||||
|
|
@ -9,25 +9,6 @@ pub struct 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>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Arrival<'a> {
|
pub struct Arrival<'a> {
|
||||||
pub route: &'a Route,
|
pub route: &'a Route,
|
||||||
pub stop: &'a Stop,
|
pub stop: &'a Stop,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use crate::gtfs::structs::Gtfs;
|
use crate::gtfs::Gtfs;
|
||||||
|
|
||||||
|
|
||||||
pub fn stop_ids_from_codes(gtfs: &Gtfs, stop_codes: &HashSet<String>) -> HashSet<String> {
|
pub fn stop_ids_from_codes(gtfs: &Gtfs, stop_codes: &HashSet<String>) -> HashSet<String> {
|
||||||
let mut ids: HashSet<String> = HashSet::new();
|
let mut ids: HashSet<String> = HashSet::new();
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::{collections::HashSet, thread, time::Duration};
|
||||||
|
|
||||||
use sdl3::event::{self, Event, EventWatchCallback};
|
use sdl3::event::{self, Event, EventWatchCallback};
|
||||||
|
|
||||||
use crate::renderer::Screen;
|
use crate::{gtfs::Gtfs, renderer::Screen};
|
||||||
|
|
||||||
|
|
||||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||||
|
|
@ -33,7 +33,7 @@ fn main() {
|
||||||
|
|
||||||
// Init GTFS static info
|
// Init GTFS static info
|
||||||
println!("Loading GTFS data...");
|
println!("Loading GTFS data...");
|
||||||
//let _gtfs = gtfs::load(SRC_FILE, >fs_prefs);
|
//let _gtfs = Gtfs::load(SRC_FILE, >fs_prefs);
|
||||||
|
|
||||||
// Init screen
|
// Init screen
|
||||||
println!("Initializing screen...");
|
println!("Initializing screen...");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue