Skip to content

Commit

Permalink
move own types to custom pg types
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Mar 28, 2024
1 parent 6187274 commit 64eed18
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 59 deletions.
2 changes: 1 addition & 1 deletion diesel.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
file = "src/schema.rs"
schema = "gtfs"
custom_type_derives = ["diesel::query_builder::QueryId"]
import_types = ["postgis_diesel::sql_types::*","diesel::sql_types::*"]
import_types = ["postgis_diesel::sql_types::*","diesel::sql_types::*","crate::custom_pg_types::*"]
generate_missing_sql_type_definitions = false

[migrations_directory]
Expand Down
1 change: 0 additions & 1 deletion src/aspen/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/// This is the service definition. It looks a lot like a trait definition.
/// It defines one RPC, hello, which takes one arg, name, and returns a String.
#[tarpc::service]
Expand Down
8 changes: 8 additions & 0 deletions src/custom_pg_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[derive(diesel::query_builder::QueryId, diesel::sql_types::SqlType)]
#[diesel(postgres_type(name = "trip_frequency"))]
pub struct TripFrequency {
pub start_time: i32,
pub end_time: i32,
pub headway_secs: i32,
pub exact_times: bool,
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
extern crate diesel_derive_newtype;

pub mod aspen;
pub mod custom_pg_types;
pub mod gtfs_rt_handlers;
pub mod models;
pub mod postgres_tools;
pub mod schema;
pub mod custom_pg_types;
1 change: 0 additions & 1 deletion src/maple/gtfs_handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pub mod colour_correction;
pub mod convex_hull;
pub mod enum_to_int;
Expand Down
10 changes: 5 additions & 5 deletions src/maple/gtfs_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ pub async fn gtfs_process_feed(
chateau: chateau_id.to_string(),
agency_lang: agency.lang.clone(),
agency_phone: agency.phone.clone(),
agency_timezone: agency.timezone.clone()
agency_timezone: agency.timezone.clone(),
};

diesel::insert_into(agencies)
.values(agency_row)
.execute(conn)
.await?;
.values(agency_row)
.execute(conn)
.await?;
}

