Skip to content

Commit

Permalink
Delete old trip structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Apr 9, 2024
1 parent 01bf8d4 commit 3b4116f
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 56 deletions.
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ crossbeam-utils = "0.8.16"
memoffset = "0.9.0"
time = "0.3.30"
rouille = "3.0"
gtfs-rt = {version = "0.5.0"}
gtfs-rt = "0.5.0"
reqwest = {version = "0.11", features = ["gzip","brotli","rustls-tls","deflate","cookies","mime_guess"]}
protobuf = "3.3"
csv = "1.3"
Expand Down Expand Up @@ -124,10 +124,7 @@ name = "spruce"
path = "src/spruce/main.rs"

#Test binaries
[[bin]]
name = "pg_tests"
path = "src/pg_tests/main.rs"

[[bin]]
name = "test_maple_syrup"
path = "src/maple_syrup/test.rs"
path = "src/maple_syrup/test.rs"
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ DROP INDEX IF EXISTS itinerary_pattern_chateau_idx;
DROP INDEX IF EXISTS trips_compressed_chateau_idx;

ALTER TABLE gtfs.routes
DROP COLUMN stops;
DROP COLUMN IF EXISTS stops;

DROP TABLE IF EXISTS gtfs.stopsforroute;
10 changes: 8 additions & 2 deletions migrations/2024-04-06-053500_timetable-compression-v1/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ CREATE TABLE gtfs.trips_compressed (

CREATE INDEX trips_compressed_chateau_idx ON gtfs.trips_compressed (chateau);

ALTER TABLE gtfs.routes
ADD stops bytea;
CREATE TABLE gtfs.stopsforroute (
onestop_feed_id text NOT NULL,
attempt_id text NOT NULL,
route_id text NOT NULL,
stops bytea,
chateau text NOT NULL,
PRIMARY KEY (onestop_feed_id, attempt_id, route_id)
);
Empty file added src/alpenrose/README.md
Empty file.
11 changes: 11 additions & 0 deletions src/alpenrose/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// Copyright Kyler Chin <[email protected]>
// Attribution cannot be removed

// AGPL 3.0

use std::thread;
use std::time::Duration;
use uuid::Uuid;
use tokio_zookeeper::*;
use futures::prelude::*;

fn main() {
let this_worker_id = Arc::new(Uuid::new_v4());
Expand All @@ -14,6 +21,10 @@ fn main() {
//hands off data to aspen to do additional cleanup and processing, Aspen will perform association with the GTFS schedule data + update dynamic graphs for routing and map representation,
//aspen will also forward critical alerts to users

let (zk, default_watcher) = ZooKeeper::connect(&"127.0.0.1:2181".parse().unwrap())
.await
.unwrap();

//spawn the thread to listen to be a leader
thread::spawn(|| {
//read passwords and dynamically update passwords from postgres
Expand Down
29 changes: 0 additions & 29 deletions src/birch/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,34 +423,6 @@ FROM (
}
}

#[actix_web::get("/barebones_trip/{chateau_id}/{trip_id}")]
async fn barebones_trip(
pool: web::Data<Arc<CatenaryPostgresPool>>,
path: web::Path<(String, String)>,
req: HttpRequest,
) -> impl Responder {
let conn_pool = pool.as_ref();
let conn_pre = conn_pool.get().await;
let conn = &mut conn_pre.unwrap();

let (chateau_id, trip_id) = path.into_inner();

use catenary::schema::gtfs::trips as trips_pg_schema;

let trips = trips_pg_schema::dsl::trips
.filter(trips_pg_schema::dsl::chateau.eq(&chateau_id))
.filter(trips_pg_schema::dsl::trip_id.eq(&trip_id))
.select((catenary::models::Trip::as_select()))
.load::<catenary::models::Trip>(conn)
.await
.unwrap();

HttpResponse::Ok()
.insert_header(("Content-Type", "application/json"))
.insert_header(("Cache-Control", "max-age=86400"))
.body(serde_json::to_string(&trips).unwrap())
}

#[actix_web::get("/getroutesofchateau/{chateau}")]
async fn routesofchateau(
pool: web::Data<Arc<CatenaryPostgresPool>>,
Expand Down Expand Up @@ -911,7 +883,6 @@ async fn main() -> std::io::Result<()> {
.service(shapes_bus_meta)
.service(irvinevehproxy)
.service(routesofchateau)
.service(barebones_trip)
.service(bus_stops_meta)
.service(bus_stops)
.service(rail_stops)
Expand Down
18 changes: 0 additions & 18 deletions src/maple/update_schedules_with_new_chateau_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ pub async fn update_schedules_with_new_chateau_id(

println!("Reassigning feed {} to Château {}", feed_id, new_chateau_id);

use catenary::schema::gtfs::trips;
use catenary::schema::gtfs::trips::dsl::trips as trips_table;

let _ = diesel::update(trips_table)
.filter(trips::dsl::onestop_feed_id.eq(feed_id))
.set(trips::dsl::chateau.eq(new_chateau_id))
.execute(conn)
.await?;

use catenary::schema::gtfs::stoptimes;
use catenary::schema::gtfs::stoptimes::dsl::stoptimes as stop_times_table;

let _ = diesel::update(stop_times_table)
.filter(stoptimes::dsl::onestop_feed_id.eq(feed_id))
.set(stoptimes::dsl::chateau.eq(new_chateau_id))
.execute(conn)
.await?;

use catenary::schema::gtfs::agencies;
use catenary::schema::gtfs::agencies::dsl::agencies as agencies_table;

Expand Down
9 changes: 9 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@ pub struct Route {
pub continuous_pickup: i16,
pub continuous_drop_off: i16,
pub shapes_list: Option<Vec<Option<String>>>,
pub chateau: String,
}

#[derive(Queryable, Selectable, Insertable, Debug, Clone, Serialize, Deserialize)]
#[diesel(table_name = crate::schema::gtfs::stopsforroute)]
pub struct StopsForRoute {
pub onestop_feed_id: String,
pub attempt_id: String,
pub route_id: String,
pub stops: Option<Vec<u8>>,
pub chateau: String,
}
Expand Down
16 changes: 15 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ pub mod gtfs {
continuous_drop_off -> Int2,
shapes_list -> Nullable<Array<Nullable<Text>>>,
chateau -> Text,
stops -> Nullable<Bytea>,
}
}

Expand Down Expand Up @@ -386,6 +385,20 @@ pub mod gtfs {
}
}

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

gtfs.stopsforroute (onestop_feed_id, attempt_id, route_id) {
onestop_feed_id -> Text,
attempt_id -> Text,
route_id -> Text,
stops -> Nullable<Bytea>,
chateau -> Text,
}
}

diesel::table! {
use postgis_diesel::sql_types::*;
use diesel::sql_types::*;
Expand Down Expand Up @@ -448,6 +461,7 @@ pub mod gtfs {
static_feeds,
static_passwords,
stops,
stopsforroute,
trip_frequencies,
trips_compressed,
);
Expand Down

0 comments on commit 3b4116f

Please sign in to comment.