From 130d8907335c93e48017c13e3202816d552683c9 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 25 Jan 2022 23:07:23 +0100 Subject: hacky proof of concept --- src/iceportal.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/iceportal.rs (limited to 'src/iceportal.rs') diff --git a/src/iceportal.rs b/src/iceportal.rs new file mode 100644 index 0000000..1b36556 --- /dev/null +++ b/src/iceportal.rs @@ -0,0 +1,67 @@ +use serde::Deserialize; +use serde_json::Value; + +use crate::travelynx::TrainRef; + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct TripInfo { + trip: Trip, + connection: Option, + selected_route: Option, + active: Option +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Trip { + train_type: String, + vzn: String, // train number + // some position info here + actual_position: u64, // distance along track, presumably + stops: Vec +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Stop { + info: StopInfo, + station: Station +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct StopInfo { + distance_from_start: u64, + position_status: String // one of "departed", "future", ... ? +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Station { + eva_nr: String, + name: String +} + + +impl TripInfo { + + pub fn guess_last_station (&self) -> Option { + let current_pos = self.trip.actual_position; + self.trip + .stops + .iter() + .rev() + .map(|stop| (stop.info.distance_from_start, stop)) + .filter(|(dist,_)| dist <= ¤t_pos) + .next() + .map(|(_,stop)| stop.station.name.clone()) + } + + pub fn get_train_ref (&self) -> TrainRef { + TrainRef { + _type: self.trip.train_type.clone(), + no: self.trip.vzn.clone() + } + } +} -- cgit v1.2.3