Skip to content

Main #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Main #61

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 .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
- name: Copy To Branches Action
uses: planetoftheweb/[email protected]
env:
key: main
key: main
7 changes: 3 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"editor.cursorBlinking": "solid",
"editor.fontFamily": "ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace",
"editor.fontLigatures": false,
"editor.fontSize": 22,
"editor.fontSize": 14,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.lineNumbers": "on",
Expand All @@ -16,9 +16,8 @@
"explorer.openEditors.visible": 0,
"files.autoSave": "afterDelay",
"screencastMode.onlyKeyboardShortcuts": true,
"terminal.integrated.fontSize": 18,
"workbench.activityBar.visible": true,
"terminal.integrated.fontSize": 14,
"workbench.colorTheme": "Visual Studio Dark",
"workbench.fontAliasing": "antialiased",
"workbench.statusBar.visible": true
}
}
Binary file modified data/nyc_parking_violations.db
Binary file not shown.
Binary file modified data/prod_nyc_parking_violations.db
Binary file not shown.
2 changes: 1 addition & 1 deletion nyc_parking_violations/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.user.yml

target/
dbt_packages/
logs/
1 change: 1 addition & 0 deletions nyc_parking_violations/.user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id: 334930ae-2627-4a6c-af90-c9826c0f4e5d
2 changes: 1 addition & 1 deletion nyc_parking_violations/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ models:
gold:
+materialized: table
tests:
+store_failures: true
+store_failures: true
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
SELECT
code AS violation_code,
definition,
manhattan_96th_st_below,
all_other_areas
FROM
parking_violation_codes
SELECT code AS violation_code,
definition, manhattan_96th_st_below, all_other_areas
FROM parking_violation_codes
31 changes: 8 additions & 23 deletions nyc_parking_violations/models/bronze/bronze_parking_violations.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
SELECT
summons_number,
registration_state,
plate_type,
issue_date,
violation_code,
vehicle_body_type,
vehicle_make,
issuing_agency,
vehicle_expiration_date,
violation_location,
violation_precinct,
issuer_precinct,
issuer_code,
issuer_command,
issuer_squad,
violation_time,
violation_county,
violation_legal_code,
vehicle_color,
vehicle_year,
FROM
parking_violations_2023
SELECT summons_number, registration_state, plate_type, issue_date, violation_code, vehicle_body_type,
vehicle_make, issuing_agency, vehicle_expiration_date, violation_location, violation_precinct,
issuer_precinct, issuer_code, issuer_command, issuer_squad, violation_time, time_first_observed,
violation_county, violation_in_front_of_or_opposite, date_first_observed, law_section, sub_division,
violation_legal_code, days_parking_in_effect, from_hours_in_effect, to_hours_in_effect, vehicle_color,
unregistered_vehicle, vehicle_year, meter_number, feet_from_curb, no_standing_or_stopping_violation,
hydrant_violation, double_parking_violation
FROM parking_violations_2023
3 changes: 2 additions & 1 deletion nyc_parking_violations/models/example/first_model.sql
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SELECT * FROM parking_violation_codes
SELECT *
FROM parking_violation_codes
6 changes: 2 additions & 4 deletions nyc_parking_violations/models/example/ref_model.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
SELECT
COUNT(*)
FROM
{{ref('first_model')}}
SELECT COUNT(*)
FROM {{ref('first_model')}}
12 changes: 4 additions & 8 deletions nyc_parking_violations/models/gold/gold_ticket_metrics.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
SELECT
violation_code,
SELECT violation_code,
COUNT(summons_number) AS ticket_count,
SUM(fee_usd) AS total_revenue_usd
FROM
{{ref('silver_violation_tickets')}}
GROUP BY
violation_code
ORDER BY
total_revenue_usd DESC
FROM {{ref('silver_violation_tickets')}}
GROUP BY violation_code
ORDER BY total_revenue_usd DESC
17 changes: 6 additions & 11 deletions nyc_parking_violations/models/gold/gold_vehicles_metrics.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
SELECT
registration_state,
COUNT(summons_number) AS ticket_count,
FROM
{{ref('silver_violation_vehicles')}}
WHERE
registration_state != 'NY'
GROUP BY
registration_state
ORDER BY
ticket_count DESC
SELECT registration_state,
COUNT(summons_number) AS ticket_count
FROM {{ref('silver_violation_vehicles')}}
WHERE registration_state != 'NY'
GROUP BY registration_state
ORDER BY ticket_count DESC
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
WITH manhattan_violation_codes AS (
SELECT
violation_code,
definition,
WITH manhattan_violation_codes
AS (
SELECT violation_code, definition,
TRUE AS is_manhattan_96th_st_below,
manhattan_96th_st_below AS fee_usd,
FROM
{{ref('bronze_parking_violation_codes')}}
manhattan_96th_st_below AS fee_usd
FROM {{ref('bronze_parking_violation_codes')}}
),

all_other_violation_codes AS (
SELECT
violation_code,
definition,
all_other_violation_codes
AS (
SELECT violation_code, definition,
FALSE AS is_manhattan_96th_st_below,
all_other_areas AS fee_usd,
FROM
{{ref('bronze_parking_violation_codes')}}
all_other_areas AS fee_usd
FROM {{ref('bronze_parking_violation_codes')}}
)

SELECT * FROM manhattan_violation_codes
SELECT *
FROM manhattan_violation_codes
UNION ALL
SELECT * FROM all_other_violation_codes
ORDER BY violation_code ASC
SELECT *
FROM all_other_violation_codes
ORDER BY violation_code
35 changes: 8 additions & 27 deletions nyc_parking_violations/models/silver/silver_parking_violations.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
SELECT
summons_number,
registration_state,
plate_type,
issue_date,
violation_code,
vehicle_body_type,
vehicle_make,
issuing_agency,
vehicle_expiration_date,
violation_location,
violation_precinct,
issuer_precinct,
issuer_code,
issuer_command,
issuer_squad,
violation_time,
violation_county,
violation_legal_code,
vehicle_color,
vehicle_year,
CASE WHEN
violation_county == 'MN'
THEN TRUE
SELECT summons_number, registration_state, plate_type, issue_date, violation_code, vehicle_body_type,
vehicle_make, issuing_agency, vehicle_expiration_date, violation_location, violation_precinct,
issuer_precinct, issuer_code, issuer_command, issuer_squad, violation_time, violation_county,
violation_legal_code, vehicle_color, vehicle_year,
CASE
WHEN violation_county == 'MN' THEN TRUE
ELSE FALSE
END AS is_manhattan_96th_st_below
FROM
{{ref('bronze_parking_violations')}}
END AS is_manhattan_96th_st_below
FROM {{ref('bronze_parking_violations')}}
31 changes: 9 additions & 22 deletions nyc_parking_violations/models/silver/silver_violation_tickets.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
SELECT
violations.summons_number,
violations.issue_date,
violations.violation_code,
violations.is_manhattan_96th_st_below,
violations.issuing_agency,
violations.violation_location,
violations.violation_precinct,
violations.issuer_precinct,
violations.issuer_code,
violations.issuer_command,
violations.issuer_squad,
violations.violation_time,
violations.violation_county,
violations.violation_legal_code,
codes.fee_usd
FROM
{{ref('silver_parking_violations')}} AS violations
LEFT JOIN
{{ref('silver_parking_violation_codes')}} AS codes ON
violations.violation_code = codes.violation_code AND
violations.is_manhattan_96th_st_below = codes.is_manhattan_96th_st_below
SELECT violations.summons_number, violations.issue_date, violations.violation_code,
violations.is_manhattan_96th_st_below, violations.issuing_agency, violations.violation_location,
violations.violation_precinct, violations.issuer_precinct, violations.issuer_code,
violations.issuer_command, violations.issuer_squad, violations.violation_time,
violations.violation_county, violations.violation_legal_code, codes.fee_usd
FROM {{ref('silver_parking_violations')}} AS violations
LEFT JOIN {{ref('silver_parking_violation_codes')}} AS codes ON
codes.violation_code = violations.violation_code
AND codes.is_manhattan_96th_st_below = violations.is_manhattan_96th_st_below
14 changes: 3 additions & 11 deletions nyc_parking_violations/models/silver/silver_violation_vehicles.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
SELECT
summons_number,
registration_state,
plate_type,
vehicle_body_type,
vehicle_make,
vehicle_expiration_date,
vehicle_color,
vehicle_year
FROM
{{ref('silver_parking_violations')}}
SELECT summons_number, registration_state, plate_type, vehicle_body_type,
vehicle_make, vehicle_expiration_date, vehicle_color, vehicle_year
FROM {{ref('silver_parking_violations')}}
18 changes: 9 additions & 9 deletions nyc_parking_violations/profiles.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
nyc_parking_violations:
outputs:
dev:
type: duckdb
path: '../data/nyc_parking_violations.db'
prod:
type: duckdb
# note that path is slightly different as GitHub actions
# start in the root directory and not in the
# nyc_parking_violations directory
path: './data/prod_nyc_parking_violations.db'
dev:
type: duckdb
path: '../data/nyc_parking_violations.db'
prod:
type: duckdb
# note that path is slightly different as GitHub actions
# start in the root directory and not in the
# nyc_parking_violations directory
path: '../data/prod_nyc_parking_violations.db'
target: dev
8 changes: 3 additions & 5 deletions nyc_parking_violations/tests/generic/generic_not_null.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-- source: https://docs.getdbt.com/guides/best-practices/writing-custom-generic-tests#generic-tests-with-default-config-values
{% test generic_not_null(model, column_name) %}

select *
from {{ model }}
where {{ column_name }} is null

SELECT *
FROM {{model}}
WHERE {{column_name}} IS NULL
{% endtest %}
15 changes: 5 additions & 10 deletions nyc_parking_violations/tests/violation_codes_revenue.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{{ config(severity = 'warn') }}

SELECT
violation_code,
{{config(severity = 'warn')}}
SELECT violation_code,
SUM(fee_usd) AS total_revenue_usd
FROM
{{ref('silver_parking_violation_codes')}}
GROUP BY
violation_code
HAVING
NOT(total_revenue_usd >= 1)
FROM {{ref('silver_parking_violation_codes')}}
GROUP BY violation_code
HAVING NOT (total_revenue_usd >= 1)
Loading