summaryrefslogtreecommitdiff
path: root/src/iceportal.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/iceportal.rs67
1 files changed, 67 insertions, 0 deletions
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<Value>,
+ selected_route: Option<Value>,
+ active: Option<Value>
+}
+
+#[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<Stop>
+}
+
+#[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<String> {
+ let current_pos = self.trip.actual_position;
+ self.trip
+ .stops
+ .iter()
+ .rev()
+ .map(|stop| (stop.info.distance_from_start, stop))
+ .filter(|(dist,_)| dist <= &current_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()
+ }
+ }
+}