make sim analytics invariant of the step() sizes called. prebaked vs

live sims were artifically different.
This commit is contained in:
Dustin Carlino 2019-11-06 12:31:13 -08:00
parent 7400659820
commit c326017883
2 changed files with 18 additions and 13 deletions

View File

@ -404,14 +404,16 @@ fn bus_route_panel(id: BusRouteID, ui: &UI, stat: Statistic, prebaked: &Analytic
if let Some(ref stats2) = baseline.get(&route.stops[idx2]) {
let vs = stats2.select(stat);
if us <= vs {
if us < vs {
txt.append(Line(" ("));
txt.append(Line((vs - us).minimal_tostring()).fg(Color::GREEN));
txt.append(Line(" faster)"));
} else {
} else if us > vs {
txt.append(Line(" ("));
txt.append(Line((us - vs).minimal_tostring()).fg(Color::RED));
txt.append(Line(" slower)"));
} else {
txt.append(Line(" (same as baseline)"));
}
}
} else {
@ -513,12 +515,14 @@ fn faster_trips_panel(mode: TripMode, ui: &UI, prebaked: &Analytics) -> Text {
let dt = now.select(stat);
let vs = baseline.select(stat);
txt.add(Line(format!("{}: ", stat)));
if dt <= vs {
if dt < vs {
txt.append(Line((vs - dt).minimal_tostring()).fg(Color::GREEN));
txt.append(Line(" faster"));
} else {
} else if dt > vs {
txt.append(Line((dt - vs).minimal_tostring()).fg(Color::RED));
txt.append(Line(" slower"));
} else {
txt.append(Line(" same as baseline"));
}
}
}

View File

@ -537,6 +537,16 @@ impl Sim {
savestate_at = Some(self.time);
}
}
// Record events at precisely the time they occur.
let mut events = Vec::new();
events.extend(self.trips.collect_events());
events.extend(self.transit.collect_events());
events.extend(self.driving.collect_events());
events.extend(self.walking.collect_events());
for ev in events {
self.analytics.event(ev, self.time, map);
}
}
if let Some(t) = savestate_at {
self.time = t;
@ -545,15 +555,6 @@ impl Sim {
self.time = target_time;
self.trip_positions = None;
let mut events = Vec::new();
events.extend(self.trips.collect_events());
events.extend(self.transit.collect_events());
events.extend(self.driving.collect_events());
events.extend(self.walking.collect_events());
for ev in events {
self.analytics.event(ev, self.time, map);
}
}
pub fn timed_step(&mut self, map: &Map, dt: Duration, timer: &mut Timer) {