//shove raw geometry into postgresql
Expand All @@ -104,7 +104,7 @@ pub async fn gtfs_process_feed(
//insert stops

//insert trips
//inside insert stoptimes
//inside insert stoptimes

//calculate hull
//submit hull
Expand Down
67 changes: 35 additions & 32 deletions src/maple/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// This was heavily inspired and copied from Emma Alexia, thank you Emma!
// Removal of the attribution is not allowed, as covered under the AGPL license

use catenary::postgres_tools::CatenaryPostgresPool;
use catenary::postgres_tools::get_connection_pool;
use catenary::postgres_tools::CatenaryPostgresPool;
use diesel::prelude::*;
use diesel_async::RunQueryDsl;
use futures::StreamExt;
Expand Down Expand Up @@ -75,29 +75,33 @@ async fn run_ingest() -> Result<(), Box<dyn Error + Send + Sync>> {
let _ = update_transitland_submodule()?;

Check warning

Code scanning / clippy

this let-binding has unit value Warning

this let-binding has unit value

//These feeds should be discarded because they are duplicated in a larger dataset called `f-sf~bay~area~rg`, which has everything in a single zip file
let feeds_to_discard: HashSet<String> = HashSet::from_iter(vec![
"f-9q8y-sfmta",
"f-9qc-westcat~ca~us",
"f-9q9-actransit",
"f-9q9-vta",
"f-9q8yy-missionbaytma~ca~us",
"f-9qbb-marintransit",
"f-9q8-samtrans",
"f-9q9-bart",
"f-9q9-caltrain",
"f-9qc3-riovistadeltabreeze",
"f-9q8z-goldengateferry",
"f-9q9j-dumbartonexpress",
"f-9qc2-trideltatransit",
"f-9q9p-sanfranciscobayferry",
"f-9qc-vinenapacounty",
"f-9qb-smart",
"f-9qc60-vacavillecitycoach",
"f-9q9jy-unioncitytransit",
"f-sfo~airtrain~shuttles",
"f-9qbdx-santarosacitybus",
"f-9q9-acealtamontcorridorexpress",
].into_iter().map(|each_feed_id| String::from(each_feed_id)));
let feeds_to_discard: HashSet<String> = HashSet::from_iter(
vec![
"f-9q8y-sfmta",
"f-9qc-westcat~ca~us",
"f-9q9-actransit",
"f-9q9-vta",
"f-9q8yy-missionbaytma~ca~us",
"f-9qbb-marintransit",
"f-9q8-samtrans",
"f-9q9-bart",
"f-9q9-caltrain",
"f-9qc3-riovistadeltabreeze",
"f-9q8z-goldengateferry",
"f-9q9j-dumbartonexpress",
"f-9qc2-trideltatransit",
"f-9q9p-sanfranciscobayferry",
"f-9qc-vinenapacounty",
"f-9qb-smart",
"f-9qc60-vacavillecitycoach",
"f-9q9jy-unioncitytransit",
"f-sfo~airtrain~shuttles",
"f-9qbdx-santarosacitybus",
"f-9q9-acealtamontcorridorexpress",
]
.into_iter()
.map(|each_feed_id| String::from(each_feed_id)),
);

info!("Initializing database connection");

Expand Down Expand Up @@ -298,13 +302,12 @@ async fn run_ingest() -> Result<(), Box<dyn Error + Send + Sync>> {
.into_iter()
.filter(|unzipped_feed| unzipped_feed.1 == true)
{

let attempt_ids = Arc::clone(&attempt_ids);
let attempt_id = attempt_ids.get(&feed_id).unwrap().clone();
if let Some(chateau_id) = feed_id_to_chateau_lookup.get(&feed_id) {
let chateau_id = chateau_id.clone();
let attempt_ids = Arc::clone(&attempt_ids);
let attempt_id = attempt_ids.get(&feed_id).unwrap().clone();
if let Some(chateau_id) = feed_id_to_chateau_lookup.get(&feed_id) {
let chateau_id = chateau_id.clone();

rt.spawn(
rt.spawn(
{
let arc_conn_pool = Arc::clone(&arc_conn_pool);
let download_feed_info_hashmap = Arc::clone(&download_feed_info_hashmap);
Expand Down Expand Up @@ -357,7 +360,7 @@ async fn run_ingest() -> Result<(), Box<dyn Error + Send + Sync>> {

}
});
}
}
}
}
} else {
Expand All @@ -370,4 +373,4 @@ async fn run_ingest() -> Result<(), Box<dyn Error + Send + Sync>> {
#[tokio::main]
async fn main() {
let _ = run_ingest().await;
}
}
2 changes: 1 addition & 1 deletion src/maple/refresh_metadata_tables.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use chateau::Chateau;
use dmfr_folder_reader::ReturnDmfrAnalysis;
use std::collections::HashMap;
use std::sync::Arc;
use std::error::Error;
use std::sync::Arc;

// Written by Kyler Chin at Catenary Transit Initiatives
// https://github.com/CatenaryTransit/catenary-backend
Expand Down
1 change: 0 additions & 1 deletion src/maple/transitland_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::time::Duration;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;


#[derive(Clone)]
struct StaticFeedToDownload {
pub feed_id: String,
Expand Down
4 changes: 2 additions & 2 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use diesel::prelude::*;
use diesel::pg::sql_types::Jsonb;
use diesel::prelude::*;
use serde_json::Value;

#[derive(Queryable, Selectable, Insertable, Clone)]
Expand Down Expand Up @@ -101,4 +101,4 @@ pub struct Agency {
pub agency_fare_url: Option<String>,
pub agency_fare_url_translations: Option<Value>,
pub chateau: String,
}
}
30 changes: 17 additions & 13 deletions src/schema.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
// @generated automatically by Diesel CLI.

pub mod gtfs {
pub mod sql_types {

#[derive(diesel::query_builder::QueryId, diesel::sql_types::SqlType)]
#[diesel(postgres_type(name = "trip_frequency"))]
pub struct TripFrequency {
pub start_time: i32,
pub end_time: i32,
pub headway_secs: i32,
pub exact_times: bool
}
}

diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.agencies (static_onestop_id, attempt_id) {
static_onestop_id -> Text,
Expand All @@ -37,6 +26,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.calendar (onestop_feed_id, attempt_id, service_id) {
onestop_feed_id -> Text,
Expand All @@ -57,6 +47,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.calendar_dates (onestop_feed_id, service_id, gtfs_date) {
onestop_feed_id -> Text,
Expand All @@ -70,6 +61,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.chateaus (chateau) {
chateau -> Text,
Expand All @@ -83,6 +75,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.feed_info (onestop_feed_id, attempt_id, feed_publisher_name) {
onestop_feed_id -> Text,
Expand All @@ -103,6 +96,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.gtfs_errors (onestop_feed_id, attempt_id) {
onestop_feed_id -> Text,
Expand All @@ -116,6 +110,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.ingested_static (onestop_feed_id, ingest_start_unix_time_ms) {
onestop_feed_id -> Text,
Expand All @@ -137,6 +132,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.realtime_feeds (onestop_feed_id) {
onestop_feed_id -> Text,
Expand All @@ -150,6 +146,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.realtime_passwords (onestop_feed_id) {
onestop_feed_id -> Text,
Expand All @@ -163,6 +160,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.routes (onestop_feed_id, attempt_id, route_id) {
onestop_feed_id -> Text,
Expand Down Expand Up @@ -190,6 +188,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.shapes (onestop_feed_id, attempt_id, shape_id) {
onestop_feed_id -> Text,
Expand All @@ -209,6 +208,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.static_download_attempts (onestop_feed_id, downloaded_unix_time_ms) {
onestop_feed_id -> Text,
Expand All @@ -226,6 +226,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.static_feeds (onestop_feed_id) {
onestop_feed_id -> Text,
Expand All @@ -238,6 +239,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.static_passwords (onestop_feed_id) {
onestop_feed_id -> Text,
Expand All @@ -251,6 +253,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.stops (onestop_feed_id, attempt_id, gtfs_id) {
onestop_feed_id -> Text,
Expand Down Expand Up @@ -288,6 +291,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use crate::custom_pg_types::*;

gtfs.stoptimes (onestop_feed_id, attempt_id, trip_id, stop_sequence) {
onestop_feed_id -> Text,
Expand All @@ -314,7 +318,7 @@ pub mod gtfs {
diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
use super::sql_types::TripFrequency;
use crate::custom_pg_types::*;

gtfs.trips (onestop_feed_id, attempt_id, trip_id) {
trip_id -> Text,
Expand Down
2 changes: 1 addition & 1 deletion src/spruce/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use actix::{ActorContext};
use actix::ActorContext;
use actix::{Actor, StreamHandler};
use actix_web::{web, App, Error, HttpRequest, HttpResponse, HttpServer};
use actix_web_actors::ws;
Expand Down

0 comments on commit 64eed18

Please sign in to comment.