many changes

This commit is contained in:
Nicholas Orlowsky 2025-09-12 19:08:22 -04:00
parent 4777f46a38
commit be177af6cd
No known key found for this signature in database
GPG key ID: A9F3BA4C0AA7A70B
25 changed files with 2059 additions and 47 deletions

View file

@ -538,6 +538,8 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
name = "libseptastic"
version = "0.1.0"
dependencies = [
"serde",
"serde_json",
"sqlx",
]

View file

@ -4,4 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
serde = "1.0.219"
serde_json = "1.0.140"
sqlx = "0.8.6"

View file

@ -0,0 +1,37 @@
use serde::{Deserialize, Serialize};
#[derive(sqlx::Type, Serialize, Deserialize, PartialEq, Debug, Clone)]
#[sqlx(type_name = "septa_direction_type", rename_all = "snake_case")]
pub enum CardinalDirection {
Northbound,
Southbound,
Eastbound,
Westbound,
Inbound,
Outbound,
Loop
}
#[derive(::sqlx::Decode, Serialize, Deserialize, Debug, Clone)]
pub struct Direction {
pub route_id: String,
pub direction_id: i64,
pub direction: CardinalDirection,
pub direction_destination: String
}
impl std::fmt::Display for CardinalDirection {
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let output = match self {
CardinalDirection::Northbound => "Northbound",
CardinalDirection::Southbound => "Southbound",
CardinalDirection::Eastbound => "Eastbound",
CardinalDirection::Westbound => "Westbound",
CardinalDirection::Inbound => "Inbound",
CardinalDirection::Outbound => "Outbound",
CardinalDirection::Loop => "Loop"
};
std::write!(f, "{}", output)
}
}

View file

@ -3,3 +3,5 @@ pub mod stop;
pub mod route_stop;
pub mod stop_schedule;
pub mod schedule_day;
pub mod direction;
pub mod ridership;

View file

@ -0,0 +1,21 @@
use serde::{Deserialize, Serialize};
use crate::direction::CardinalDirection;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Ridership {
pub route_id: String,
pub stop_id: i64,
pub direction: CardinalDirection,
pub exp_ons: i64,
pub exp_offs: i64,
pub ons: i64,
pub offs: i64,
pub year: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LineRidership {
pub route_id: String,
pub unlinked_trips: i64
}

View file

@ -1,4 +1,6 @@
#[derive(sqlx::Type, PartialEq, Debug, Clone)]
use serde::{Deserialize, Serialize};
#[derive(sqlx::Type, Serialize, Deserialize, PartialEq, Debug, Clone)]
#[sqlx(type_name = "septa_route_type", rename_all = "snake_case")]
pub enum RouteType {
Trolley,
@ -8,34 +10,11 @@ pub enum RouteType {
TracklessTrolley
}
#[derive(sqlx::Type, PartialEq, Debug, Clone)]
#[sqlx(type_name = "septa_direction_type", rename_all = "snake_case")]
pub enum CardinalDirection {
Northbound,
Southbound,
Eastbound,
Westbound // (and down)
}
#[derive(Debug, Clone)]
pub struct Directional {
pub direction: CardinalDirection,
pub direction_destination: String
}
#[derive(Debug, Clone)]
pub struct RouteDirectional {
pub primary: Directional, // 0
pub secondary: Directional, // 1
}
#[derive(Debug, Clone)]
#[derive(::sqlx::FromRow, Serialize, Deserialize, Debug, Clone)]
pub struct Route {
pub name: String,
pub short_name: String,
pub color_hex: String,
pub route_type: RouteType,
pub id: String,
pub directional: RouteDirectional
pub id: String
}

View file

@ -1,9 +1,7 @@
use super::route::CardinalDirection;
#[derive(Debug, Clone)]
pub struct RouteStop {
pub route_id: String,
pub stop_id: i64,
pub direction: CardinalDirection,
pub direction_id: i64,
pub stop_sequence: i64
}

View file

@ -1,12 +1,20 @@
use super::route::CardinalDirection;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StopSchedule {
pub route_id: String,
pub trip_id: String,
pub service_id: String,
pub direction: CardinalDirection,
pub direction_id: i64,
pub arrival_time: i64,
pub stop_id: i64,
pub stop_sequence: i64
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Trip {
pub route_id: String,
pub trip_id: String,
pub direction_id: i64,
pub schedule: Vec<StopSchedule>
}