spat: Use likely time, if available
This commit is contained in:
parent
712550160f
commit
c771afe744
4 changed files with 33 additions and 18 deletions
|
|
@ -66,7 +66,7 @@ pub struct State {
|
||||||
pub struct SignalGroupData {
|
pub struct SignalGroupData {
|
||||||
pub phase: SignalPhase,
|
pub phase: SignalPhase,
|
||||||
pub maneuver: map::Maneuvers,
|
pub maneuver: map::Maneuvers,
|
||||||
pub min_end_sec: Option<i16>,
|
pub end_sec: Option<i16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "spat")]
|
#[cfg(feature = "spat")]
|
||||||
|
|
@ -290,19 +290,23 @@ impl State {
|
||||||
.map(core::convert::Into::into)
|
.map(core::convert::Into::into)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let min_end_sec = sig.min_end_time().map(|time| {
|
let end_sec =
|
||||||
let dur = time.sub(self.time.and_utc()).as_seconds_f32();
|
sig.likely_time()
|
||||||
|
.or_else(|| sig.min_end_time())
|
||||||
|
.map(|time| {
|
||||||
|
let dur =
|
||||||
|
time.sub(self.time.and_utc()).as_seconds_f32();
|
||||||
|
|
||||||
#[allow(clippy::cast_possible_truncation)]
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
let min_end_sec = dur.round() as i16;
|
let end_sec = dur.round() as i16;
|
||||||
|
|
||||||
min_end_sec
|
end_sec
|
||||||
});
|
});
|
||||||
|
|
||||||
Some(SignalGroupData {
|
Some(SignalGroupData {
|
||||||
phase,
|
phase,
|
||||||
maneuver: manv,
|
maneuver: manv,
|
||||||
min_end_sec,
|
end_sec,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
||||||
|
|
@ -160,12 +160,19 @@ impl Intersection {
|
||||||
&& let Some(sig_grp) = self.signal_groups.get_mut(idx)
|
&& let Some(sig_grp) = self.signal_groups.get_mut(idx)
|
||||||
{
|
{
|
||||||
sig_grp.phase = Some(event.event_state);
|
sig_grp.phase = Some(event.event_state);
|
||||||
if let Some(timing) = &event.timing
|
if let Some(timing) = &event.timing {
|
||||||
&& !timing.min_end_time.is_out_of_range()
|
if !timing.min_end_time.is_out_of_range()
|
||||||
&& !timing.min_end_time.is_unknown()
|
&& !timing.min_end_time.is_unknown()
|
||||||
{
|
{
|
||||||
sig_grp.min_end_time =
|
sig_grp.min_end_time =
|
||||||
Some(timing.min_end_time.to_datetime_from_moy(moy, year));
|
Some(timing.min_end_time.to_datetime_from_moy(moy, year));
|
||||||
|
}
|
||||||
|
if let Some(likely) = &timing.likely_time
|
||||||
|
&& !likely.is_out_of_range()
|
||||||
|
&& !likely.is_unknown()
|
||||||
|
{
|
||||||
|
sig_grp.likely_time = Some(likely.to_datetime_from_moy(moy, year));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -216,6 +223,7 @@ impl Intersection {
|
||||||
target_lanes,
|
target_lanes,
|
||||||
phase: None,
|
phase: None,
|
||||||
min_end_time: None,
|
min_end_time: None,
|
||||||
|
likely_time: None,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
@ -403,7 +411,7 @@ pub struct SignalGroup {
|
||||||
phase: Option<etsi_its_dsrc::MovementPhaseState>,
|
phase: Option<etsi_its_dsrc::MovementPhaseState>,
|
||||||
min_end_time: Option<chrono::DateTime<chrono::Utc>>,
|
min_end_time: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
// max_end_time: Option<chrono::DateTime<chrono::Utc>>,
|
// max_end_time: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
// likely_time: Option<chrono::DateTime<chrono::Utc>>,
|
likely_time: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Display for SignalGroup {
|
impl core::fmt::Display for SignalGroup {
|
||||||
|
|
@ -432,6 +440,9 @@ impl SignalGroup {
|
||||||
pub fn min_end_time(&self) -> Option<chrono::prelude::DateTime<chrono::prelude::Utc>> {
|
pub fn min_end_time(&self) -> Option<chrono::prelude::DateTime<chrono::prelude::Utc>> {
|
||||||
self.min_end_time
|
self.min_end_time
|
||||||
}
|
}
|
||||||
|
pub fn likely_time(&self) -> Option<chrono::prelude::DateTime<chrono::prelude::Utc>> {
|
||||||
|
self.likely_time
|
||||||
|
}
|
||||||
|
|
||||||
pub fn phase_to_str(&self) -> Option<String> {
|
pub fn phase_to_str(&self) -> Option<String> {
|
||||||
self.phase.map(|v| {
|
self.phase.map(|v| {
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||||
|
|
||||||
for sig in &signal_groups {
|
for sig in &signal_groups {
|
||||||
let duration_str = sig
|
let duration_str = sig
|
||||||
.min_end_sec
|
.end_sec
|
||||||
.map(|v| alloc::format!("for {v} s"))
|
.map(|v| alloc::format!("for {v} s"))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
println!("GLOSA: {} {} {duration_str}", sig.maneuver, sig.phase);
|
println!("GLOSA: {} {} {duration_str}", sig.maneuver, sig.phase);
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,9 @@ where
|
||||||
.draw(target)?;
|
.draw(target)?;
|
||||||
|
|
||||||
// draw timing indicator
|
// draw timing indicator
|
||||||
if let Some(min_end_sec) = sig.min_end_sec {
|
if let Some(end_sec) = sig.end_sec {
|
||||||
text::Text::with_alignment(
|
text::Text::with_alignment(
|
||||||
&alloc::format!("{min_end_sec}s"),
|
&alloc::format!("{end_sec}s"),
|
||||||
geometry::Point::new(centerline, 160),
|
geometry::Point::new(centerline, 160),
|
||||||
text_style,
|
text_style,
|
||||||
text::Alignment::Center,
|
text::Alignment::Center,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue