Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __scripts__/bootstrap_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions __scripts__/create_trip_tables.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- Active: 1770507353299@@localhost@5432@assignment1
create schema if not exists indego;

drop table if exists indego.trips_2021_q3;
Expand All @@ -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 (
Expand All @@ -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;
9 changes: 9 additions & 0 deletions __scripts__/script
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 7 additions & 13 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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" ]
11 changes: 10 additions & 1 deletion query02.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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


/*
Expand Down
2 changes: 2 additions & 0 deletions query03.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*/

-- Enter your SQL query here
select round(avg(duration), 2) as avg_duration
from indego.trips_2021_q3
2 changes: 2 additions & 0 deletions query04.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*/

-- Enter your SQL query here
select round(avg(duration), 2) as avg_duration
from indego.trips_2022_q3
6 changes: 6 additions & 0 deletions query05.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions query06.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions query07.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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


/*
Expand Down
13 changes: 13 additions & 0 deletions query08.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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


/*
Expand Down
10 changes: 10 additions & 0 deletions query09.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions query10.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions query11.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions query12.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions query13.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions query14.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions script_postgis.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION postgis;
Loading