Fixed calculation of arrival time.
This commit is contained in:
parent
e185b38222
commit
391380040e
|
|
@ -76,7 +76,10 @@ impl Gtfs {
|
||||||
trip: &trip,
|
trip: &trip,
|
||||||
departure_time: stop_timestamp.into()
|
departure_time: stop_timestamp.into()
|
||||||
};
|
};
|
||||||
debug!("Arrival to {:#?} for trip ID {:#?}.", arrival.trip.trip_headsign.as_ref().unwrap(), arrival.trip.id);
|
debug!("{:#?}: Arrival to {:#?} for trip ID {:#?}.",
|
||||||
|
format!("{:02}:{:02}", (arrival.departure_time/3600) as u32, ((arrival.departure_time / 60) % 60) as u32),
|
||||||
|
arrival.trip.trip_headsign.as_ref().unwrap(),
|
||||||
|
arrival.trip.id);
|
||||||
arrivals.push(arrival);
|
arrivals.push(arrival);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
use std::{cmp::min};
|
use std::{cmp::min};
|
||||||
use log::{error, warn};
|
use chrono::{Local, NaiveTime, Timelike};
|
||||||
|
use log::{debug, error, warn};
|
||||||
use sdl3::{Sdl, pixels::Color, rect::Rect};
|
use sdl3::{Sdl, pixels::Color, rect::Rect};
|
||||||
use structs::{Prefs, DisplayData};
|
use structs::{Prefs, DisplayData};
|
||||||
|
|
||||||
|
|
@ -32,18 +33,21 @@ impl Screen<'_> {
|
||||||
return COLOR_LCD_RED;
|
return COLOR_LCD_RED;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_due_for(&self, due_in: i32, departure_time: u32) -> String {
|
fn format_due_for(&self, due_in_mins: i32, departure_time: u32) -> String {
|
||||||
if due_in < 60 {
|
debug!("Due in mins: {:02}", due_in_mins);
|
||||||
|
if due_in_mins <= 1 {
|
||||||
return String::from("due");
|
return String::from("due");
|
||||||
}
|
}
|
||||||
if due_in < 3600 {
|
if due_in_mins < 60 {
|
||||||
return ((due_in / 60) as i32).to_string() + "min";
|
return due_in_mins.to_string() + "min";
|
||||||
}
|
}
|
||||||
return format!("{:02}:{:02}", (departure_time / 3600) as i32, ((departure_time % 3600) / 60) as i32);
|
return format!("{:02}:{:02}", (departure_time / 3600) as i32, ((departure_time / 60) % 60) as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn update_information(&mut self, display_data: &DisplayData) {
|
pub fn update_information(&mut self, display_data: &DisplayData) {
|
||||||
|
let seconds_since_midnight = Local::now().num_seconds_from_midnight();
|
||||||
|
|
||||||
self.do_clear();
|
self.do_clear();
|
||||||
|
|
||||||
// Print status first
|
// Print status first
|
||||||
|
|
@ -55,13 +59,13 @@ impl Screen<'_> {
|
||||||
self.do_print_at(5, &format!("TODO: DATE/TIME GOES HERE").to_string(), 0);
|
self.do_print_at(5, &format!("TODO: DATE/TIME GOES HERE").to_string(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then data lines from the bottom up
|
// Then data lines from the bottom
|
||||||
let num_arrivals: i32 = min(LINE_COUNT, display_data.lines.len() as i32);
|
let num_arrivals: i32 = min(LINE_COUNT, display_data.lines.len() as i32);
|
||||||
for index in 0..num_arrivals {
|
for index in 0..num_arrivals {
|
||||||
let line: u32 = ((num_arrivals - 1) - index) as u32;
|
let line: u32 = ((num_arrivals - 1) - index) as u32;
|
||||||
// Compose a line of text with all the information
|
// Compose a line of text with all the information
|
||||||
let entry = display_data.lines.get(line as usize).unwrap();
|
let entry = display_data.lines.get(line as usize).unwrap();
|
||||||
let due_in_mins = (entry.departure_time / 60) as i32;
|
let due_in_mins = ((entry.departure_time - seconds_since_midnight) / 60) as i32;
|
||||||
let due_color: Color = self.color_for(due_in_mins);
|
let due_color: Color = self.color_for(due_in_mins);
|
||||||
let due_text = self.format_due_for(due_in_mins, entry.departure_time);
|
let due_text = self.format_due_for(due_in_mins, entry.departure_time);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue