Compare commits
3 Commits
a2ccb9b761
...
realtime
| Author | SHA1 | Date | |
|---|---|---|---|
| 559a314dbe | |||
| b60520009f | |||
| 618c4ff2fe |
@@ -10,6 +10,8 @@ csv = "1.4"
|
|||||||
gtfs-structures = "0.47"
|
gtfs-structures = "0.47"
|
||||||
gtfs-realtime = "0.2"
|
gtfs-realtime = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
prost = "0.14"
|
||||||
|
prost-types = "0.14"
|
||||||
reqwest = { version = "0.11", features = ["blocking"] }
|
reqwest = { version = "0.11", features = ["blocking"] }
|
||||||
sdl3 = {version = "0.17", features = ["ttf"]}
|
sdl3 = {version = "0.17", features = ["ttf"]}
|
||||||
serde = { version = "1.0", features = ["derive"]}
|
serde = { version = "1.0", features = ["derive"]}
|
||||||
|
|||||||
+4
-2
@@ -7,7 +7,7 @@ pub mod structs;
|
|||||||
use chrono::{DateTime, Local, Timelike};
|
use chrono::{DateTime, Local, Timelike};
|
||||||
use log::{debug, trace, warn};
|
use log::{debug, trace, warn};
|
||||||
use std::{collections::{HashMap, HashSet}, fs::File };
|
use std::{collections::{HashMap, HashSet}, fs::File };
|
||||||
use gtfs_structures::{ContinuousPickupDropOff::ArrangeByPhone, Exception, RawTrip};
|
use gtfs_structures::{Exception, RawTrip};
|
||||||
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences, Error}};
|
use crate::gtfs::{loader::load_gtfs, structs::{Arrival, Gtfs, Preferences, Error}};
|
||||||
|
|
||||||
|
|
||||||
@@ -18,12 +18,14 @@ impl Gtfs<'_> {
|
|||||||
let target_date = naive_target.date();
|
let target_date = naive_target.date();
|
||||||
|
|
||||||
// Find which calendars apply
|
// Find which calendars apply
|
||||||
|
debug!("Looking for calendars that apply to date {:#?}", target_date);
|
||||||
let mut active_service_ids: HashSet<String> = HashSet::new();
|
let mut active_service_ids: HashSet<String> = HashSet::new();
|
||||||
for (id, calendar) in self.calendar.iter() {
|
for (id, calendar) in self.calendar.iter() {
|
||||||
if calendar.valid_weekday(target_date)
|
if calendar.valid_weekday(target_date)
|
||||||
&& calendar.start_date <= target_date
|
&& calendar.start_date <= target_date
|
||||||
&& calendar.end_date > target_date {
|
&& calendar.end_date > target_date {
|
||||||
active_service_ids.insert(id.to_string());
|
active_service_ids.insert(id.to_string());
|
||||||
|
debug!("Matched calendar: {:#?}", calendar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug!("Found {} services active today", active_service_ids.len());
|
debug!("Found {} services active today", active_service_ids.len());
|
||||||
@@ -43,7 +45,7 @@ impl Gtfs<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug!("After exceptions, there are now {} services active", active_service_ids.len());
|
debug!("After exceptions, there are now {} services active: {:#?}", active_service_ids.len(), active_service_ids);
|
||||||
|
|
||||||
// Find the trips happening on these calendars
|
// Find the trips happening on these calendars
|
||||||
let mut trips: HashMap<&String, &RawTrip> = HashMap::new();
|
let mut trips: HashMap<&String, &RawTrip> = HashMap::new();
|
||||||
|
|||||||
+10
-3
@@ -28,8 +28,13 @@ impl Gtfs<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse response
|
// Parse response
|
||||||
let realtime_info: gtfs_realtime::FeedMessage
|
let response_bytes= response.bytes()?;
|
||||||
= serde_json::from_reader(response)?;
|
let data: Result<gtfs_realtime::FeedMessage, prost::DecodeError> = prost::Message::decode(response_bytes.as_ref());
|
||||||
|
if data.is_err() {
|
||||||
|
return Err(Error {
|
||||||
|
_message : format! ("Error loading realtime prtobuf: {:#?}", data.err().unwrap())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Build a map of (trip, stop) -> Arrival for faster lookup
|
// Build a map of (trip, stop) -> Arrival for faster lookup
|
||||||
@@ -41,7 +46,9 @@ impl Gtfs<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match deltas to existing arrivals
|
// Match deltas to existing arrivals
|
||||||
for entity in realtime_info.entity {
|
let entities = data.unwrap().entity;
|
||||||
|
debug!("Loaded {} entities from realtime update.", entities.len());
|
||||||
|
for entity in entities {
|
||||||
if entity.trip_update.is_some() && entity.stop.is_some() {
|
if entity.trip_update.is_some() && entity.stop.is_some() {
|
||||||
let trip_update = entity.trip_update.unwrap();
|
let trip_update = entity.trip_update.unwrap();
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ impl Screen<'_> {
|
|||||||
fn format_due_for(&self, due_in_mins: i32, departure_time: u32) -> String {
|
fn format_due_for(&self, due_in_mins: i32, departure_time: u32) -> String {
|
||||||
trace!("Due in mins: {:02}", due_in_mins);
|
trace!("Due in mins: {:02}", due_in_mins);
|
||||||
if due_in_mins <= 1 {
|
if due_in_mins <= 1 {
|
||||||
return String::from("due");
|
return String::from("Due");
|
||||||
}
|
}
|
||||||
if due_in_mins < 60 {
|
if due_in_mins < 60 {
|
||||||
return due_in_mins.to_string() + "min";
|
return due_in_mins.to_string() + "min";
|
||||||
|
|||||||
Reference in New Issue
Block a user