Skip to content

Lab 01 · NHL play-by-play

Calgary Flames shot analysis

Every Flames shot attempt since 2021-22, including this season. Where they shoot from, and where goals come from.

Last full season2025-26, 77 points
34-39-9
Top goal scorer22 goals in 2025-26
Morgan Frost
Games reconciled to the official scoreevery game, every season
438

Computed by the pipeline on Nov 30, 2026. See how

01

Dashboard

Source: NHL public API, schedules and play-by-play. Regular season only.

Loading Flames data…

02

Ask the Flames data

Ask a question in plain English. Claude writes the SQL and your browser runs it. See the guardrails.

Loading Ask the data…

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.

  • Reconciling detail to the official total

    Attribution that ties back to booked revenue, so finance and marketing report one number.

  • A locked-down API proxy

    Ad, CRM and ticketing data pulled safely, with rate limits and only the endpoints you need.

  • Raw events modelled in SQL

    Messy app and ad-platform events turned into one consistent view of each customer.

Decisions and trade-offs

What I chose, why, and what it cost.

  1. Keep the hockey rules in one place

    Why
    Rules like what counts as a power play live in one tested spot, so every chart agrees.
    Trade-off
    The raw NHL data needs a separate clean-up step first.
  2. Only allow the two NHL requests the site needs

    Why
    The NHL blocks direct browser access, so the site relays requests. Locking it down stops misuse.
    Trade-off
    Adding a new kind of NHL data takes a small code change.
  3. Download each finished game once

    Why
    Final results don’t change, so there’s no need to fetch them again.
    Trade-off
    If the NHL corrects an old game, the fix needs a manual refresh.

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
1.1 s
Rows extracted
71,035
Tests
9 pass · 0 warn

Lineage

Click a node for its SQL, schema and row counts. Run pipeline live checks the NHL for games newer than the snapshot. Changes stay in this tab.

  1. 1 Source

  2. 2 Bronze

  3. 3 Silver

  4. 4 Gold

  5. 5 Checks

  6. 6 Browser

stg_shotsdbt/models/flames/stg_shots.sql

52,750 rows · built in 293 ms · last production run

Shot attempts with strength derived from the situation code and coordinates flipped so every shooter attacks the right-hand net.

with attempts as (
    select
        p.*,
        p.owner_team_id = p.home_team_id                        as shooter_is_home,
        try_cast(substr(p.situation_code, 1, 1) as integer)     as away_goalie,
        try_cast(substr(p.situation_code, 2, 1) as integer)     as away_skaters,
        try_cast(substr(p.situation_code, 3, 1) as integer)     as home_skaters,
        try_cast(substr(p.situation_code, 4, 1) as integer)     as home_goalie
    from {{ ref('raw_plays') }} p
    where p.event_type in ('goal', 'shot-on-goal', 'missed-shot', 'blocked-shot')
      and p.period_type <> 'SO'
      and p.x is not null and p.y is not null
),

sided as (
    select
        *,
        -- A team attacks the net opposite the end it defends.
        case when shooter_is_home = coalesce(home_defending_side = 'right', false) then -1 else 1 end as flip,
        case when shooter_is_home then home_skaters else away_skaters end as own_skaters,
        case when shooter_is_home then away_skaters else home_skaters end as opp_skaters,
        case when shooter_is_home then away_goalie else home_goalie end  as opp_goalie
    from attempts
)

select
    s.game_id,
    s.period,
    cast(split_part(s.time_in_period, ':', 1) as integer) * 60
        + cast(split_part(s.time_in_period, ':', 2) as integer)            as period_seconds,
    case when s.owner_team_id = 20 then 'CGY' else 'OPP' end        as team,
    s.event_type                                                            as event,
    s.event_type = 'goal'                                                   as is_goal,
    s.shot_type,
    case
        when s.own_skaters is null or s.opp_goalie is null then 'other'
        when s.opp_goalie = 0 then 'EN'
        when s.own_skaters = s.opp_skaters and s.own_skaters = 5 then '5v5'
        when s.own_skaters = s.opp_skaters then 'even'
        when s.own_skaters > s.opp_skaters then 'PP'
        else 'SH'
    end                                                                     as strength,
    s.x * s.flip                                                            as x,
    s.y * s.flip                                                            as y,
    r.first_name || ' ' || r.last_name                                      as shooter
from sided s
left join {{ ref('raw_roster') }} r
    on r.game_id = s.game_id and r.player_id = s.shooter_id
ColumnTypeNull %
game_idBIGINT0
periodINTEGER0
period_secondsINTEGER0
teamVARCHAR0
eventVARCHAR0
is_goalBOOLEAN0
shot_typeVARCHAR27.0
strengthVARCHAR0
xINTEGER0
yINTEGER0
shooterVARCHAR0

Data quality tests

