Skip to content

Commit

Permalink
Begin adding Chateau grouping system
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Feb 23, 2024
1 parent c1e8d64 commit ae6d84f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
44 changes: 27 additions & 17 deletions migrations/20240110110356_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ CREATE TABLE gtfs.static_feeds (
onestop_feed_id text NOT NULL PRIMARY KEY,
only_realtime_ref text,
operators text[] NOT NULL,
operators_to_gtfs_ids JSONB NOT NULL,
operators_to_gtfs_ids hstore NOT NULL,
realtime_onestop_ids text[] NOT NULL,
realtime_onestop_ids_to_gtfs_ids JSONB NOT NULL,
realtime_onestop_ids_to_gtfs_ids hstore NOT NULL,
chateau text NOT NULL,
hull GEOMETRY(POLYGON,4326)
);

Expand All @@ -43,6 +44,7 @@ CREATE TABLE gtfs.feed_info (
feed_contact_email text,
feed_contact_url text,
attempt_id text,
chateau text,
PRIMARY KEY (onestop_feed_id, attempt_id, feed_publisher_name)
);

Expand All @@ -51,19 +53,20 @@ CREATE TABLE gtfs.operators (
name text,
gtfs_static_feeds text[],
gtfs_realtime_feeds text[],
static_onestop_feeds_to_gtfs_ids JSONB,
realtime_onestop_feeds_to_gtfs_ids JSONB
static_onestop_feeds_to_gtfs_ids hstore,
realtime_onestop_feeds_to_gtfs_ids hstore
);

CREATE TABLE gtfs.realtime_feeds (
onestop_feed_id text PRIMARY KEY,
name text,
operators text[],
operators_to_gtfs_ids JSONB,
operators_to_gtfs_ids hstore,
max_lat double precision,
max_lon double precision,
min_lat double precision,
min_lon double precision
min_lon double precision,
chateau text NOT NULL,
);

