mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
compare faster trips by baseline over time
This commit is contained in:
parent
3ba33e4bd0
commit
7c6f2c62b6
@ -167,10 +167,14 @@ pub struct PrebakedResults {
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct FasterTrips(pub BTreeMap<TripMode, DurationStats>);
|
||||
pub struct FasterTrips(pub Vec<(Duration, Option<TripMode>, Duration)>);
|
||||
|
||||
impl FasterTrips {
|
||||
pub fn from(sim: &Sim) -> FasterTrips {
|
||||
FasterTrips(sim.get_analytics().finished_trips.clone())
|
||||
}
|
||||
|
||||
pub fn to_stats(&self, now: Duration) -> BTreeMap<TripMode, DurationStats> {
|
||||
let mut distribs: BTreeMap<TripMode, DurationHistogram> = BTreeMap::new();
|
||||
for m in vec![
|
||||
TripMode::Walk,
|
||||
@ -180,14 +184,20 @@ impl FasterTrips {
|
||||
] {
|
||||
distribs.insert(m, Default::default());
|
||||
}
|
||||
for (_, m, dt) in sim.get_finished_trips().finished_trips {
|
||||
distribs.get_mut(&m).unwrap().add(dt);
|
||||
for (t, mode, dt) in &self.0 {
|
||||
if *t > now {
|
||||
break;
|
||||
}
|
||||
// Skip aborted trips
|
||||
if let Some(m) = mode {
|
||||
distribs.get_mut(&m).unwrap().add(*dt);
|
||||
}
|
||||
}
|
||||
let mut results = BTreeMap::new();
|
||||
for (m, distrib) in distribs {
|
||||
results.insert(m, distrib.to_stats());
|
||||
}
|
||||
FasterTrips(results)
|
||||
results
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -407,8 +407,15 @@ fn gridlock_panel(ui: &UI, prebaked: &PrebakedResults) -> Text {
|
||||
}
|
||||
|
||||
fn faster_trips_panel(mode: TripMode, ui: &UI, prebaked: &PrebakedResults) -> Text {
|
||||
let now = &FasterTrips::from(&ui.primary.sim).0[&mode];
|
||||
let baseline = &prebaked.faster_trips.0[&mode];
|
||||
let now = FasterTrips::from(&ui.primary.sim)
|
||||
.to_stats(ui.primary.sim.time())
|
||||
.remove(&mode)
|
||||
.unwrap();
|
||||
let baseline = prebaked
|
||||
.faster_trips
|
||||
.to_stats(ui.primary.sim.time())
|
||||
.remove(&mode)
|
||||
.unwrap();
|
||||
|
||||
let mut txt = Text::new();
|
||||
txt.add(Line(format!(
|
||||
@ -417,6 +424,10 @@ fn faster_trips_panel(mode: TripMode, ui: &UI, prebaked: &PrebakedResults) -> Te
|
||||
mode,
|
||||
prettyprint_usize(baseline.count),
|
||||
)));
|
||||
if now.count == 0 || baseline.count == 0 {
|
||||
return txt;
|
||||
}
|
||||
|
||||
// TODO Which one?
|
||||
if false {
|
||||
for (stat, dt) in &now.stats {
|
||||
|
@ -51,7 +51,7 @@ impl ShowTripStats {
|
||||
let mut counts = Counter::new();
|
||||
let mut pts_per_mode: BTreeMap<Option<TripMode>, Vec<(Duration, usize)>> =
|
||||
lines.iter().map(|(_, _, m)| (*m, Vec::new())).collect();
|
||||
for (t, m) in &ui.primary.sim.get_analytics().finished_trips {
|
||||
for (t, m, _) in &ui.primary.sim.get_analytics().finished_trips {
|
||||
counts.inc(*m);
|
||||
if *t > times[0] {
|
||||
times.remove(0);
|
||||
|
@ -12,7 +12,8 @@ pub struct Analytics {
|
||||
pub bus_arrivals: HashMap<(BusStopID, BusRouteID), Vec<Duration>>,
|
||||
pub total_bus_passengers: Counter<BusRouteID>,
|
||||
// TODO Hack: No TripMode means aborted
|
||||
pub finished_trips: Vec<(Duration, Option<TripMode>)>,
|
||||
// Finish time, mode (or None as aborted), trip duration
|
||||
pub finished_trips: Vec<(Duration, Option<TripMode>, Duration)>,
|
||||
}
|
||||
|
||||
pub struct ThruputStats {
|
||||
@ -65,10 +66,10 @@ impl Analytics {
|
||||
}
|
||||
|
||||
// Finished trips
|
||||
if let Event::TripFinished(_, mode) = ev {
|
||||
self.finished_trips.push((time, Some(mode)));
|
||||
if let Event::TripFinished(_, mode, dt) = ev {
|
||||
self.finished_trips.push((time, Some(mode), dt));
|
||||
} else if let Event::TripAborted(_) = ev {
|
||||
self.finished_trips.push((time, None));
|
||||
self.finished_trips.push((time, None, Duration::ZERO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use crate::{AgentID, CarID, ParkingSpot, PedestrianID, TripID, TripMode};
|
||||
use geom::Duration;
|
||||
use map_model::{BuildingID, BusRouteID, BusStopID, IntersectionID, LaneID, Traversable};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
@ -21,6 +22,6 @@ pub enum Event {
|
||||
|
||||
AgentEntersTraversable(AgentID, Traversable),
|
||||
|
||||
TripFinished(TripID, TripMode),
|
||||
TripFinished(TripID, TripMode, Duration),
|
||||
TripAborted(TripID),
|
||||
}
|
||||
|
@ -138,7 +138,11 @@ impl TripManager {
|
||||
assert!(!trip.finished_at.is_some());
|
||||
trip.finished_at = Some(now);
|
||||
self.unfinished_trips -= 1;
|
||||
self.events.push(Event::TripFinished(trip.id, trip.mode));
|
||||
self.events.push(Event::TripFinished(
|
||||
trip.id,
|
||||
trip.mode,
|
||||
now - trip.spawned_at,
|
||||
));
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
@ -309,7 +313,11 @@ impl TripManager {
|
||||
assert!(!trip.finished_at.is_some());
|
||||
trip.finished_at = Some(now);
|
||||
self.unfinished_trips -= 1;
|
||||
self.events.push(Event::TripFinished(trip.id, trip.mode));
|
||||
self.events.push(Event::TripFinished(
|
||||
trip.id,
|
||||
trip.mode,
|
||||
now - trip.spawned_at,
|
||||
));
|
||||
}
|
||||
|
||||
// If no route is returned, the pedestrian boarded a bus immediately.
|
||||
@ -389,7 +397,11 @@ impl TripManager {
|
||||
assert!(!trip.finished_at.is_some());
|
||||
trip.finished_at = Some(now);
|
||||
self.unfinished_trips -= 1;
|
||||
self.events.push(Event::TripFinished(trip.id, trip.mode));
|
||||
self.events.push(Event::TripFinished(
|
||||
trip.id,
|
||||
trip.mode,
|
||||
now - trip.spawned_at,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn car_or_bike_reached_border(&mut self, now: Duration, car: CarID, i: IntersectionID) {
|
||||
@ -403,7 +415,11 @@ impl TripManager {
|
||||
assert!(!trip.finished_at.is_some());
|
||||
trip.finished_at = Some(now);
|
||||
self.unfinished_trips -= 1;
|
||||
self.events.push(Event::TripFinished(trip.id, trip.mode));
|
||||
self.events.push(Event::TripFinished(
|
||||
trip.id,
|
||||
trip.mode,
|
||||
now - trip.spawned_at,
|
||||
));
|
||||
}
|
||||
|
||||
pub fn abort_trip_failed_start(&mut self, id: TripID) {
|
||||
|
Loading…
Reference in New Issue
Block a user