mbta_rs/models/prediction.rs
1//! Data models for MBTA predictions.
2
3use chrono::{offset::FixedOffset, DateTime};
4use serde::{Deserialize, Serialize};
5
6use super::*;
7
8/// Multiple predictions.
9pub type Predictions = Vec<Prediction>;
10
11/// The predicted arrival and departure time to/from a stop at a given sequence along a trip going a direction along a route.
12pub type Prediction = Resource<PredictionAttributes>;
13
14/// Attributes for a prediction.
15#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
16pub struct PredictionAttributes {
17 /// The sequence the stop is arrived at during the trip.
18 /// The stop sequence is monotonically increasing along the trip, but the stop_sequence along the trip are not necessarily consecutive.
19 #[serde(default)]
20 pub stop_sequence: Option<u64>,
21 /// Status of the prediction.
22 pub status: Option<String>,
23 /// Direction in which trip is traveling: 0 or 1.
24 pub direction_id: u8,
25 /// When the vehicle is now predicted to depart. [None] if the last stop on the trip.
26 #[serde(with = "optional_mbta_datetime_format")]
27 pub departure_time: Option<DateTime<FixedOffset>>,
28 /// When the vehicle is now predicted to arrive. [None] if the first stop on the trip.
29 #[serde(with = "optional_mbta_datetime_format")]
30 pub arrival_time: Option<DateTime<FixedOffset>>,
31 /// How the predicted stop relates to the scheduled stops. [None] if the predicted stop was scheduled.
32 pub schedule_relationship: Option<ScheduleRelationship>,
33}
34
35/// How a predicted stop relates to the scheduled stops.
36#[derive(Debug, PartialEq, Clone, Copy, Deserialize, Serialize)]
37#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
38pub enum ScheduleRelationship {
39 /// An extra trip that was added in addition to a running schedule, for example, to replace a broken vehicle or to respond to sudden passenger load.
40 Added,
41 /// A trip that existed in the schedule but was removed.
42 Cancelled,
43 /// No data is given for this stop. It indicates that there is no realtime information available.
44 NoData,
45 /// The stop was originally scheduled, but was skipped.
46 Skipped,
47 /// A trip that is running with no schedule associated to it.
48 Unscheduled,
49}