diff --git a/__scripts__/bootstrap_data.sh b/__scripts__/bootstrap_data.sh index 43526e1..77d0c0a 100755 --- a/__scripts__/bootstrap_data.sh +++ b/__scripts__/bootstrap_data.sh @@ -4,7 +4,7 @@ set -e set -x SCRIPTDIR=$(readlink -f $(dirname $0)) -DATADIR=$(readlink -f $(dirname $0)/../__data__) +DATADIR=$(readlink -f $(dirname $0)/__data__) mkdir -p ${DATADIR} # Download and unzip data (if not already downloaded) diff --git a/__scripts__/create_trip_tables.sql b/__scripts__/create_trip_tables.sql index 0d1317e..4d575c4 100644 --- a/__scripts__/create_trip_tables.sql +++ b/__scripts__/create_trip_tables.sql @@ -1,3 +1,4 @@ +-- Active: 1770507353299@@localhost@5432@assignment1 create schema if not exists indego; drop table if exists indego.trips_2021_q3; @@ -20,6 +21,12 @@ create table indego.trips_2021_q3 ( bike_type text ); +set DateStyle = 'MDY'; +copy indego.trips_2021_q3 +from 'F:/Graduate School Stuff/Semester 4/Deep Learning/assignment01/__data__/indego-trips-2021-q3.csv' +with (format csv, header true); + + drop table if exists indego.trips_2022_q3; create table indego.trips_2022_q3 ( @@ -40,4 +47,9 @@ create table indego.trips_2022_q3 ( bike_type text ); +set DateStyle = 'MDY'; +copy indego.trips_2022_q3 +from 'F:/Graduate School Stuff/Semester 4/Deep Learning/assignment01/__data__/indego-trips-2022-q3.csv' +with (format csv, header true); + create extension if not exists postgis; diff --git a/__scripts__/script b/__scripts__/script new file mode 100644 index 0000000..48e062a --- /dev/null +++ b/__scripts__/script @@ -0,0 +1,9 @@ +ogr2ogr \ +-f "PostgreSQL" \ +-nln "stations_geo" \ +-lco "SCHEMA=indego" \ +-lco "GEOM_TYPE=geography" \ +-lco "GEOMETRY_NAME=geog" \ +-lco "OVERWRITE=yes" \ +PG:"host=localhost port=5432 dbname=assignment1 user=postgres password='P123i,./g456'" \ +"/f/Graduate School Stuff/Semester 4/Deep Learning/assignment01/__data__/station_status.json" \ No newline at end of file diff --git a/compose.yml b/compose.yml index 9837ac1..3711944 100644 --- a/compose.yml +++ b/compose.yml @@ -2,14 +2,14 @@ services: db: image: postgis/postgis + ports: + - "5432:5432" environment: - POSTGRES_PASSWORD: postgres + POSTGRES_PASSWORD: P123i,./g456 + POSTGRES_DB: assignment1 healthcheck: # test: ["CMD-SHELL", "pg_isready -U postgres"] - test: [ - "CMD-SHELL", - 'psql -U postgres -d postgres -c "SELECT ST_Buffer( ST_SetSRID(''POINT(0 0)''::GEOMETRY, 4326), 1) AS geom ;"', - ] + test: [ "CMD-SHELL", 'psql -U postgres -d postgres -c "SELECT ST_Buffer( ST_SetSRID(''POINT(0 0)''::GEOMETRY, 4326), 1) AS geom ;"' ] interval: 5s timeout: 5s retries: 5 @@ -18,10 +18,7 @@ services: image: ghcr.io/weitzman-musa-geocloud/assignment01:main volumes: - .:/assignment01 - command: [ - "bash", "-c", - "cd /assignment01 && __entrypoints__/run_linter.sh -- ." - ] + command: [ "bash", "-c", "cd /assignment01 && __entrypoints__/run_linter.sh -- ." ] run-tests: image: ghcr.io/weitzman-musa-geocloud/assignment01:main @@ -36,7 +33,4 @@ services: POSTGRES_NAME: postgres volumes: - .:/assignment01 - command: [ - "bash", "-c", - "cd /assignment01 && npm install > /dev/null && __entrypoints__/run_tests.sh -- --rootDir /assignment01" - ] + command: [ "bash", "-c", "cd /assignment01 && npm install > /dev/null && __entrypoints__/run_tests.sh -- --rootDir /assignment01" ] diff --git a/query02.sql b/query02.sql index 2b7ad18..1948285 100644 --- a/query02.sql +++ b/query02.sql @@ -10,7 +10,16 @@ */ -- Enter your SQL query here - +select + round( + (count_2022 - count_2021) * 100.0 / count_2021, + 2 + )::text || '%' as perc_change +from ( + select + (select count(*) from indego.trips_2021_q3) as count_2021, + (select count(*) from indego.trips_2022_q3) as count_2022 +) as counts /* diff --git a/query03.sql b/query03.sql index 83e9e36..5babeef 100644 --- a/query03.sql +++ b/query03.sql @@ -6,3 +6,5 @@ */ -- Enter your SQL query here +select round(avg(duration), 2) as avg_duration +from indego.trips_2021_q3 diff --git a/query04.sql b/query04.sql index 8223f17..9f2996c 100644 --- a/query04.sql +++ b/query04.sql @@ -6,3 +6,5 @@ */ -- Enter your SQL query here +select round(avg(duration), 2) as avg_duration +from indego.trips_2022_q3 diff --git a/query05.sql b/query05.sql index fba8f23..40de43b 100644 --- a/query05.sql +++ b/query05.sql @@ -5,3 +5,9 @@ */ -- Enter your SQL query here +select max(duration) as max_duration +from ( + select duration from indego.trips_2021_q3 + union all + select duration from indego.trips_2022_q3 +) as all_trips diff --git a/query06.sql b/query06.sql index 1cb254b..ddbfd5b 100644 --- a/query06.sql +++ b/query06.sql @@ -7,3 +7,20 @@ */ -- Enter your SQL query here +select + extract(year from start_time)::integer as trip_year, + extract(quarter from start_time)::integer as trip_quarter, + count(*) as num_trips +from indego.trips_2021_q3 +where duration < 10 +group by trip_year, trip_quarter + +union all + +select + extract(year from start_time)::integer as trip_year, + extract(quarter from start_time)::integer as trip_quarter, + count(*) as num_trips +from indego.trips_2022_q3 +where duration < 10 +group by trip_year, trip_quarter diff --git a/query07.sql b/query07.sql index 782eda5..5f37192 100644 --- a/query07.sql +++ b/query07.sql @@ -6,7 +6,23 @@ */ -- Enter your SQL query here +select + extract(year from start_time)::integer as trip_year, + extract(quarter from start_time)::integer as trip_quarter, + count(*) as num_trips +from indego.trips_2021_q3 +where start_time::date != end_time::date +group by trip_year, trip_quarter +union all + +select + extract(year from start_time)::integer as trip_year, + extract(quarter from start_time)::integer as trip_quarter, + count(*) as num_trips +from indego.trips_2022_q3 +where start_time::date != end_time::date +group by trip_year, trip_quarter /* diff --git a/query08.sql b/query08.sql index f35a927..294a707 100644 --- a/query08.sql +++ b/query08.sql @@ -9,6 +9,19 @@ */ -- Enter your SQL query here +select + start_station as station_id, + st_point(start_lon, start_lat)::geography as stations_geog, + count(*) as num_trips +from ( + select * from indego.trips_2021_q3 + union all + select * from indego.trips_2022_q3 +) as all_trips +where extract(hour from start_time) between 7 and 9 +group by start_station, start_lon, start_lat +order by num_trips desc +limit 5 /* diff --git a/query09.sql b/query09.sql index cc1d88d..6d5f51b 100644 --- a/query09.sql +++ b/query09.sql @@ -7,3 +7,13 @@ */ -- Enter your SQL query here +select + passholder_type, + count(*) as num_trips +from ( + select passholder_type from indego.trips_2021_q3 + union all + select passholder_type from indego.trips_2022_q3 +) as all_trips +group by passholder_type +order by num_trips desc diff --git a/query10.sql b/query10.sql index 56cd844..ec497b9 100644 --- a/query10.sql +++ b/query10.sql @@ -8,3 +8,9 @@ */ -- Enter your SQL query here +select + id as station_id, + geog as station_geog, + round(st_distance(geog, st_point(-75.192584, 39.952415)::geography) / 50) * 50 as distance +from indego.stations_geo +order by station_id diff --git a/query11.sql b/query11.sql index 36f6b65..86b1101 100644 --- a/query11.sql +++ b/query11.sql @@ -5,3 +5,5 @@ */ -- Enter your SQL query here +select round(avg(st_distance(geog, st_point(-75.192584, 39.952415)::geography)) / 1000) as avg_distance_km +from indego.stations_geo diff --git a/query12.sql b/query12.sql index 448ca09..bb81622 100644 --- a/query12.sql +++ b/query12.sql @@ -6,3 +6,6 @@ */ -- Enter your SQL query here +select count(*) as num_stations +from indego.stations_geo +where st_distance(geog, st_point(-75.192584, 39.952415)::geography) <= 1000 diff --git a/query13.sql b/query13.sql index ac9e192..091e8ba 100644 --- a/query13.sql +++ b/query13.sql @@ -7,3 +7,10 @@ */ -- Enter your SQL query here +select + id as station_id, + name as station_name, + round(st_distance(geog, st_point(-75.192584, 39.952415)::geography) / 50) * 50 as distance +from indego.stations_geo +order by distance desc +limit 1 diff --git a/query14.sql b/query14.sql index e039693..7b9b011 100644 --- a/query14.sql +++ b/query14.sql @@ -7,3 +7,10 @@ */ -- Enter your SQL query here +select + id as station_id, + name as station_name, + round(st_distance(geog, st_point(-75.192584, 39.952415)::geography) / 50) * 50 as distance +from indego.stations_geo +order by distance asc +limit 1 diff --git a/script_postgis.sql b/script_postgis.sql new file mode 100644 index 0000000..8d9700b --- /dev/null +++ b/script_postgis.sql @@ -0,0 +1 @@ +CREATE EXTENSION postgis;