mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 00:12:55 +03:00
squish down the popdat output by using enums for purpose
This commit is contained in:
parent
42c021c8df
commit
dad1c170ed
@ -47,8 +47,11 @@ impl TripsVisualizer {
|
||||
));
|
||||
let trip = &self.trips[self.current];
|
||||
txt.add_line(format!("Leave at {}", trip.depart_at));
|
||||
txt.add_line(format!("Purpose: {}", trip.purpose));
|
||||
txt.add_line(format!("{:?}", trip.mode));
|
||||
txt.add_line(format!(
|
||||
"Purpose: {:?} -> {:?}",
|
||||
trip.purpose.0, trip.purpose.1
|
||||
));
|
||||
txt.add_line(format!("Mode: {:?}", trip.mode));
|
||||
txt.add_line(format!("Trip time: {}", trip.trip_time));
|
||||
txt.add_line(format!("Trip distance: {}", trip.trip_dist));
|
||||
txt.add_line(format!(
|
||||
@ -103,16 +106,18 @@ struct Trip {
|
||||
from: BuildingID,
|
||||
to: BuildingID,
|
||||
depart_at: Duration,
|
||||
purpose: String,
|
||||
mode: popdat::psrc::TripMode,
|
||||
purpose: (popdat::psrc::Purpose, popdat::psrc::Purpose),
|
||||
mode: popdat::psrc::Mode,
|
||||
trip_time: Duration,
|
||||
trip_dist: Distance,
|
||||
}
|
||||
|
||||
fn clip_trips(popdat: &PopDat, ui: &UI, _timer: &mut Timer) -> Vec<Trip> {
|
||||
fn clip_trips(popdat: &PopDat, ui: &UI, timer: &mut Timer) -> Vec<Trip> {
|
||||
let mut results = Vec::new();
|
||||
let bounds = ui.primary.map.get_gps_bounds();
|
||||
timer.start_iter("clip trips", popdat.trips.len());
|
||||
for trip in &popdat.trips {
|
||||
timer.next();
|
||||
if !bounds.contains(trip.from) || !bounds.contains(trip.to) {
|
||||
continue;
|
||||
}
|
||||
@ -123,18 +128,13 @@ fn clip_trips(popdat: &PopDat, ui: &UI, _timer: &mut Timer) -> Vec<Trip> {
|
||||
from: from.unwrap(),
|
||||
to: to.unwrap(),
|
||||
depart_at: trip.depart_at,
|
||||
purpose: trip.purpose.clone(),
|
||||
purpose: trip.purpose,
|
||||
mode: trip.mode,
|
||||
trip_time: trip.trip_time,
|
||||
trip_dist: trip.trip_dist,
|
||||
});
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"Clipped {} trips from {}",
|
||||
results.len(),
|
||||
popdat.trips.len()
|
||||
);
|
||||
results
|
||||
}
|
||||
|
||||
|
@ -11,21 +11,35 @@ pub struct Trip {
|
||||
pub to: LonLat,
|
||||
// Relative to midnight
|
||||
pub depart_at: Duration,
|
||||
pub mode: TripMode,
|
||||
pub mode: Mode,
|
||||
|
||||
// TODO Encode way more compactly as (enum, enum)
|
||||
pub purpose: String,
|
||||
pub purpose: (Purpose, Purpose),
|
||||
pub trip_time: Duration,
|
||||
pub trip_dist: Distance,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||
pub enum TripMode {
|
||||
pub enum Mode {
|
||||
Walk,
|
||||
Bike,
|
||||
Drive,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||
pub enum Purpose {
|
||||
Home,
|
||||
Work,
|
||||
School,
|
||||
Escort,
|
||||
PersonalBusiness,
|
||||
Shopping,
|
||||
Meal,
|
||||
Social,
|
||||
Recreation,
|
||||
Medical,
|
||||
ParkAndRideTransfer,
|
||||
}
|
||||
|
||||
pub fn import_trips(
|
||||
path: &str,
|
||||
parcels: HashMap<String, LonLat>,
|
||||
@ -60,7 +74,7 @@ pub fn import_trips(
|
||||
};
|
||||
|
||||
// opurp and dpurp
|
||||
let purpose = format!("{} -> {}", get_purpose(&rec[16]), get_purpose(&rec[7]));
|
||||
let purpose = (get_purpose(&rec[16]), get_purpose(&rec[7]));
|
||||
|
||||
// travtime
|
||||
let trip_time = Duration::f64_minutes(rec[25].parse::<f64>()?);
|
||||
@ -145,30 +159,30 @@ pub fn import_parcels(
|
||||
}
|
||||
|
||||
// From https://github.com/psrc/soundcast/wiki/Outputs#trip-file-_triptsv, opurp and dpurp
|
||||
fn get_purpose(code: &str) -> &str {
|
||||
fn get_purpose(code: &str) -> Purpose {
|
||||
match code {
|
||||
"0.0" => "home",
|
||||
"1.0" => "work",
|
||||
"2.0" => "school",
|
||||
"3.0" => "escort",
|
||||
"4.0" => "personal business",
|
||||
"5.0" => "shopping",
|
||||
"6.0" => "meal",
|
||||
"7.0" => "social",
|
||||
"8.0" => "recreation",
|
||||
"9.0" => "medical",
|
||||
"10.0" => "park-and-ride transfer",
|
||||
"0.0" => Purpose::Home,
|
||||
"1.0" => Purpose::Work,
|
||||
"2.0" => Purpose::School,
|
||||
"3.0" => Purpose::Escort,
|
||||
"4.0" => Purpose::PersonalBusiness,
|
||||
"5.0" => Purpose::Shopping,
|
||||
"6.0" => Purpose::Meal,
|
||||
"7.0" => Purpose::Social,
|
||||
"8.0" => Purpose::Recreation,
|
||||
"9.0" => Purpose::Medical,
|
||||
"10.0" => Purpose::ParkAndRideTransfer,
|
||||
_ => panic!("Unknown opurp/dpurp {}", code),
|
||||
}
|
||||
}
|
||||
|
||||
// From https://github.com/psrc/soundcast/wiki/Outputs#trip-file-_triptsv, mode
|
||||
fn get_mode(code: &str) -> Option<TripMode> {
|
||||
fn get_mode(code: &str) -> Option<Mode> {
|
||||
// TODO I'm not sure how to interpret some of these.
|
||||
match code {
|
||||
"1.0" | "6.0" => Some(TripMode::Walk),
|
||||
"2.0" => Some(TripMode::Bike),
|
||||
"3.0" | "4.0" | "5.0" => Some(TripMode::Drive),
|
||||
"1.0" | "6.0" => Some(Mode::Walk),
|
||||
"2.0" => Some(Mode::Bike),
|
||||
"3.0" | "4.0" | "5.0" => Some(Mode::Drive),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user