summaryrefslogtreecommitdiff
path: root/src/iceportal.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/iceportal.rs109
1 files changed, 54 insertions, 55 deletions
diff --git a/src/iceportal.rs b/src/iceportal.rs
index 0d2076e..fb5bca8 100644
--- a/src/iceportal.rs
+++ b/src/iceportal.rs
@@ -2,99 +2,98 @@ use chrono::{DateTime, NaiveDateTime, Utc};
use serde::Deserialize;
use serde_json::Value;
-use crate::{travelynx::TrainRef, types::IsStation, serde::*};
+use crate::{serde::*, travelynx::TrainRef, types::IsStation};
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TripInfo {
- trip: Trip,
- connection: Option<Value>,
- selected_route: Option<Value>,
- active: Option<Value>
+ 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>
+ 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")]
pub struct Stop {
- info: StopInfo,
- station: Station,
- timetable: Timetable
+ info: StopInfo,
+ station: Station,
+ timetable: Timetable
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct StopInfo {
- distance_from_start: u64,
- position_status: String // one of "departed", "future", ... ?
+ 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
+ eva_nr: String,
+ name: String
}
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Timetable {
- #[serde(deserialize_with = "option_naive_read_unixtime_db")]
- scheduled_arrival_time: Option<DateTime<Utc>>,
- #[serde(deserialize_with = "option_naive_read_unixtime_db")]
- actual_arrival_time: Option<DateTime<Utc>>
+ #[serde(deserialize_with = "option_naive_read_unixtime_db")]
+ scheduled_arrival_time: Option<DateTime<Utc>>,
+ #[serde(deserialize_with = "option_naive_read_unixtime_db")]
+ actual_arrival_time: Option<DateTime<Utc>>
}
impl IsStation for Stop {
- fn name (&self) -> &str {
- &self.station.name
- }
+ fn name(&self) -> &str {
+ &self.station.name
+ }
- fn scheduled_arrival (&self) -> Option<&chrono::DateTime<Utc>> {
- self.timetable.scheduled_arrival_time.as_ref()
- }
+ fn scheduled_arrival(&self) -> Option<&chrono::DateTime<Utc>> {
+ self.timetable.scheduled_arrival_time.as_ref()
+ }
- fn real_arrival (&self) -> Option<&chrono::DateTime<Utc>> {
- self.timetable.scheduled_arrival_time.as_ref()
- }
+ fn real_arrival(&self) -> Option<&chrono::DateTime<Utc>> {
+ self.timetable.scheduled_arrival_time.as_ref()
+ }
- fn ds100 (&self) -> &str {
- "??"
- }
+ fn ds100(&self) -> &str {
+ "??"
+ }
}
-
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()
- }
+ 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()
}
+ }
- pub fn trip (&self) -> crate::types::Trip<'_,Stop> {
- crate::types::Trip(&self.trip.stops)
- }
+ pub fn trip(&self) -> crate::types::Trip<'_, Stop> {
+ crate::types::Trip(&self.trip.stops)
+ }
}