refactoring some TripMode enum stuff

This commit is contained in:
Dustin Carlino 2019-11-04 13:51:25 -08:00
parent ada5484501
commit 974ad24ec3
4 changed files with 33 additions and 23 deletions

View File

@ -79,7 +79,7 @@ impl Scoreboard {
let len = deltas.len() as f64;
summary.add_appended(vec![
Line(format!("{:?}", mode)).fg(Color::PURPLE),
Line(format!("{}", mode)).fg(Color::PURPLE),
Line(format!(
" trips: {} same, {} different",
abstutil::prettyprint_usize(num_same),
@ -136,14 +136,10 @@ fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Tra
.iter()
.map(|(_, m, _, _)| *m)
.collect::<BTreeSet<TripMode>>();
vec![
Choice::new("walk", TripMode::Walk).active(modes.contains(&TripMode::Walk)),
Choice::new("bike", TripMode::Bike).active(modes.contains(&TripMode::Bike)),
Choice::new("transit", TripMode::Transit)
.active(modes.contains(&TripMode::Transit)),
Choice::new("drive", TripMode::Drive).active(modes.contains(&TripMode::Drive)),
]
TripMode::all()
.into_iter()
.map(|m| Choice::new(m.to_string(), m).active(modes.contains(&m)))
.collect()
})?
.1;
wizard.choose("Examine which trip?", || {

View File

@ -179,12 +179,7 @@ impl FasterTrips {
pub fn to_stats(&self, now: Duration) -> BTreeMap<TripMode, DurationStats> {
let mut distribs: BTreeMap<TripMode, DurationHistogram> = BTreeMap::new();
for m in vec![
TripMode::Walk,
TripMode::Bike,
TripMode::Transit,
TripMode::Drive,
] {
for m in TripMode::all() {
distribs.insert(m, DurationHistogram::new());
}
for (t, mode, dt) in &self.0 {

View File

@ -52,7 +52,7 @@ impl Scoreboard {
distrib.add(dt);
}
summary.add_appended(vec![
Line(format!("{:?}", mode)).fg(Color::CYAN),
Line(format!("{}", mode)).fg(Color::CYAN),
Line(format!(" trips: {}", distrib.describe())),
]);
}
@ -91,13 +91,10 @@ fn browse_trips(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Tra
.iter()
.map(|(_, m, _)| *m)
.collect::<BTreeSet<TripMode>>();
vec![
Choice::new("walk", TripMode::Walk).active(modes.contains(&TripMode::Walk)),
Choice::new("bike", TripMode::Bike).active(modes.contains(&TripMode::Bike)),
Choice::new("transit", TripMode::Transit).active(modes.contains(&TripMode::Transit)),
Choice::new("drive", TripMode::Drive).active(modes.contains(&TripMode::Drive)),
]
TripMode::all()
.into_iter()
.map(|m| Choice::new(m.to_string(), m).active(modes.contains(&m)))
.collect()
})?;
wizard.choose("Examine which trip?", || {
let trips = ui.primary.sim.get_finished_trips();

View File

@ -714,6 +714,28 @@ pub enum TripMode {
Drive,
}
impl TripMode {
pub fn all() -> Vec<TripMode> {
vec![
TripMode::Walk,
TripMode::Bike,
TripMode::Transit,
TripMode::Drive,
]
}
}
impl std::fmt::Display for TripMode {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
TripMode::Walk => write!(f, "walk"),
TripMode::Bike => write!(f, "bike"),
TripMode::Transit => write!(f, "transit"),
TripMode::Drive => write!(f, "drive"),
}
}
}
// TODO Argh no, not more of these variants!
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]