Fixed arrival time.
This commit is contained in:
parent
e758edd45a
commit
cef6faa05f
|
|
@ -14,7 +14,7 @@ zip = "8.3"
|
|||
csv = "1.4"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
opt-level = 0
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
|
|
|
|||
|
|
@ -74,12 +74,13 @@ impl Gtfs {
|
|||
stop: self.stops.get(&stop_time.stop_id)?,
|
||||
stop_time: stop_time,
|
||||
trip: &trip,
|
||||
departure_time: NaiveTime::from_num_seconds_from_midnight_opt(stop_timestamp, 0).unwrap()
|
||||
departure_time: stop_timestamp.into()
|
||||
};
|
||||
arrivals.push(arrival);
|
||||
}
|
||||
}
|
||||
}
|
||||
arrivals.sort();
|
||||
debug!("Found {} arrivals", arrivals.len());
|
||||
|
||||
return Some(arrivals);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub struct Gtfs {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Arrival<'a> {
|
||||
pub departure_time: NaiveTime,
|
||||
pub departure_time: i64,
|
||||
pub route: &'a Route,
|
||||
pub stop: &'a Stop,
|
||||
pub stop_time: &'a RawStopTime,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
mod gtfs;
|
||||
mod renderer;
|
||||
use std::{collections::HashSet, ops::Add, os::unix::process::ExitStatusExt, process, thread::Builder, time::SystemTime};
|
||||
use chrono::{DateTime, Duration, Local, NaiveTime};
|
||||
use chrono::{DateTime, Duration, Local, NaiveTime, Timelike};
|
||||
use log::{Metadata, Record, debug, error, info};
|
||||
use sdl3::event::Event;
|
||||
use crate::{gtfs::structs::{Arrival, Gtfs}, renderer::structs::{DisplayData, DisplayEntry, Screen}};
|
||||
|
|
@ -31,20 +31,22 @@ fn refresh_schedule<'a>(gtfs: &'a Gtfs, screen : &mut Screen<'a>) -> Option<Vec<
|
|||
next_arrivals.sort();
|
||||
|
||||
// Create the DisplayData structure to render the information to screen
|
||||
let current_time = Local::now().time();
|
||||
let now =Local::now();
|
||||
let current_time: i64 = (now.hour() * 3600 + now.minute() * 60 + now.second()).into();
|
||||
let mut display_data: DisplayData = DisplayData {
|
||||
lines: Vec::<DisplayEntry>::new(),
|
||||
status: None
|
||||
};
|
||||
|
||||
display_data.lines.extend(next_arrivals.iter().map(|arrival| -> DisplayEntry {
|
||||
|
||||
DisplayEntry {
|
||||
destination: arrival.stop_time.stop_headsign.clone()
|
||||
.or(arrival.trip.trip_headsign.clone()
|
||||
.or(Option::Some(String::from("Unknown")
|
||||
))).unwrap(),
|
||||
route: arrival.route.short_name.clone().or(arrival.route.long_name.clone()).unwrap(),
|
||||
due_in: (arrival.departure_time - current_time).num_minutes().try_into().unwrap()
|
||||
due_in: (arrival.departure_time - current_time) / 60,
|
||||
}
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -38,12 +38,15 @@ impl Screen<'_> {
|
|||
|
||||
pub fn update_information(&mut self, display_data: &DisplayData) {
|
||||
self.do_clear();
|
||||
|
||||
// TODO: Add header
|
||||
|
||||
let num_arrivals: i32 = min(if display_data.status.is_some() {LINE_COUNT - 1} else {LINE_COUNT}, display_data.lines.len().try_into().unwrap());
|
||||
for line in 0..num_arrivals {
|
||||
// Compose a line of text with all the information
|
||||
let entry = display_data.lines.get(line as usize).unwrap();
|
||||
let line: u32 = line.try_into().unwrap();
|
||||
let due_in_mins = (entry.due_in / 60) as i32;
|
||||
let line: u32 = (line + 1).try_into().unwrap();
|
||||
let due_in_mins = entry.due_in as i32;
|
||||
let arrival_color: Color = self.color_for(due_in_mins);
|
||||
|
||||
self.color = COLOR_LCD_AMBER;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub struct Prefs {
|
|||
pub struct DisplayEntry {
|
||||
pub route: String,
|
||||
pub destination: String,
|
||||
pub due_in: i32,
|
||||
pub due_in: i64,
|
||||
}
|
||||
|
||||
pub struct DisplayData {
|
||||
|
|
|
|||
Loading…
Reference in New Issue