Made GFS code into an ADT

This commit is contained in:
2026-04-21 08:32:49 +01:00
parent 4d527a9ada
commit 707aecdba7
5 changed files with 48 additions and 42 deletions
+42 -16
View File
@@ -5,31 +5,57 @@ use std::{
collections::{HashMap},
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<'_>> {
let arrivals = Vec::<Arrival>::new();
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>,
}
impl Gtfs {
pub fn _get_next_stops(&self) -> Vec<Arrival<'_>> {
let arrivals = Vec::<Arrival>::new();
return arrivals;
}
/// Load a GTFS structure from a zip file
pub fn load(src_file: &str, prefs: &Preferences) -> Gtfs {
// Open zip file
let mut zip_reader = zip::ZipArchive::new(File::open(src_file).unwrap()).unwrap();
/// Load a GTFS structure from a zip file
pub fn load(src_file: &str, prefs: &Preferences) -> Gtfs {
// Open zip file
let mut zip_reader = zip::ZipArchive::new(File::open(src_file).unwrap()).unwrap();
let mut gtfs: Gtfs = Gtfs {
agencies: Vec::new(),
calendar: HashMap::new(),
calendar_dates: HashMap::new(),
routes: HashMap::new(),
stops: HashMap::new(),
trips: HashMap::new(),
stop_times: HashMap::new(),
};
let mut gtfs: Gtfs = Gtfs {
agencies: Vec::new(),
calendar: HashMap::new(),
calendar_dates: HashMap::new(),
routes: HashMap::new(),
stops: HashMap::new(),
trips: HashMap::new(),
stop_times: HashMap::new(),
};
load_gtfs(&mut gtfs, &mut zip_reader, &prefs.route_numbers, &prefs.stop_codes);
return gtfs;
}
}