mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
refactoring some TripMode enum stuff
This commit is contained in:
parent
ada5484501
commit
974ad24ec3
@ -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?", || {
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
|
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user