use serde::{Deserialize, Serialize};
use geom::Duration;
use map_model::{
BuildingID, IntersectionID, LaneID, Map, Path, PathRequest, TransitRouteID, TransitStopID,
Traversable, TurnID,
};
use synthpop::TripMode;
use crate::{AgentID, CarID, ParkingSpot, PedestrianID, PersonID, Problem, TripID};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum Event {
CarReachedParkingSpot(CarID, ParkingSpot),
CarLeftParkingSpot(CarID, ParkingSpot),
BusArrivedAtStop(CarID, TransitRouteID, TransitStopID),
BusDepartedFromStop(CarID, TransitRouteID, TransitStopID),
PassengerBoardsTransit(PersonID, CarID, TransitRouteID, TransitStopID, Duration),
PassengerAlightsTransit(PersonID, CarID, TransitRouteID, TransitStopID),
PersonEntersBuilding(PersonID, BuildingID),
PersonLeavesBuilding(PersonID, BuildingID),
PersonLeavesMap(PersonID, Option<AgentID>, IntersectionID),
PersonEntersMap(PersonID, AgentID, IntersectionID),
PedReachedParkingSpot(PedestrianID, ParkingSpot),
BikeStoppedAtSidewalk(CarID, LaneID),
ProblemEncountered(TripID, Problem),
AgentEntersTraversable(AgentID, Option<TripID>, Traversable, Option<usize>),
IntersectionDelayMeasured(TripID, TurnID, AgentID, Duration),
TripFinished {
trip: TripID,
mode: TripMode,
total_time: Duration,
blocked_time: Duration,
},
TripCancelled(TripID, TripMode),
TripPhaseStarting(TripID, PersonID, Option<PathRequest>, TripPhaseType),
PathAmended(Path),
Alert(AlertLocation, String),
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum AlertLocation {
Nil,
Intersection(IntersectionID),
Person(PersonID),
Building(BuildingID),
}
#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)]
pub enum TripPhaseType {
Driving,
Walking,
Biking,
Parking,
WaitingForBus(TransitRouteID, TransitStopID),
RidingBus(TransitRouteID, TransitStopID, CarID),
Cancelled,
Finished,
DelayedStart,
}
impl TripPhaseType {
pub fn describe(self, map: &Map) -> String {
match self {
TripPhaseType::Driving => "Driving".to_string(),
TripPhaseType::Walking => "Walking".to_string(),
TripPhaseType::Biking => "Biking".to_string(),
TripPhaseType::Parking => "Parking".to_string(),
TripPhaseType::WaitingForBus(r, _) => {
format!("Waiting for transit route {}", map.get_tr(r).long_name)
}
TripPhaseType::RidingBus(r, _, _) => {
format!("Riding route {}", map.get_tr(r).long_name)
}
TripPhaseType::Cancelled => "Trip was cancelled due to some bug".to_string(),
TripPhaseType::Finished => "Trip finished".to_string(),
TripPhaseType::DelayedStart => "Delayed by a previous trip taking too long".to_string(),
}
}
}