CREATE TABLE gtfs.ingested (
Expand Down Expand Up @@ -93,6 +96,7 @@ CREATE TABLE gtfs.agencies (
agency_phone text,
agency_fare_url text,
agency_fare_url_lang hstore,
chateau text NOT NULL,
PRIMARY KEY (static_onestop_id, attempt_id, agency_id)
);

Expand All @@ -115,6 +119,7 @@ CREATE TABLE gtfs.routes (
continuous_pickup smallint,
continuous_drop_off smallint,
shapes_list text[],
chateau text NOT NULL,
PRIMARY KEY (onestop_feed_id, attempt_id, route_id)
);

Expand All @@ -128,6 +133,7 @@ CREATE TABLE IF NOT EXISTS gtfs.shapes (
route_type smallint NOT NULL,
route_label text,
text_color text,
chateau text NOT NULL,
PRIMARY KEY (onestop_feed_id, attempt_id, shape_id)
);

Expand All @@ -147,6 +153,7 @@ CREATE TABLE gtfs.trips (
shape_id text,
wheelchair_accessible int,
bikes_allowed int,
chateau text NOT NULL,
PRIMARY KEY (onestop_feed_id, attempt_id, trip_id)
);

Expand Down Expand Up @@ -177,6 +184,7 @@ CREATE TABLE gtfs.stops (
children_route_types smallint[],
station_feature boolean,
hidden boolean,
chateau text NOT NULL,
location_alias text[],
tts_stop_lang hstore,
PRIMARY KEY (onestop_feed_id, attempt_id, gtfs_id)
Expand All @@ -200,6 +208,7 @@ CREATE TABLE gtfs.stoptimes (
continuous_drop_off smallint,
point GEOMETRY(POINT, 4326) NOT NULL,
route_id text,
chateau text NOT NULL,
PRIMARY KEY (onestop_feed_id, attempt_id, trip_id, stop_sequence)
);

Expand All @@ -208,13 +217,14 @@ CREATE TABLE IF NOT EXISTS {schemaname}.gtfs_errors (
error text NOT NULL,
attempt_id text,
file_hash text,
chateau text NOT NULL,
PRIMARY KEY (onestop_feed_id, attempt_id)
);

CREATE INDEX gtfs_static_geom_idx ON gtfs.shapes USING GIST (linestring);
CREATE INDEX gtfs_static_stops_geom_idx ON gtfs.stops USING GIST (point);
CREATE INDEX gtfs_static_feed_id ON gtfs.shapes (onestop_feed_id);
CREATE INDEX gtfs_static_feed ON gtfs.routes (onestop_feed_id);
CREATE INDEX gtfs_static_feed_id ON gtfs.shapes (chateau);
CREATE INDEX gtfs_static_feed ON gtfs.routes (chateaus);
CREATE INDEX gtfs_static_route_type ON gtfs.routes (route_type);
CREATE INDEX static_hulls ON gtfs.static_feeds USING GIST (hull);

Expand All @@ -229,7 +239,7 @@ CREATE FUNCTION gtfs.busonly(z integer, x integer, y integer)
ST_Transform(linestring, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
chateau, onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
FROM gtfs.shapes
WHERE (linestring && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (route_type = 3 OR route_type = 11 OR route_type = 200)
) as tile WHERE geom IS NOT NULL;
Expand All @@ -249,7 +259,7 @@ CREATE FUNCTION gtfs.notbus(z integer, x integer, y integer)
ST_Transform(linestring, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
chateau, onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
FROM gtfs.shapes
WHERE (linestring && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND route_type != 3 AND route_type != 11
) as tile WHERE geom IS NOT NULL;
Expand All @@ -269,7 +279,7 @@ CREATE FUNCTION gtfs.localrail(z integer, x integer, y integer)
ST_Transform(linestring, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
chateau, onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
FROM gtfs.shapes
WHERE (linestring && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (route_type = 0 OR route_type = 1 OR route_type = 5 OR route_type = 12)
) as tile WHERE geom IS NOT NULL;
Expand All @@ -289,7 +299,7 @@ CREATE FUNCTION gtfs.intercityrail(z integer, x integer, y integer)
ST_Transform(linestring, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
chateau, onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
FROM gtfs.shapes
WHERE (linestring && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (route_type = 2)
) as tile WHERE geom IS NOT NULL;
Expand All @@ -309,7 +319,7 @@ CREATE FUNCTION gtfs.other(z integer, x integer, y integer)
ST_Transform(linestring, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
chateau, onestop_feed_id, shape_id, color, routes, route_type, route_label, text_color
FROM gtfs.shapes
WHERE (linestring && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (route_type = 4 OR route_type = 6 OR route_type = 7)
) as tile WHERE geom IS NOT NULL;
Expand All @@ -329,7 +339,7 @@ CREATE FUNCTION gtfs.stationfeatures(z integer, x integer, y integer)
ST_Transform(point, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types
chateau, onestop_feed_id, name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types
FROM gtfs.stops
WHERE (point && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (location_type=2 OR location_type=3 OR location_type=4)
) as tile WHERE geom IS NOT NULL;
Expand All @@ -349,7 +359,7 @@ CREATE FUNCTION gtfs.busstops(z integer, x integer, y integer)
ST_Transform(point, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, REPLACE (name, 'Station','') as name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types, hidden
chateau, onestop_feed_id, REPLACE (name, 'Station','') as name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types, hidden
FROM gtfs.stops
WHERE (point && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (ARRAY[3,11,200,1700,1500,1702]::smallint[] && route_types::smallint[] OR ARRAY[3,11,200,1700,1500,1702]::smallint[] && children_route_types::smallint[]) AND hidden = false
) as tile WHERE geom IS NOT NULL;
Expand All @@ -369,7 +379,7 @@ CREATE FUNCTION gtfs.railstops(z integer, x integer, y integer)
ST_Transform(point, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, REPLACE (name, 'Station','') as name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types, hidden
chateau, onestop_feed_id, REPLACE (name, 'Station','') as name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types, hidden
FROM gtfs.stops
WHERE (point && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (ARRAY[0,1,2,5,12]::smallint[] && route_types::smallint[] OR ARRAY[0,1,2,5,12]::smallint[] && children_route_types::smallint[]) AND hidden = false
) as tile WHERE geom IS NOT NULL;
Expand All @@ -389,7 +399,7 @@ CREATE FUNCTION gtfs.otherstops(z integer, x integer, y integer)
ST_Transform(point, 3857),
ST_TileEnvelope(z, x, y),
4096, 64, true) AS geom,
onestop_feed_id, REPLACE (name, 'Station','') as name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types
chateau, onestop_feed_id, REPLACE (name, 'Station','') as name, displayname, code, gtfs_desc, location_type, parent_station, zone_id, url, timezone, wheelchair_boarding, level_id, platform_code, routes, route_types, children_ids, children_route_types
FROM gtfs.stops
WHERE (point && ST_Transform(ST_TileEnvelope(z, x, y), 4326)) AND (ARRAY[4,6,7]::smallint[] && route_types::smallint[] OR ARRAY[4,6,7]::smallint[] && children_route_types::smallint[])
) as tile WHERE geom IS NOT NULL;
Expand Down
13 changes: 13 additions & 0 deletions src/http-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ pub async fn microtime(req: HttpRequest) -> impl Responder {
))
}

#[actix_web::get("/ntpns")]
pub async fn ntpns(req: HttpRequest) -> impl Responder {
HttpResponse::Ok()
.insert_header(("Content-Type", "text/plain"))
.body(format!(
"{}",
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_micros()
))
}

#[actix_web::get("/amtrakproxy")]
pub async fn amtrakproxy(req: HttpRequest) -> impl Responder {
let raw_data =
Expand Down

0 comments on commit ae6d84f

Please sign in to comment.