Skip to content

Commit

Permalink
Update project layout
Browse files Browse the repository at this point in the history
  • Loading branch information
fulldecent committed Mar 31, 2017
1 parent f70aa2c commit 3854c4c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 33 deletions.
1 change: 0 additions & 1 deletion Getting GTFS Data from SEPTA/.gitignore

This file was deleted.

24 changes: 0 additions & 24 deletions Getting GTFS Data from SEPTA/README.md

This file was deleted.

52 changes: 52 additions & 0 deletions website/databases/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Database Notes

## TrainView Schema

```sql lite
CREATE TABLE trainview (
day date NOT NULL,
train varchar(4) NOT NULL,
time time NOT NULL,
lateness smallint(6) NOT NULL,
PRIMARY KEY (day,train,time)
);
CREATE INDEX train ON trainview (train,time);
CREATE INDEX trains ON trainview (train);
```

Note: We store data with separate `day` and `time`. If `time` is before `03:00` then this represents a time during `day` plus one day. This is because service calculations reset at 3am.

## Schedule Schema

See schema definition in `sqliteGTFSImport.txt`.

## Load SEPTA GTFS Data

1. Set up

```sh
rm -rf tmp
mkdir tmp
cd tmp
```

2. Download the release from https://github.com/septadev/GTFS/releases into there

3. Extract

```sh
unzip gtfs_public.zip
unzip google_rail.zip
cd ..
```

4. Load this into a SQLite database

```sh
rm -f septaSchedules.db
sqlite3 septaSchedules.db < sqliteGTFSImport.txt
```

5. Copy this database into your `databases` folder


Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
--

CREATE TABLE agency (
agency_id TEXT,
agency_id TEXT PRIMARY KEY,
agency_name TEXT,
agency_url TEXT,
agency_timezone TEXT,
agency_lang TEXT
);
CREATE TABLE calendar (
service_id TEXT,
service_id TEXT PRIMARY KEY,
monday NUMERIC,
tuesday NUMERIC,
wednesday NUMERIC,
Expand All @@ -30,10 +30,11 @@ CREATE TABLE calendar (
CREATE TABLE calendar_dates (
service_id TEXT,
date NUMERIC,
exception_type NUMERIC
exception_type NUMERIC,
PRIMARY KEY (service_id, date)
);
CREATE TABLE routes (
route_id TEXT,
route_id TEXT PRIMARY KEY,
agency_id TEXT,
route_short_name TEXT,
route_long_name TEXT,
Expand All @@ -47,10 +48,12 @@ CREATE TABLE shapes (
shape_id TEXT,
shape_pt_lat REAL,
shape_pt_lon REAL,
shape_pt_sequence NUMERIC)
shape_pt_sequence NUMERIC,
PRIMARY KEY (shape_id, shape_pt_sequence)
)
;
CREATE TABLE stops (
stop_id TEXT,
stop_id TEXT PRIMARY KEY,
stop_name TEXT,
stop_desc TEXT,
stop_lat REAL,
Expand All @@ -65,12 +68,13 @@ CREATE TABLE stop_times (
stop_id TEXT,
stop_sequence NUMERIC,
pickup_type NUMERIC,
drop_off_type NUMERIC
drop_off_type NUMERIC,
PRIMARY KEY (trip_id, stop_id)
);
CREATE TABLE trips (
route_id TEXT,
service_id TEXT,
trip_id TEXT,
trip_id TEXT PRIMARY KEY,
trip_headsign TEXT,
direction_id NUMERIC,
block_id TEXT,
Expand Down

0 comments on commit 3854c4c

Please sign in to comment.