live tracking and filter
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
534c36b0f7
commit
f5e0a31bb7
16 changed files with 414 additions and 115 deletions
|
|
@ -1,10 +1,10 @@
|
|||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
use actix_web::Route;
|
||||
use std::collections::HashMap;
|
||||
use libseptastic::{direction::CardinalDirection, route::RouteType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{Postgres, Transaction};
|
||||
|
||||
use crate::services::trip_tracking::TripTracking;
|
||||
|
||||
pub async fn get_route_by_id(
|
||||
id: String,
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
|
|
@ -36,6 +36,39 @@ pub async fn get_route_by_id(
|
|||
});
|
||||
}
|
||||
|
||||
pub async fn get_all_routes(
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
) -> ::anyhow::Result<Vec<libseptastic::route::Route>> {
|
||||
|
||||
let rows = sqlx::query!(
|
||||
r#"SELECT
|
||||
id,
|
||||
name,
|
||||
short_name,
|
||||
color_hex,
|
||||
route_type as "route_type: libseptastic::route::RouteType"
|
||||
FROM
|
||||
septa_routes
|
||||
;"#
|
||||
)
|
||||
.fetch_all(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
let mut routes = Vec::new();
|
||||
|
||||
for row in rows {
|
||||
routes.push(libseptastic::route::Route {
|
||||
name: row.name,
|
||||
short_name: row.short_name,
|
||||
color_hex: row.color_hex,
|
||||
route_type: row.route_type,
|
||||
id: row.id,
|
||||
});
|
||||
}
|
||||
|
||||
return Ok(routes);
|
||||
}
|
||||
|
||||
pub async fn get_direction_by_route_id(
|
||||
id: String,
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
|
|
@ -89,9 +122,11 @@ pub struct Trip {
|
|||
pub route_id: String,
|
||||
pub trip_id: String,
|
||||
pub direction_id: i64,
|
||||
pub tracking_data: TripTracking,
|
||||
pub schedule: Vec<StopSchedule>
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_schedule_by_route_id(
|
||||
id: String,
|
||||
transaction: &mut Transaction<'_, Postgres>,
|
||||
|
|
@ -133,7 +168,7 @@ pub async fn get_schedule_by_route_id(
|
|||
|
||||
let mut sched_groups: HashMap<String, Vec<StopSchedule>> = HashMap::new();
|
||||
for row in rows {
|
||||
let mut arr = match sched_groups.get_mut(&row.trip_id) {
|
||||
let arr = match sched_groups.get_mut(&row.trip_id) {
|
||||
Some(x) => x,
|
||||
None => {
|
||||
sched_groups.insert(row.trip_id.clone(), Vec::new());
|
||||
|
|
@ -159,7 +194,8 @@ pub async fn get_schedule_by_route_id(
|
|||
trip_id: group.0,
|
||||
route_id: group.1[0].route_id.clone(),
|
||||
schedule: group.1.clone(),
|
||||
direction_id: group.1[0].direction_id.clone()
|
||||
direction_id: group.1[0].direction_id.clone(),
|
||||
tracking_data: TripTracking::Untracked
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue