2024-09-10 21:37:18 +02:00
|
|
|
use chrono::{DateTime, FixedOffset, Timelike};
|
2024-09-07 18:31:04 +02:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
pub struct Container<D> {
|
|
|
|
pub data: D,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Status {
|
2024-09-10 21:37:18 +02:00
|
|
|
pub train: TransportResource,
|
2024-09-07 18:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct TransportResource {
|
2024-09-10 21:37:18 +02:00
|
|
|
pub category: String,
|
|
|
|
pub line_name: String,
|
|
|
|
pub distance: u32,
|
|
|
|
pub duration: u32,
|
|
|
|
pub operator: Option<OperatorResource>,
|
|
|
|
pub origin: StopOverResource,
|
|
|
|
pub destination: StopOverResource,
|
2024-09-07 18:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct StopOverResource {
|
2024-09-10 21:37:18 +02:00
|
|
|
pub name: String,
|
|
|
|
pub ril_identifier: Option<String>,
|
|
|
|
pub arrival_planned: Option<DateTime<FixedOffset>>,
|
|
|
|
pub arrival_real: Option<DateTime<FixedOffset>>,
|
|
|
|
pub departure_planned: Option<DateTime<FixedOffset>>,
|
|
|
|
pub departure_real: Option<DateTime<FixedOffset>>,
|
|
|
|
pub platform: Option<String>,
|
|
|
|
pub departure_platform_planned: Option<String>,
|
|
|
|
pub departure_platform_real: Option<String>,
|
2024-09-11 02:09:08 +02:00
|
|
|
pub arrival_platform_planned: Option<String>,
|
|
|
|
pub arrival_platform_real: Option<String>,
|
2024-09-10 21:37:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ????
|
|
|
|
pub struct JsonableData {
|
|
|
|
pub time_err: bool,
|
|
|
|
pub time_planned: Option<i64>,
|
|
|
|
pub time_real: Option<i64>,
|
|
|
|
pub station: String,
|
|
|
|
pub ril100: Option<String>,
|
|
|
|
pub platform_data_available: bool,
|
|
|
|
pub platform_planned: Option<String>,
|
|
|
|
pub platform_real: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
// What the meaning of the stop in the journey is
|
|
|
|
pub enum StopJourneyPart {
|
|
|
|
Origin,
|
|
|
|
Destination,
|
|
|
|
}
|
|
|
|
impl StopOverResource {
|
|
|
|
pub fn get_time_data(&self, journey_part: StopJourneyPart) -> JsonableData {
|
2024-09-11 02:09:08 +02:00
|
|
|
let (time_planned, time_real, platform_planned, platform_real) = match journey_part {
|
|
|
|
StopJourneyPart::Origin => (
|
|
|
|
self.departure_planned,
|
|
|
|
self.departure_real,
|
|
|
|
self.departure_platform_planned.clone(),
|
|
|
|
self.departure_platform_real.clone(),
|
|
|
|
),
|
|
|
|
StopJourneyPart::Destination => (
|
|
|
|
self.arrival_planned,
|
|
|
|
self.arrival_real,
|
|
|
|
self.arrival_platform_planned.clone(),
|
|
|
|
self.arrival_platform_real.clone(),
|
|
|
|
),
|
2024-09-10 21:37:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
let time_err = time_planned == None;
|
|
|
|
|
|
|
|
JsonableData {
|
|
|
|
time_err,
|
|
|
|
time_planned: time_planned.map(|ts| ts.timestamp()),
|
|
|
|
time_real: time_real.map(|ts| ts.timestamp()),
|
|
|
|
station: self.name.clone(),
|
|
|
|
ril100: self.ril_identifier.clone(),
|
2024-09-11 02:09:08 +02:00
|
|
|
platform_data_available: platform_planned.is_some() || platform_real.is_some(),
|
|
|
|
platform_planned,
|
|
|
|
platform_real,
|
2024-09-10 21:37:18 +02:00
|
|
|
}
|
|
|
|
}
|
2024-09-07 18:31:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct OperatorResource {
|
2024-09-10 21:37:18 +02:00
|
|
|
pub name: String,
|
2024-09-07 18:31:04 +02:00
|
|
|
}
|