From the last production run. Warnings are real issues in the source, flagged rather than hidden.

  • ✓ passresult is W, L or OTLaccepted_values · flames_games0

    No ties, no unknowns. severity: error

    select count(*) as failures from (
    with all_values as (
    
        select
            result as value_field,
            count(*) as n_records
    
        from main.flames_games
        group by result
    
    )
    
    select *
    from all_values
    where value_field not in (
        'W','L','OTL'
    )
    ) dbt_test
  • ✓ passCoordinate flip points shots at the attacking netsingular · flames_shots0

    At least 95% of unblocked attempts should land in the attacking half. If the API changes its side convention, this catches it. severity: warn

    select count(*) as failures from (
    select avg((x > 0)::integer) as share_in_attacking_half
    from main.flames_shots
    where event <> 'blocked-shot'
    having avg((x > 0)::integer) < 0.95
    ) dbt_test
  • ✓ passPoints match the resultexpression_is_true · flames_games0

    Standings logic is applied consistently. severity: error

    select count(*) as failures from (
    select * from main.flames_games where not (points = case result when 'W' then 2 when 'OTL' then 1 else 0 end)
    ) dbt_test
  • ✓ passCoordinates are on the iceexpression_is_true · flames_shots0

    A rink is 200 by 85 feet. severity: error

    select count(*) as failures from (
    select * from main.flames_shots where not (x between -100 and 100 and y between -43 and 43)
    ) dbt_test
  • ✓ passShot-level goals reconcile to the final scoresingular · flames_shots0

    Counts goal events per game and compares them to the official score, allowing for the extra goal a shootout winner is credited. severity: error

    select count(*) as failures from (
    -- Returns games whose shot-level goals don't match the official score.
    with shot_goals as (
        select game_id,
               count(*) filter (where is_goal and team = 'CGY') as gf,
               count(*) filter (where is_goal and team = 'OPP') as ga
        from main.flames_shots
        group by 1
    )
    
    select g.game_id
    from main.flames_games g
    left join shot_goals s using (game_id)
    where g.goals_for - (g.decided_in = 'SO' and g.result = 'W')::integer <> coalesce(s.gf, 0)
       or g.goals_against - (g.decided_in = 'SO' and g.result <> 'W')::integer <> coalesce(s.ga, 0)
    ) dbt_test
  • ✓ passShooter name is presentnot_null · flames_shots0

    A few events arrive without a matching roster entry. severity: warn

    select count(*) as failures from (
    select shooter
    from main.flames_shots
    where shooter is null
    ) dbt_test
  • ✓ passEvery shot belongs to a known gamerelationships · flames_shots0

    Referential integrity between the two served tables. severity: error

    select count(*) as failures from (
    with child as (
        select game_id as from_field
        from main.flames_shots
        where game_id is not null
    ),
    
    parent as (
        select game_id as to_field
        from main.flames_games
    )
    
    select
        from_field
    
    from child
    left join parent
        on child.from_field = parent.to_field
    
    where parent.to_field is null
    ) dbt_test
  • ✓ passAt least 82 gamesrow_count_at_least · flames_games0

    Guards against a partial extract replacing full seasons. severity: error

    select count(*) as failures from (
    select count(*) as row_count from main.flames_games having count(*) < 82
    ) dbt_test
  • ✓ passgame_id is uniqueunique · flames_games0

    One row per game. severity: error

    select count(*) as failures from (
    select
        game_id as unique_field,
        count(*) as n_records
    
    from main.flames_games
    where game_id is not null
    group by game_id
    having count(*) > 1
    ) dbt_test

Run history

The last 10 production runs, newest first. Kept in manifest.json.

RunTriggerRows inDurationTests
Nov 30, 2026, 5:01 p.m. MDTGitHub Actions71,0351.1 s✓ 9 pass
Nov 23, 2026, 3:49 p.m. MDTGitHub Actions70,3741.9 s✓ 9 pass
Nov 16, 2026, 1:58 p.m. MDTGitHub Actions69,9072.5 s✓ 9 pass
Nov 9, 2026, 2:15 p.m. MDTGitHub Actions69,4431.6 s✓ 9 pass
Nov 2, 2026, 1:54 p.m. MDTGitHub Actions68,8031.8 s✓ 9 pass
Oct 26, 2026, 10:22 a.m. MDTGitHub Actions68,2111.3 s✓ 9 pass
Oct 19, 2026, 10:43 a.m. MDTGitHub Actions67,9271.7 s✓ 9 pass
Oct 12, 2026, 1:30 p.m. MDTGitHub Actions67,4072.2 s✓ 9 pass
Oct 9, 2026, 10:20 a.m. MDTGitHub Actions67,2411.3 s✓ 9 pass
Oct 7, 2026, 2:25 p.m. MDTLocal67,0780.6 s✓ 9 pass

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
flames_games: game_idflames_shots: game_id
Consumers
Lab dashboards, Ask the data (Claude-generated SQL)
Source
NHL public API · schedules and play-by-playData © NHL. Used here for non-commercial illustration.
  • Regular-season games only. Preseason and playoffs are excluded.
  • Shot coordinates are in feet, with the shooter always attacking x = 89.
  • Shot-level goals reconcile to the official final score for every game.
  • A failing error-level test blocks the refresh. The last good snapshot keeps serving.

Served files

Gold models written as Parquet and committed, so a deploy never depends on a third-party API.

Telemetry

This tab only. Nothing here leaves your browser.

Core Web Vitals

LCP
…
waiting
INP
…
waiting
CLS
…
waiting
FCP
…
waiting
TTFB
…
waiting

Measured in this browser with the web-vitals library. INP appears after you interact.

Query engine

Engine
Not started
Start-up
–
Data downloaded
–
Tables loaded
–
Queries run
0
Errors
0
p50 latency
–
p95 latency
–