Introduced preferences struct
This commit is contained in:
parent
a22e1ee3fa
commit
34dad5e000
|
|
@ -129,7 +129,7 @@ fn load_vector_map<'a, K, V, IndexFn, FilterT>(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn load_gtfs(gtfs: &mut Gtfs, zip_reader: &mut ZipArchive<File>, route_numbers: HashSet<String>, stop_codes: HashSet<String>) {
|
pub fn load_gtfs(gtfs: &mut Gtfs, zip_reader: &mut ZipArchive<File>, route_numbers: &HashSet<String>, stop_codes: &HashSet<String>) {
|
||||||
|
|
||||||
// Agencies
|
// Agencies
|
||||||
load_vector(&mut gtfs.agencies, zip_reader, "agency.txt");
|
load_vector(&mut gtfs.agencies, zip_reader, "agency.txt");
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,23 @@
|
||||||
mod loader;
|
mod loader;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod structs;
|
pub mod structs;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fs::File,
|
fs::File,
|
||||||
};
|
};
|
||||||
use crate::gtfs::{loader::load_gtfs, structs::Gtfs};
|
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences}};
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_next_stops(gtfs: &Gtfs) -> Vec<Arrival> {
|
||||||
|
let arrivals = Vec::<Arrival>::new();
|
||||||
|
|
||||||
|
return arrivals;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Load a GTFS structure from a zip file
|
/// Load a GTFS structure from a zip file
|
||||||
pub fn load(src_file: &str, route_numbers: HashSet<String>, stop_codes: HashSet<String>) -> 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();
|
||||||
|
|
||||||
|
|
@ -24,7 +32,7 @@ pub fn load(src_file: &str, route_numbers: HashSet<String>, stop_codes: HashSet<
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
load_gtfs(&mut gtfs, &mut zip_reader, route_numbers, stop_codes);
|
load_gtfs(&mut gtfs, &mut zip_reader, &prefs.route_numbers, &prefs.stop_codes);
|
||||||
|
|
||||||
return gtfs;
|
return gtfs;
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
|
use gtfs_structures::{Agency, Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop, TimepointType};
|
||||||
|
|
||||||
|
// This is to store the preferences for the GTFS(-R) side of the code.
|
||||||
|
pub struct Preferences {
|
||||||
|
pub route_numbers: HashSet<String>,
|
||||||
|
pub stop_codes: HashSet<String>,
|
||||||
|
}
|
||||||
|
|
||||||
use gtfs_structures::{Agency, Calendar, CalendarDate, RawStopTime, RawTrip, Route, Stop};
|
|
||||||
|
|
||||||
// The main GTFS struct. This is similar to (but not exactly) gtfs-structures::Gtfs because we don't need everything
|
// The main GTFS struct. This is similar to (but not exactly) gtfs-structures::Gtfs because we don't need everything
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -20,3 +27,9 @@ pub struct Gtfs {
|
||||||
/// Stop times for the chosen stops and the chosen routes
|
/// Stop times for the chosen stops and the chosen routes
|
||||||
pub stop_times: HashMap<(String, u32), RawStopTime>,
|
pub stop_times: HashMap<(String, u32), RawStopTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Arrival<'a> {
|
||||||
|
pub route: &'a Route,
|
||||||
|
pub stop: &'a Stop,
|
||||||
|
pub timepoint: &'a TimepointType,
|
||||||
|
}
|
||||||
12
src/main.rs
12
src/main.rs
|
|
@ -1,16 +1,22 @@
|
||||||
mod gtfs;
|
mod gtfs;
|
||||||
use std::{collections::HashSet, time::Instant};
|
use std::{collections::HashSet, time::Instant};
|
||||||
|
|
||||||
|
use crate::gtfs::structs;
|
||||||
|
|
||||||
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
const SRC_FILE: &str = "/home/nahuel/Downloads/GTFS_Realtime.zip";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
|
let gtfs_prefs = 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")])
|
||||||
|
};
|
||||||
|
|
||||||
// Init GTFS static info
|
// Init GTFS static info
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
let start_gtfs = Instant::now();
|
let start_gtfs = Instant::now();
|
||||||
println!("Loading GTFS data...");
|
println!("Loading GTFS data...");
|
||||||
let gtfs = gtfs::load(SRC_FILE,
|
let gtfs = gtfs::load(SRC_FILE, >fs_prefs);
|
||||||
HashSet::from([String::from("15A"), String::from("F1"), String::from("F2"), String::from("F3")]),
|
|
||||||
HashSet::from([String::from("1117")]));
|
|
||||||
println!("Loaded records in {:#?}. Data size: {:#?}", start_gtfs.elapsed(), ::std::mem::size_of_val(>fs))
|
println!("Loaded records in {:#?}. Data size: {:#?}", start_gtfs.elapsed(), ::std::mem::size_of_val(>fs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue