Skip to content
Open

Main #77

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
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"files.autoSave": "afterDelay",
"screencastMode.onlyKeyboardShortcuts": true,
"terminal.integrated.fontSize": 18,
"workbench.activityBar.visible": true,
"workbench.colorTheme": "Visual Studio Dark",
"workbench.fontAliasing": "antialiased",
"workbench.statusBar.visible": true
Expand Down
Binary file modified data/nyc_parking_violations.db
Binary file not shown.
Binary file added data/nyc_parking_violations2.db
Binary file not shown.
Binary file modified data/prod_nyc_parking_violations.db
Binary file not shown.

This file was deleted.

23 changes: 0 additions & 23 deletions nyc_parking_violations/models/bronze/bronze_parking_violations.sql

This file was deleted.

4 changes: 0 additions & 4 deletions nyc_parking_violations/models/example/ref_model.sql

This file was deleted.

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_violations2/.user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id: 23096e09-b919-420a-854b-199a5ab84b4f
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'nyc_parking_violations'
name: 'nyc_parking_violations2'
version: '1.0.0'
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: 'nyc_parking_violations'
profile: 'nyc_parking_violations2'

# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
Expand All @@ -31,7 +31,7 @@ clean-targets: # directories to be removed by `dbt clean`
# directory as views. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
nyc_parking_violations:
nyc_parking_violations2:
# Config indicated by + and applies to all files under models/example/
example:
+materialized: ephemeral
Expand All @@ -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
@@ -0,0 +1,7 @@
SELECT
code AS violation_code,
definition,
manhattan_96th_st_below,
all_other_areas
FROM
parking_violation_codes
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ The total number of tickets issued for a specific violation code.

{% docs total_revenue_usd %}
The total revenue accumulated from tickets, based on the violation code. This sum is represented in USD.
{% enddocs %}
{% enddocs %}
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ models:
- name: registration_state
description: '{{ doc("registration_state") }}'
- name: ticket_count
description: '{{ doc("ticket_count") }}'
description: '{{ doc("ticket_count") }}'
4 changes: 4 additions & 0 deletions nyc_parking_violations2/models/example/ref_model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
COUNT(*)
FROM
{{ref('first_model')}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nyc_parking_violations:
nyc_parking_violations2:
outputs:
dev:
type: duckdb
Expand All @@ -8,5 +8,5 @@ nyc_parking_violations:
# 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'
path: '../data/prod_nyc_parking_violations.db'
target: dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ FROM
GROUP BY
violation_code
HAVING
NOT(total_revenue_usd >= 1)
NOT(total_revenue_usd >= 1)
180 changes: 178 additions & 2 deletions run_sql_queries_here.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,203 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import duckdb\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>violation_code</th>\n",
" <th>total_revenue_usd</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>41</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" violation_code total_revenue_usd\n",
"0 41 0.0"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sql_query = '''\n",
"select * from \"nyc_parking_violations\".\"main_dbt_test__audit\".\"violation_codes_revenue\"\n",
"'''\n",
"\n",
"with duckdb.connect('data/nyc_parking_violations.db') as con:\n",
" display(con.sql(sql_query).df())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sql_query_import_1 = '''\n",
"CREATE OR REPLACE TABLE parking_violations_code AS \n",
"SELECT *\n",
"FROM read_csv_auto(\n",
" 'data/dof_parking_violation_codes.csv',\n",
" normalize_names=True\n",
" )\n",
"'''\n",
"\n",
"sql_query_import_2 = '''\n",
"CREATE OR REPLACE TABLE parking_violations_2023 AS \n",
"SELECT *\n",
"FROM read_csv_auto(\n",
" 'data/parking_violations_issued_fiscal_year_2023_sample.csv',\n",
" normalize_names=True\n",
" )\n",
"'''\n",
"\n",
"with duckdb.connect('data/prod_nyc_parking_violations2.db') as con:\n",
" con.sql(sql_query_import_1)\n",
" con.sql(sql_query_import_2)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>name</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>bronze_parking_violation_codes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>bronze_parking_violations</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>gold_ticket_metrics</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>gold_vehicles_metrics</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>parking_violation_codes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>parking_violations_2023</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>parking_violations_code</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>silver_violation_tickets</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>silver_violation_vehicles</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" name\n",
"0 bronze_parking_violation_codes\n",
"1 bronze_parking_violations\n",
"2 gold_ticket_metrics\n",
"3 gold_vehicles_metrics\n",
"4 parking_violation_codes\n",
"5 parking_violations_2023\n",
"6 parking_violations_code\n",
"7 silver_violation_tickets\n",
"8 silver_violation_vehicles"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"sql_query = '''\n",
"show tables\n",
"'''\n",
"\n",
"with duckdb.connect('data/nyc_parking_violations.db') as con:\n",
"with duckdb.connect('data/prod_nyc_parking_violations.db') as con:\n",
" display(con.sql(sql_query).df())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down