Lab 03 · City of Calgary open data
Where Calgary is building
Every building permit since 2015. How many homes were permitted, how long it took, and where.
- New homes permittedin 2025
- 22,493
- Of new homes were apartmentsby units permitted in 2025
- 49.6%
- Median wait for a new-home permitapplications in 2025
- 14 days
01
Dashboard
Source: City of Calgary Open Data, Building Permits (c2es-76ed). Applications since 2015.
02
Ask the permit data
Ask a question in plain English. Claude writes the SQL and your browser runs it. See the guardrails.
03
Why it matters
Anyone can generate a dashboard now. The value is knowing what to build, and what it’s for.
In a sales or marketing team
The same techniques, applied to revenue data.
CRM pipeline reports that catch deals that changed stage, as well as new deals.
Bad lead or campaign rows get flagged to an owner instead of quietly skewing a report.
Sales and marketing agree on what “qualified lead” means before anyone builds on it.
Decisions and trade-offs
What I chose, why, and what it cost.
Catch updates to old permits as well as new ones
- Permits change status over time, so each refresh looks for anything that changed.
- Each refresh pulls more data. Correct counts are worth it.
Keep a copy of the data with the site
- The site never breaks because the City’s data service is down.
- Storage grows a little each week. I’d move it to cloud storage if it got large.
Warnings never block a refresh. Errors always do.
- Known data quirks stay visible without holding back fresh data.
- Someone has to read the warnings, so the page shows them to everyone.
04
Pipeline
Every number above comes from this pipeline: dbt models in raw, cleaned and business-ready layers, with tests and a contract. An Airflow DAG runs it weekly. You can run it in your browser too.
- Last production run
- 2026-11-30
- Trigger
- Airflow on GitHub Actions
- Duration
- 2.0 s
- Rows extracted
- 239,059
- Tests
- 9 pass · 3 warn
Lineage
Click a node for its SQL, schema and row counts. Run pipeline live pulls permits changed since the snapshot from data.calgary.ca. Changes stay in this tab.
1 Source
2 Bronze
3 Silver
4 Gold
5 Checks
6 Browser
stg_permitsdbt/models/permits/stg_permits.sql
239,059 rows · built in 873 ms · last production run
Typed, renamed and deduplicated. Zero coordinates become NULL. One row per permit, latest version wins.
select
permitnum as permit_id,
cast(cast(applieddate as timestamp) as date) as applied_date,
cast(try_cast(issueddate as timestamp) as date) as issued_date,
cast(try_cast(completeddate as timestamp) as date) as completed_date,
statuscurrent as status,
permittypemapped as permit_type,
permitclassmapped as permit_class,
permitclassgroup as class_group,
workclassgroup as work_group,
coalesce(try_cast(housingunits as integer), 0) as housing_units,
try_cast(estprojectcost as double) as est_cost,
try_cast(totalsqft as double) as sqft,
communityname as community,
nullif(round(try_cast(latitude as double), 4), 0) as lat,
nullif(round(try_cast(longitude as double), 4), 0) as lon,
try_cast(source_updated_at as timestamp) as updated_at
from {{ ref('raw_permits') }}
where permitnum is not null
qualify row_number() over (partition by permitnum order by source_updated_at desc) = 1| Column | Type | Null % |
|---|---|---|
| permit_id | VARCHAR | 0 |
| applied_date | DATE | 0 |
| issued_date | DATE | 6.0 |
| completed_date | DATE | 8.1 |
| status | VARCHAR | 0 |
| permit_type | VARCHAR | 0 |
| permit_class | VARCHAR | 0 |
| class_group | VARCHAR | 0 |
| work_group | VARCHAR | 0 |
| housing_units | INTEGER | 0 |
| est_cost | DOUBLE | 10.3 |
| sqft | DOUBLE | 76.0 |
| community | VARCHAR | 0 |
| lat | DOUBLE | 0.1 |
| lon | DOUBLE | 0.1 |
| updated_at | TIMESTAMP | 0 |
Data quality tests
From the last production run. Warnings are real issues in the source, flagged rather than hidden.
✓ passpermit_class is a known valueaccepted_values · permits0
Catches a new category upstream before it silently drops out of charts. severity: error
select count(*) as failures from ( with all_values as ( select permit_class as value_field, count(*) as n_records from main.permits group by permit_class ) select * from all_values where value_field not in ( 'Residential','Non-Residential','Unspecified' ) ) dbt_test✓ passwork_group is a known valueaccepted_values · permits0
Same guard for the work type. severity: error
select count(*) as failures from ( with all_values as ( select work_group as value_field, count(*) as n_records from main.permits group by work_group ) select * from all_values where value_field not in ( 'New','Improvement','Demolition','Unspecified' ) ) dbt_test! warnCompleted on or after issuedexpression_is_true · permits28 rows
Upstream date entry issue. Flagged so time-to-complete metrics can exclude them. severity: warn
select count(*) as failures from ( select * from main.permits where not (completed_date is null or issued_date is null or completed_date >= issued_date) ) dbt_test✓ passhousing_units is between 0 and 2,000expression_is_true · permits0
A negative or huge unit count is a data entry error, not a building. severity: error
select count(*) as failures from ( select * from main.permits where not (housing_units between 0 and 2000) ) dbt_test! warnIssued on or after appliedexpression_is_true · permits1 rows
A permit can't be issued before it's applied for. Flagged, not dropped. severity: warn
select count(*) as failures from ( select * from main.permits where not (issued_date is null or issued_date >= applied_date) ) dbt_test✓ passCoordinates fall inside Calgaryexpression_is_true · permits0
Swapped or mistyped coordinates would put permits in another city. severity: error
select count(*) as failures from ( select * from main.permits where not (lat is null or (lat between 50.80 and 51.25 and lon between -114.35 and -113.80)) ) dbt_test✓ passapplied_date is never nullnot_null · permits0
Every permit has an application date. severity: error
select count(*) as failures from ( select applied_date from main.permits where applied_date is null ) dbt_test! warnCoordinates are presentnot_null · permits158 rows
Some permits have no location. They stay in totals but can't be mapped. severity: warn
select count(*) as failures from ( select lat from main.permits where lat is null ) dbt_test✓ passpermit_id is never nullnot_null · permits0
Every row is addressable. severity: error
select count(*) as failures from ( select permit_id from main.permits where permit_id is null ) dbt_test✓ passSource updated in the last 8 daysrecency · permits0
If the City stops publishing, the refresh fails instead of serving stale data quietly. severity: error
select count(*) as failures from ( select max(updated_at) as latest from main.permits having max(updated_at) < DATE '2026-11-30' - interval 8 day ) dbt_test✓ passAt least 200,000 rowsrow_count_at_least · permits0
Guards against a partial extract replacing the full table. severity: error
select count(*) as failures from ( select count(*) as row_count from main.permits having count(*) < 200000 ) dbt_test✓ passpermit_id is uniqueunique · permits0
The primary key holds. severity: error
select count(*) as failures from ( select permit_id as unique_field, count(*) as n_records from main.permits where permit_id is not null group by permit_id having count(*) > 1 ) dbt_test
Run history
The last 10 production runs, newest first. Kept in manifest.json.
| Run | Trigger | Rows in | Duration | Tests |
|---|---|---|---|---|
| Nov 30, 2026, 5:01 p.m. MDT | GitHub Actions | 239,059 | 2.0 s | ✓ 9 pass · ! 3 warn |
| Nov 23, 2026, 3:49 p.m. MDT | GitHub Actions | 238,580 | 2.3 s | ✓ 9 pass · ! 3 warn |
| Nov 16, 2026, 1:58 p.m. MDT | GitHub Actions | 238,159 | 2.8 s | ✓ 9 pass · ! 3 warn |
| Nov 9, 2026, 2:15 p.m. MDT | GitHub Actions | 237,836 | 2.4 s | ✓ 9 pass · ! 3 warn |
| Nov 2, 2026, 1:54 p.m. MDT | GitHub Actions | 237,426 | 2.6 s | ✓ 9 pass · ! 3 warn |
| Oct 26, 2026, 10:22 a.m. MDT | GitHub Actions | 236,881 | 1.5 s | ✓ 9 pass · ! 3 warn |
| Oct 19, 2026, 10:43 a.m. MDT | GitHub Actions | 236,361 | 2.4 s | ✓ 9 pass · ! 3 warn |
| Oct 12, 2026, 1:30 p.m. MDT | GitHub Actions | 235,995 | 2.4 s | ✓ 9 pass · ! 3 warn |
| Oct 9, 2026, 10:20 a.m. MDT | GitHub Actions | 235,789 | 1.8 s | ✓ 9 pass · ! 3 warn |
| Oct 7, 2026, 2:25 p.m. MDT | Local | 235,585 | 0.8 s | ✓ 9 pass · ! 3 warn |
Data contract
What consumers of this data can rely on. The tests above enforce every line of it.
- Owner
- Cody Chandler
- Refresh
- Weekly, Mondays at 10:00 UTC, via Airflow on GitHub Actions
- Freshness SLA
- 8 days
- Keys
- permits: permit_id
- Consumers
- Lab dashboards, Ask the data (Claude-generated SQL)
- Source
- City of Calgary Open Data · Building PermitsOpen Government Licence – City of Calgary
- permit_id is unique and never null.
- Dates are DATE values. No timestamps, no time zones.
- Missing coordinates are NULL, never 0.
- A failing error-level test blocks the refresh. The last good snapshot keeps serving.
- Schema changes land in this repo, reviewed, before they ship.
Served files
Gold models written as Parquet and committed, so a deploy never depends on a third-party API.
- permits.parquet239,059 rows · 3.24 MB
sha256 40e123d9c340155d…