Skip to content

Commit

Permalink
filter ttc subterrain for only subway
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Nov 15, 2024
1 parent 937ada7 commit af191a2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/aspen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ impl AspenRpc for AspenServer {

// println!("Saved FeedMessages for {}", realtime_feed_id);

if new_data || chateau_id == "uc~irvine~anteater~express" || chateau_id == "nj~transit~rail" {
if new_data
|| chateau_id == "uc~irvine~anteater~express"
|| chateau_id == "nj~transit~rail"
{
let mut lock_chateau_queue = self.alpenrose_to_process_queue_chateaus.lock().await;

if !lock_chateau_queue.contains(&chateau_id) {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
pub mod metrolink_ptc_to_stop_id;
pub mod rt_recent_history;
use crate::rt_recent_history::*;
pub mod schedule_filtering;
pub mod tile_save_and_get;

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
Expand Down
12 changes: 12 additions & 0 deletions src/maple/gtfs_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::collections::HashSet;
use std::error::Error;
use std::sync::Arc;
use std::time::Instant;
use gtfs_structures::Gtfs;

#[derive(Debug)]
pub struct GtfsSummary {
Expand Down Expand Up @@ -65,6 +66,17 @@ pub async fn gtfs_process_feed(

let gtfs = gtfs_structures::Gtfs::new(path.as_str())?;

let gtfs: Gtfs = match feed_id {
"f-dpz8-ttc" => {
use catenary::schedule_filtering::include_only_route_types;

let route_types = vec![gtfs_structures::RouteType::Subway];

include_only_route_types(gtfs, route_types)
},
_ => gtfs
};

println!(
"Finished reading GTFS for {}, took {:?}ms",
feed_id, gtfs.read_duration
Expand Down
55 changes: 55 additions & 0 deletions src/schedule_filtering/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::collections::BTreeSet;

use gtfs_structures::*;

pub fn include_only_route_types(gtfs: Gtfs, route_types: Vec<gtfs_structures::RouteType>) -> Gtfs {
let mut gtfs = gtfs;

let route_ids_to_keep: BTreeSet<String> = gtfs
.routes
.iter()
.filter(|(route_id, route)| route_types.contains(&route.route_type))
.map(|(route_id, route)| route_id)
.cloned()
.collect();

let trips_to_keep: BTreeSet<String> = gtfs
.trips
.iter()
.filter(|(trip_id, trip)| route_ids_to_keep.contains(&trip.route_id))
.map(|(trip_id, trip)| trip_id)
.cloned()
.collect();

let mut keep_stop_ids: BTreeSet<String> = BTreeSet::new();

for trip_id in &trips_to_keep {
let trip = gtfs.trips.get(trip_id).unwrap();

for stop_time in &trip.stop_times {
keep_stop_ids.insert(stop_time.stop.id.clone());
}
}

// remove data that are not needed

gtfs.routes = gtfs
.routes
.into_iter()
.filter(|(route_id, route)| route_ids_to_keep.contains(route_id))
.collect();

gtfs.trips = gtfs
.trips
.into_iter()
.filter(|(trip_id, trip)| trips_to_keep.contains(trip_id))
.collect();

gtfs.stops = gtfs
.stops
.into_iter()
.filter(|(stop_id, stop)| keep_stop_ids.contains(stop_id))
.collect();

gtfs
}

0 comments on commit af191a2

Please sign in to comment.