-
Notifications
You must be signed in to change notification settings - Fork 0
migrate_gtfs_data_from_nandi_to_gims #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blaze-198
wants to merge
8
commits into
main
Choose a base branch
from
migrate_gtfs_data_from_nandi_to_gims
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1dbfd5a
feat: push to gcp sandbox and prod registries
pranavs6 e8ce13a
exposing cluster id for stops
sameerzohy e86c24c
added query param for clusterId exposing
sameerzohy a99410d
call_chalo_api_with_call_api
blaze-198 90e87c7
migrate_gtfs_data_from_nandi_to_gims
blaze-198 fee3f98
chore: update preprocessed GTFS data from Nandi build (5c729d)
4ff5d01
chore: update preprocessed GTFS data from Nandi build (b2ba47)
11deece
chore: update preprocessed GTFS data from Nandi build (5ad145)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| { | ||
| "version": "60c162a080f3", | ||
| "build_commit": "5ad145", | ||
| "generated_at": "2026-06-05T19:44:13Z", | ||
| "gtfs_feeds": [ | ||
| "bangalore_metro", | ||
| "bhubaneshwar_bus", | ||
| "chennai_bus", | ||
| "chennai_metro", | ||
| "chennai_suburban", | ||
| "delhi_bus_nammayatri_application_mock", | ||
| "delhi_metro", | ||
| "kochi_metro", | ||
| "kolkata_bus", | ||
| "kolkata_metro", | ||
| "mumbai_metro", | ||
| "mumbai_suburban", | ||
| "sambalpur_bus" | ||
| ], | ||
| "files": { | ||
| "routes.json": { | ||
| "sha256": "4985f6d10c1ef7fc6c3181b07dd4a92ee8f0d1a17e0f9c7fe58f9d9b1fc5dc3e", | ||
| "count": 5643 | ||
| }, | ||
| "stops.json": { | ||
| "sha256": "074bcec44ac8d4ddc7eae05e86470b6faaaa4141f3a3df2c59bdbd25b3ffe53c", | ||
| "count": 24998 | ||
| }, | ||
| "patterns.json": { | ||
| "sha256": "efd57d7bff3fecbb1dc4e29dc11b5515665c05989fbc03b58b5e7b85c33fa7e7", | ||
| "count": 5755 | ||
| }, | ||
| "route_stops.json": { | ||
| "sha256": "7a1a7077970d8aae04ea9f910fe3b4e0cfcd495bdceffc41de26967839fb3893", | ||
| "count": 109280 | ||
| }, | ||
| "trip_stoptimes/bangalore_metro.json": { | ||
| "sha256": "e639d9a639c089d51cfd85efadcda52c2b5a277e8c6a77b159d5b4c4ea8a17f4", | ||
| "count": 2722 | ||
| }, | ||
| "trip_stoptimes/bhubaneshwar_bus.json": { | ||
| "sha256": "70816626318d547ab9cd801f62369af29c8c878d6a1dc3409dd4d6bb194ff47e", | ||
| "count": 4199 | ||
| }, | ||
| "trip_stoptimes/chennai_bus.json": { | ||
| "sha256": "5ab26b1ea65ef894f0d7f22f6db60d4be28215703178bca1677d4f47fe63f029", | ||
| "count": 51512 | ||
| }, | ||
| "trip_stoptimes/chennai_metro.json": { | ||
| "sha256": "19433454474303f58dc3428ccd33aa8c32239d9b2956a4299a539dc28e34a9a1", | ||
| "count": 3738 | ||
| }, | ||
| "trip_stoptimes/chennai_suburban.json": { | ||
| "sha256": "981ea7728f23fdf991e83329fd6988090f63a56f3955ef87ce1f11bd5f20ef9a", | ||
| "count": 807 | ||
| }, | ||
| "trip_stoptimes/delhi_bus_nammayatri_application_mock.json": { | ||
| "sha256": "da9b10ea10dd6dcd3c9ca2bf9cc33d26c874c03ba0f78dda9cbb89bf4b320b60", | ||
| "count": 24 | ||
| }, | ||
| "trip_stoptimes/delhi_metro.json": { | ||
| "sha256": "ae75e590e6a4149e9f1355ddbc76a105a0104aa9ad9a1cd1842ac7a3a1587c8c", | ||
| "count": 21825 | ||
| }, | ||
| "trip_stoptimes/kochi_metro.json": { | ||
| "sha256": "13c6cb2d264d3f10e50351801f7d3cebd0b3fd68e7460d5797b2e1223fcbb928", | ||
| "count": 450 | ||
| }, | ||
| "trip_stoptimes/kolkata_bus.json": { | ||
| "sha256": "b2d61d80185de6db39c61f3a475ff61065fe3794a2eeb73f9d0002983655816f", | ||
| "count": 17227 | ||
| }, | ||
| "trip_stoptimes/kolkata_metro.json": { | ||
| "sha256": "d84a6561c5b6415fb9d63ab1738ba502ff0fed7fcaf75572f38c6d2fa3ec0d19", | ||
| "count": 1652 | ||
| }, | ||
| "trip_stoptimes/mumbai_metro.json": { | ||
| "sha256": "4b04febcf317c01a7a3344232538e1f76677a8055947f2f4acb5fff549f9e145", | ||
| "count": 278 | ||
| }, | ||
| "trip_stoptimes/mumbai_suburban.json": { | ||
| "sha256": "8a374cba7e8b57f9cb8e9c43300984dd7014e2a51e3cc210c7a41fdfa928d2d7", | ||
| "count": 134 | ||
| }, | ||
| "trip_stoptimes/sambalpur_bus.json": { | ||
| "sha256": "11196eed2c41b0aa60e8f4268aa5eeb7aa04de108bcb046ade0800fa8f22f496", | ||
| "count": 405 | ||
| } | ||
| }, | ||
| "stats": { | ||
| "bangalore_metro": { | ||
| "routes": 6, | ||
| "stops": 472, | ||
| "patterns": 58, | ||
| "route_stop_mappings": 170 | ||
| }, | ||
| "bhubaneshwar_bus": { | ||
| "routes": 493, | ||
| "stops": 2916, | ||
| "patterns": 493, | ||
| "route_stop_mappings": 16875 | ||
| }, | ||
| "chennai_bus": { | ||
| "routes": 4138, | ||
| "stops": 17909, | ||
| "patterns": 4138, | ||
| "route_stop_mappings": 71269 | ||
| }, | ||
| "chennai_metro": { | ||
| "routes": 44, | ||
| "stops": 313, | ||
| "patterns": 50, | ||
| "route_stop_mappings": 593 | ||
| }, | ||
| "chennai_suburban": { | ||
| "routes": 804, | ||
| "stops": 722, | ||
| "patterns": 807, | ||
| "route_stop_mappings": 16814 | ||
| }, | ||
| "delhi_bus_nammayatri_application_mock": { | ||
| "routes": 1, | ||
| "stops": 11, | ||
| "patterns": 1, | ||
| "route_stop_mappings": 11 | ||
| }, | ||
| "delhi_metro": { | ||
| "routes": 22, | ||
| "stops": 1126, | ||
| "patterns": 57, | ||
| "route_stop_mappings": 561 | ||
| }, | ||
| "kochi_metro": { | ||
| "routes": 2, | ||
| "stops": 25, | ||
| "patterns": 8, | ||
| "route_stop_mappings": 50 | ||
| }, | ||
| "kolkata_bus": { | ||
| "routes": 88, | ||
| "stops": 693, | ||
| "patterns": 88, | ||
| "route_stop_mappings": 1773 | ||
| }, | ||
| "kolkata_metro": { | ||
| "routes": 10, | ||
| "stops": 182, | ||
| "patterns": 20, | ||
| "route_stop_mappings": 114 | ||
| }, | ||
| "mumbai_metro": { | ||
| "routes": 2, | ||
| "stops": 12, | ||
| "patterns": 2, | ||
| "route_stop_mappings": 24 | ||
| }, | ||
| "mumbai_suburban": { | ||
| "routes": 2, | ||
| "stops": 37, | ||
| "patterns": 2, | ||
| "route_stop_mappings": 74 | ||
| }, | ||
| "sambalpur_bus": { | ||
| "routes": 31, | ||
| "stops": 580, | ||
| "patterns": 31, | ||
| "route_stop_mappings": 952 | ||
| } | ||
| } | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ use crate::services::{ | |
| }, | ||
| fleet_operator::{DBFleetOperatorService, FleetOperatorService, MockFleetOperatorService}, | ||
| gtfs_service::GTFSService, | ||
| metro_graph::MetroGraph, | ||
| operator::{DBOperatorService, MockOperatorService, OperatorService}, | ||
| osrtc_station_cache::OsrtcStationCache, | ||
| trip_service::TripService, | ||
|
|
@@ -70,6 +71,15 @@ pub struct AppConfig { | |
| pub ignored_trip_ids: Vec<String>, | ||
| pub bhubaneswar_cache_update_interval: u64, | ||
| pub bhubaneswar_external_auth: Option<String>, | ||
| /// When true, load GTFS data from preprocessed JSON files (produced by | ||
| /// Nandi preprocessor) instead of calling Nandi/OTP APIs. | ||
| #[serde(default)] | ||
| pub use_preprocessed_data: bool, | ||
| /// Directory containing preprocessed JSON files (routes.json, stops.json, | ||
| /// patterns.json, route_stops.json, metadata.json). | ||
| /// Defaults to "./assets" if not set. | ||
| #[serde(default = "default_preprocessed_data_dir")] | ||
| pub preprocessed_data_dir: String, | ||
| pub phone_number_hash_key: String, | ||
| /// Enable schedule-based active trip reconciliation (default: false) | ||
| pub enable_schedule_reconciliation: bool, | ||
|
|
@@ -80,6 +90,10 @@ pub struct AppConfig { | |
| pub osrtc_feed_key: Option<String>, | ||
| } | ||
|
|
||
| fn default_preprocessed_data_dir() -> String { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
| "./assets".to_string() | ||
| } | ||
|
|
||
| impl OtpConfig { | ||
| pub fn find_instance_by_gtfs_id(&self, gtfs_id: &str) -> Option<&OtpInstance> { | ||
| self.gtfs_id_based_instances | ||
|
|
@@ -148,6 +162,8 @@ pub struct AppState { | |
| pub bus_registration_mapping: Arc<HashMap<String, HashMap<String, String>>>, | ||
| pub fleet_list: Arc<HashMap<String, HashMap<String, Vec<String>>>>, | ||
| pub vehicle_service_sub_types: Arc<HashMap<String, HashMap<String, Vec<String>>>>, | ||
| /// Metro transit graphs loaded from preprocessed JSON (gtfs_id -> MetroGraph) | ||
| pub metro_graphs: Arc<HashMap<String, MetroGraph>>, | ||
| pub depot_manager_details: Arc<HashMap<String, crate::models::DepotManagerDetails>>, | ||
| pub fleet_tag_list: Arc<HashMap<String, HashMap<String, String>>>, | ||
| pub chennai_service_type_cache: Arc<RwLock<HashMap<String, (Instant, Option<String>)>>>, | ||
|
|
@@ -354,6 +370,7 @@ impl AppState { | |
|
|
||
| // Load bus registration mapping from CSV | ||
| let bus_registration_mapping = Arc::new(Self::load_bus_registration_mapping().await?); | ||
| let metro_graphs = Arc::new(Self::load_metro_graphs(&app_config)); | ||
|
|
||
| // Load depot manager details from CSV | ||
| let depot_manager_details = Arc::new(Self::load_depot_manager_details().await?); | ||
|
|
@@ -372,6 +389,7 @@ impl AppState { | |
| bus_registration_mapping, | ||
| fleet_list: Arc::new(Self::load_fleet_list().await?), | ||
| vehicle_service_sub_types: Arc::new(Self::load_vehicle_service_sub_types().await?), | ||
| metro_graphs, | ||
| depot_manager_details, | ||
| fleet_tag_list: Arc::new(Self::load_fleet_tag_list().await?), | ||
| chennai_service_type_cache: Arc::new(RwLock::new(HashMap::new())), | ||
|
|
@@ -604,6 +622,61 @@ impl AppState { | |
| Ok(sub_types_map) | ||
| } | ||
|
|
||
| /// Load metro transit graphs from preprocessed JSON files in the | ||
| /// preprocessed data directory. | ||
| /// | ||
| /// Looks for `metro_graph.json` which contains a map of gtfs_id -> MetroGraph. | ||
| /// If the file doesn't exist, returns an empty map (metro routing won't | ||
| /// be available but all other APIs work fine). | ||
| fn load_metro_graphs(config: &AppConfig) -> HashMap<String, MetroGraph> { | ||
| let graph_file = std::path::Path::new(&config.preprocessed_data_dir) | ||
| .join("metro_graph.json"); | ||
|
|
||
| if !graph_file.exists() { | ||
| info!( | ||
| "No metro_graph.json found in {}, metro routing will not be available", | ||
| config.preprocessed_data_dir | ||
| ); | ||
| return HashMap::new(); | ||
| } | ||
|
|
||
| info!( | ||
| "Loading metro graphs from {}", | ||
| graph_file.display() | ||
| ); | ||
|
|
||
| match std::fs::read_to_string(&graph_file) { | ||
| Ok(json) => match serde_json::from_str::<HashMap<String, MetroGraph>>(&json) { | ||
| Ok(graphs) => { | ||
| for (gtfs_id, graph) in &graphs { | ||
| info!( | ||
| "Loaded metro graph for {}: {} nodes, {} routes", | ||
| gtfs_id, | ||
| graph.nodes.len(), | ||
| graph.route_stop_sequences.len() | ||
| ); | ||
| } | ||
| info!("Loaded {} metro transit graphs", graphs.len()); | ||
| graphs | ||
| } | ||
| Err(e) => { | ||
| error!( | ||
| "Failed to deserialize metro_graph.json: {}. Metro routing will not be available.", | ||
| e | ||
| ); | ||
| HashMap::new() | ||
| } | ||
| }, | ||
| Err(e) => { | ||
| error!( | ||
| "Failed to read metro_graph.json: {}. Metro routing will not be available.", | ||
| e | ||
| ); | ||
| HashMap::new() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async fn load_depot_manager_details( | ||
| ) -> Result<HashMap<String, crate::models::DepotManagerDetails>> { | ||
| use crate::models::DepotManagerDetails; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove