Skip to content

Commit

Permalink
Insert agencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Mar 27, 2024
1 parent bae3e88 commit 6b8f717
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
4 changes: 2 additions & 2 deletions migrations/2024-03-26-004608_init/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ CREATE TABLE gtfs.realtime_feeds (

CREATE TABLE gtfs.agencies (
static_onestop_id text NOT NULL,
-- fill with word "default" if this is empty
agency_id text NOT NULL,
-- Option<String> where None is a valid key
agency_id text,
attempt_id text NOT NULL,
agency_name text NOT NULL,
agency_name_translations jsonb,
Expand Down
36 changes: 36 additions & 0 deletions src/maple/gtfs_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ pub async fn gtfs_process_feed(
//identify colours of shapes based on trip id's route id
let (shape_to_color_lookup, shape_to_text_color_lookup) = shape_to_colour(&feed_id, &gtfs);

//insert agencies
for agency in &gtfs.agencies {
use catenary::schema::gtfs::agencies::dsl::agencies;

let agency_row = catenary::models::Agency {
static_onestop_id: feed_id.to_string(),
agency_id: agency.id.clone(),
attempt_id: attempt_id.to_string(),
agency_name: agency.name.clone(),
agency_name_translations: None,
agency_url_translations: None,
agency_url: agency.url.clone(),
agency_fare_url: agency.fare_url.clone(),
agency_fare_url_translations: None,
chateau: chateau_id.to_string(),
agency_lang: agency.lang.clone(),
agency_phone: agency.phone.clone(),
agency_timezone: agency.timezone.clone()
};

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

//shove raw geometry into postgresql
shapes_into_postgres(
&gtfs,
Expand All @@ -73,5 +99,15 @@ pub async fn gtfs_process_feed(
)
.await?;

//insert routes

//insert trips
//inside insert stoptimes

//insert stops

//calculate hull
//submit hull

Ok(())
}
21 changes: 21 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use diesel::prelude::*;
use diesel::pg::sql_types::Jsonb;
use serde_json::Value;

#[derive(Queryable, Selectable, Insertable, Clone)]
#[diesel(table_name = crate::schema::gtfs::shapes)]
Expand Down Expand Up @@ -81,3 +83,22 @@ pub struct IngestedStatic {
pub languages_avaliable: Vec<Option<String>>,
pub ingestion_version: i32,
}

#[derive(Queryable, Selectable, Insertable, Debug, Clone)]
#[diesel(table_name = crate::schema::gtfs::agencies)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Agency {
pub static_onestop_id: String,
pub agency_id: Option<String>,
pub attempt_id: String,
pub agency_name: String,
pub agency_name_translations: Option<Value>,
pub agency_url: String,
pub agency_url_translations: Option<Value>,
pub agency_timezone: String,
pub agency_lang: Option<String>,
pub agency_phone: Option<String>,
pub agency_fare_url: Option<String>,
pub agency_fare_url_translations: Option<Value>,
pub chateau: String,
}
2 changes: 1 addition & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod gtfs {

gtfs.agencies (static_onestop_id, attempt_id) {
static_onestop_id -> Text,
agency_id -> Text,
agency_id -> Nullable<Text>,
attempt_id -> Text,
agency_name -> Text,
agency_name_translations -> Nullable<Jsonb>,
Expand Down

0 comments on commit 6b8f717

Please sign in to comment.