mbta_rs/models/
alert.rs

1//! Data models for MBTA alerts.
2
3use chrono::{offset::FixedOffset, DateTime};
4use serde::{Deserialize, Serialize};
5
6use super::*;
7
8/// Multiple alerts.
9pub type Alerts = Vec<Alert>;
10
11/// An active or upcoming system alert.
12pub type Alert = Resource<AlertAttributes>;
13
14/// Attributes for an alert.
15#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
16pub struct AlertAttributes {
17    /// A URL for extra details, such as outline construction or maintenance plans.
18    pub url: Option<String>,
19    /// Date/Time alert created.
20    #[serde(with = "mbta_datetime_format")]
21    pub created_at: DateTime<FixedOffset>,
22    /// Date/Time alert last updated.
23    #[serde(with = "mbta_datetime_format")]
24    pub updated_at: DateTime<FixedOffset>,
25    /// Summarizes when an alert is in effect.
26    pub timeframe: Option<String>,
27    /// Header description for an alert.
28    pub header: String,
29    /// A shortened version of `header`.
30    pub short_header: String,
31    /// How severe the alert is, from 0 (least severe) to 10 (most severe).
32    pub severity: u8,
33    /// Summarizes the service and the impact to that service.
34    pub service_effect: String,
35    /// Identifies whether an alert is a new or old, in effect or upcoming.
36    pub lifecycle: Lifecycle,
37    /// The effect of this problem on the affected entity.
38    pub effect: Effect,
39    /// This plain-text string will be formatted as the body of the alert (or shown on an explicit “expand” request by the user).
40    /// The information in the description should add to the information of the header.
41    pub description: Option<String>,
42    /// What is causing the alert.
43    pub cause: Cause,
44    /// Set if alert is meant to be displayed prominently, such as the top of every page.
45    pub banner: Option<String>,
46    /// Active periods for an alert.
47    pub active_period: Vec<ActivePeriod>,
48    /// Entities affected by an alert.
49    pub informed_entity: Vec<InformedEntity>,
50}
51
52/// Start and end dates for an active alert.
53#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Copy)]
54pub struct ActivePeriod {
55    /// Start date for an active alert.
56    #[serde(with = "mbta_datetime_format")]
57    pub start: DateTime<FixedOffset>,
58    /// End date for an active alert.
59    #[serde(with = "optional_mbta_datetime_format")]
60    pub end: Option<DateTime<FixedOffset>>,
61}
62
63/// An entity affected by an alert. At least one of the fields other than activities will be non-null.
64/// The affected entity is the intersection of these fields, not the union: if stop and route both have values, the alert does not affect the entire route.
65#[derive(Deserialize, Serialize, Debug, PartialEq, Clone)]
66pub struct InformedEntity {
67    /// ID of the affected trip.
68    pub trip: Option<String>,
69    /// ID of the affected stop.
70    pub stop: Option<String>,
71    /// Type of the affected route.
72    pub route_type: Option<RouteType>,
73    /// ID of the affected route.
74    pub route: Option<String>,
75    /// ID of the affected facility.
76    pub facility: Option<String>,
77    /// Direction ID of the affected trip.
78    pub direction_id: Option<u8>,
79    /// Activities affected by the alert.
80    pub activities: Vec<Activity>,
81}
82
83/// Whether an alert is a new or old, in effect or upcoming.
84#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Copy)]
85#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
86pub enum Lifecycle {
87    /// A new alert.
88    New,
89    /// An ongoing alert.
90    Ongoing,
91    /// An ongoing and upcoming alert.
92    OngoingUpcoming,
93    /// An upcoming alert.
94    Upcoming,
95}
96
97/// The effect of a problem on an affected entity.
98#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Copy)]
99#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
100pub enum Effect {
101    /// Access issue.
102    AccessIssue,
103    /// Additional service.
104    AdditionalService,
105    /// Amber alert.
106    AmberAlert,
107    /// Bike issue.
108    BikeIssue,
109    /// Cancellation.
110    Cancellation,
111    /// Delay.
112    Delay,
113    /// Detour.
114    Detour,
115    /// Dock closure.
116    DockClosure,
117    /// Dock issue.
118    DockIssue,
119    /// Elevator closure.
120    ElevatorClosure,
121    /// Escalator closure.
122    EscalatorClosure,
123    /// Extra service.
124    ExtraService,
125    /// Facility issue.
126    FacilityIssue,
127    /// Modified service.
128    ModifiedService,
129    /// No service.
130    NoService,
131    /// Other effect.
132    OtherEffect,
133    /// Parking closure.
134    ParkingClosure,
135    /// Parking issue.
136    ParkingIssue,
137    /// Policy change.
138    PolicyChange,
139    /// Schedule change.
140    ScheduleChange,
141    /// Service change.
142    ServiceChange,
143    /// Shuttle.
144    Shuttle,
145    /// Snow route.
146    SnowRoute,
147    /// Station closure.
148    StationClosure,
149    /// Station issue.
150    StationIssue,
151    /// Stop closure.
152    StopClosure,
153    /// Stop move.
154    StopMove,
155    /// Stop moved.
156    StopMoved,
157    /// Summary.
158    Summary,
159    /// Suspension.
160    Suspension,
161    /// Track change.
162    TrackChange,
163    /// Unknown effect.
164    UnknownEffect,
165}
166
167/// What is causing an alert.
168#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Copy)]
169#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
170pub enum Cause {
171    /// A general accident.
172    Accident,
173    /// Amtrak.
174    Amtrak,
175    /// An earlier mechanical problem.
176    AnEarlierMechanicalProblem,
177    /// An earlier signal problem.
178    AnEarlierSignalProblem,
179    /// Automobiles impeding service.
180    AutosImpedingService,
181    /// Coast guard restriction.
182    CoastGuardRestriction,
183    /// Congestion.
184    Congestion,
185    /// Construction.
186    Construction,
187    /// Crossing malfunction.
188    CrossingMalfunction,
189    /// Demonstration.
190    Demonstration,
191    /// Disabled bus.
192    DisabledBus,
193    /// Disabled train.
194    DisabledTrain,
195    /// Drawbridge being raised.
196    DrawbridgeBeingRaised,
197    /// Electrical work.
198    ElectricalWork,
199    /// Fire.
200    Fire,
201    /// Fog.
202    Fog,
203    /// Freight train interference.
204    FreightTrainInterference,
205    /// Hazmat condition.
206    HazmatCondition,
207    /// Heavy ridership.
208    HeavyRidership,
209    /// High winds.
210    HighWinds,
211    /// Holiday.
212    Holiday,
213    /// Hurricane.
214    Hurricane,
215    /// Ice in harbor.
216    IceInHarbor,
217    /// Maintenance.
218    Maintenance,
219    /// Mechanical problem.
220    MechanicalProblem,
221    /// Medical emergency.
222    MedicalEmergency,
223    /// Parade.
224    Parade,
225    /// Police action.
226    PoliceAction,
227    /// Power problem.
228    PowerProblem,
229    /// Severe weather.
230    SevereWeather,
231    /// Signal problem.
232    SignalProblem,
233    /// Slippery rail.
234    SlipperyRail,
235    /// Snow.
236    Snow,
237    /// Special event.
238    SpecialEvent,
239    /// Speed restriction.
240    SpeedRestriction,
241    /// Switch problem.
242    SwitchProblem,
243    /// Tie replacement.
244    TieReplacement,
245    /// Track problem.
246    TrackProblem,
247    /// Track work.
248    TrackWork,
249    /// Traffic.
250    Traffic,
251    /// Unruly passenger.
252    UnrulyPassenger,
253    /// Unknown cause.
254    UnknownCause,
255    /// Weather.
256    Weather,
257}
258
259/// An activity affected by an alert.
260#[derive(Deserialize, Serialize, Debug, PartialEq, Clone, Copy)]
261#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
262pub enum Activity {
263    /// Boarding a vehicle.
264    Board,
265    /// Bringing a bike.
266    BringingBike,
267    /// Exiting.
268    Exit,
269    /// Parking a car.
270    ParkCar,
271    /// Riding a vehicle.
272    Ride,
273    /// Storing a bike.
274    StoreBike,
275    /// Using an escalator.
276    UsingEscalator,
277    /// Using a wheelchair.
278    UsingWheelchair,
279}