continue working on traveldings (get live checkin thing working maybe??)
This commit is contained in:
parent
258d4639d7
commit
bd3674accf
5 changed files with 274 additions and 30 deletions
|
@ -1,4 +1,4 @@
|
|||
use chrono::{DateTime, FixedOffset};
|
||||
use chrono::{DateTime, FixedOffset, Timelike};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
@ -9,39 +9,77 @@ pub struct Container<D> {
|
|||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Status {
|
||||
train: TransportResource,
|
||||
pub train: TransportResource,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TransportResource {
|
||||
category: String,
|
||||
line_name: String,
|
||||
distance: u32,
|
||||
duration: u32,
|
||||
operator: OperatorResource,
|
||||
origin: StopOverResource,
|
||||
destination: StopOverResource,
|
||||
pub category: String,
|
||||
pub line_name: String,
|
||||
pub distance: u32,
|
||||
pub duration: u32,
|
||||
pub operator: Option<OperatorResource>,
|
||||
pub origin: StopOverResource,
|
||||
pub destination: StopOverResource,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct StopOverResource {
|
||||
name: String,
|
||||
ril_identifier: Option<String>,
|
||||
arrival: Option<DateTime<FixedOffset>>,
|
||||
arrival_planned: Option<DateTime<FixedOffset>>,
|
||||
arrival_real: Option<DateTime<FixedOffset>>,
|
||||
departure: Option<DateTime<FixedOffset>>,
|
||||
departure_planned: Option<DateTime<FixedOffset>>,
|
||||
departure_real: Option<DateTime<FixedOffset>>,
|
||||
platform: Option<String>,
|
||||
departure_platform_planned: Option<String>,
|
||||
departure_platform_real: Option<String>,
|
||||
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>,
|
||||
}
|
||||
|
||||
// ????
|
||||
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 {
|
||||
let (time_planned, time_real) = match journey_part {
|
||||
StopJourneyPart::Origin => (self.departure_planned, self.departure_real),
|
||||
StopJourneyPart::Destination => (self.arrival_planned, self.arrival_real),
|
||||
};
|
||||
|
||||
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(),
|
||||
platform_data_available: self.departure_platform_planned.is_none()
|
||||
|| self.departure_platform_real.is_none(),
|
||||
platform_planned: self.departure_platform_planned.clone(),
|
||||
platform_real: self.departure_platform_real.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct OperatorResource {
|
||||
name: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue