just add data loader here
Some checks failed
Create and publish a Docker image / build-and-push-image (push) Has been cancelled
Some checks failed
Create and publish a Docker image / build-and-push-image (push) Has been cancelled
This commit is contained in:
parent
04ae29eb27
commit
55df6bdb16
23 changed files with 4097 additions and 1 deletions
19
data_loader/src/septa_json/direction.rs
Normal file
19
data_loader/src/septa_json/direction.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use crate::traits::*;
|
||||
use serde::Deserialize;
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Direction {
|
||||
#[serde(rename="Route")]
|
||||
pub route: String,
|
||||
#[serde(rename="DirectionDescription")]
|
||||
pub direction_destination: String,
|
||||
#[serde(rename="Direction")]
|
||||
pub direction: String,
|
||||
#[serde(rename="TrueDirection")]
|
||||
pub true_direction: String,
|
||||
#[serde(rename="Mode")]
|
||||
pub mode: String
|
||||
}
|
||||
|
||||
impl SeptaJson for Direction {}
|
||||
6
data_loader/src/septa_json/mod.rs
Normal file
6
data_loader/src/septa_json/mod.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
pub mod route;
|
||||
pub mod route_stop;
|
||||
pub mod stop_schedule;
|
||||
pub mod schedule_day;
|
||||
pub mod direction;
|
||||
pub mod ridership;
|
||||
37
data_loader/src/septa_json/ridership.rs
Normal file
37
data_loader/src/septa_json/ridership.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use crate::traits::*;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Ridership {
|
||||
#[serde(rename = "Stop ID")]
|
||||
pub stop_id: Option<String>,
|
||||
|
||||
#[serde(rename = "Stop Code")]
|
||||
pub stop_code: String,
|
||||
|
||||
#[serde(rename = "Stop")]
|
||||
pub stop_name: String,
|
||||
|
||||
#[serde(rename = "Route")]
|
||||
pub route_id: String,
|
||||
|
||||
#[serde(rename = "Direction")]
|
||||
pub direction: String,
|
||||
|
||||
#[serde(rename = "Ons")]
|
||||
pub ons: String,
|
||||
|
||||
#[serde(rename = "Offs")]
|
||||
pub offs: String,
|
||||
|
||||
#[serde(rename = "Exp_Ons")]
|
||||
pub exp_ons: String,
|
||||
|
||||
#[serde(rename = "Exp_Offs")]
|
||||
pub exp_offs: String,
|
||||
|
||||
#[serde(rename = "Year")]
|
||||
pub year: String
|
||||
}
|
||||
|
||||
impl SeptaJson for Ridership {}
|
||||
42
data_loader/src/septa_json/route.rs
Normal file
42
data_loader/src/septa_json/route.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use crate::traits::*;
|
||||
use serde_repr::*;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Serialize_repr, Deserialize_repr, PartialEq, Debug)]
|
||||
#[repr(u8)]
|
||||
pub enum RouteType {
|
||||
Trolley= 0,
|
||||
SubwayElevated = 1,
|
||||
RegionalRail = 2,
|
||||
Bus = 3,
|
||||
TracklessTrolley = 11
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Document {
|
||||
#[serde(rename = "type")]
|
||||
pub doc_type: String,
|
||||
pub title: String,
|
||||
pub url: String,
|
||||
pub link_label: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Route {
|
||||
pub release_name: String,
|
||||
pub route_id: String,
|
||||
pub route_short_name: String,
|
||||
pub route_long_name: String,
|
||||
pub route_type: RouteType,
|
||||
pub route_color: String,
|
||||
pub route_text_color: String,
|
||||
pub route_frequency_text: String,
|
||||
pub is_frequent_bus: bool,
|
||||
pub route_color_dark: String,
|
||||
pub route_color_text_dark: String,
|
||||
pub documents: Vec<Document>
|
||||
}
|
||||
|
||||
impl SeptaJson for Route {}
|
||||
impl SeptaJson for RouteType {}
|
||||
31
data_loader/src/septa_json/route_stop.rs
Normal file
31
data_loader/src/septa_json/route_stop.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use crate::traits::*;
|
||||
use serde::{self, Deserialize, Deserializer};
|
||||
|
||||
pub fn de_string_or_int<'de, D>(deserializer: D) -> Result<i64, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
use serde::de::Error;
|
||||
use serde_json::Value;
|
||||
|
||||
match Value::deserialize(deserializer)? {
|
||||
Value::Number(n) => n.as_i64().ok_or_else(|| Error::custom("Invalid number")),
|
||||
Value::String(s) => s.parse::<i64>().map_err(|_| Error::custom("Invalid string number")),
|
||||
_ => Err(Error::custom("Expected a string or number")),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct RouteStop {
|
||||
pub route_id: String,
|
||||
pub direction_id: i64,
|
||||
#[serde(deserialize_with = "de_string_or_int")]
|
||||
pub stop_id: i64,
|
||||
pub stop_name: String,
|
||||
pub stop_sequence: i64,
|
||||
pub stop_lat: f64,
|
||||
pub stop_lon: f64,
|
||||
}
|
||||
|
||||
impl SeptaJson for RouteStop {}
|
||||
impl SeptaJson for Vec<RouteStop> {}
|
||||
18
data_loader/src/septa_json/schedule_day.rs
Normal file
18
data_loader/src/septa_json/schedule_day.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
|
||||
use crate::traits::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Default, Debug, Serialize, Deserialize)]
|
||||
pub struct ScheduleDay {
|
||||
pub release_name: String,
|
||||
pub special: bool,
|
||||
pub service_id: Vec<String>,
|
||||
pub service_added: Vec<String>,
|
||||
pub service_removed: Vec<String>
|
||||
}
|
||||
|
||||
pub type Calendar = BTreeMap<String, ScheduleDay>;
|
||||
|
||||
impl SeptaJson for Calendar {}
|
||||
27
data_loader/src/septa_json/stop_schedule.rs
Normal file
27
data_loader/src/septa_json/stop_schedule.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use crate::traits::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum TripId {
|
||||
RegionalRail(String),
|
||||
Other(i64)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct StopSchedule {
|
||||
pub route_id: String,
|
||||
pub block_id: i64,
|
||||
pub release_name: String,
|
||||
pub trip_id: TripId,
|
||||
pub service_id: String,
|
||||
pub trip_headsign: Option<String>,
|
||||
pub direction_id: i64,
|
||||
pub arrival_time: String,
|
||||
pub stop_id: i64,
|
||||
pub stop_name: String,
|
||||
pub stop_sequence: i64,
|
||||
pub last_stop_id: i64
|
||||
}
|
||||
|
||||
impl SeptaJson for StopSchedule {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue