Skip to content
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

Add_md_snapshot #164

Merged
merged 5 commits into from
May 21, 2024
Merged
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
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ docker-run-evidence:
--env MDS_ENABLE_EXPORT=true \
--env ENVIRONMENT=docker \
mdsbox make run serve

DATES = $(shell python -c 'from datetime import datetime, timedelta; start_date = datetime(2023, 10, 24); end_date = datetime(2024, 4, 12); date_list = [start_date + timedelta(days=x) for x in range((end_date - start_date).days + 1)]; print(" ".join(date.strftime("%Y-%m-%d") for date in date_list))')

dbt-run-backfill:
@for date in $(DATES); do \
echo "Running dbt build for $$date"; \
(cd transform && dbt build -s tag:nba --vars "nba_start_date: $$date"); \
done
2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

720 changes: 429 additions & 291 deletions evidence/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions evidence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
},
"type": "module",
"dependencies": {
"@evidence-dev/core-components": "^4.2.0",
"@evidence-dev/core-components": "^4.0.1",
"@evidence-dev/csv": "^1.0.7",
"@evidence-dev/duckdb": "^1.0.9",
"@evidence-dev/evidence": "^35.0.0"
"@evidence-dev/evidence": "^33.0.1"
},
"overrides": {
"jsonwebtoken": "9.0.0",
Expand Down
1 change: 1 addition & 0 deletions transform/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ vars:
nba_elo_offset: 100 # nba offset to ELO to get to ~12% home advantage
nfl_elo_offset: 52 # nfl offset to ELO to get to 7.5% home advantage
ncaaf_elo_offset: 52 # ncaaf offset to ELO to get to 7.5% home advantage
nba_start_date: '2024-04-15' # set as of date for start of season

# external files are only registered as DuckDB views when they are created, not when they are referenced.
on-run-start:
Expand Down
8 changes: 6 additions & 2 deletions transform/models/nba/analysis/reg_season_summary.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{{ config(materialized="table") }}
{{
config(
materialized="table"
)
}}

with
cte_summary as (
Expand Down Expand Up @@ -41,6 +45,6 @@ select
c.seed_5th::int || ' to ' || c.seed_95th::int as seed_range,
c.made_postseason,
c.made_play_in,
{{ var("sim_start_game_id") }} as sim_start_game_id
'{{ var("nba_start_date") }}'::date as nba_sim_start_date
from cte_summary c
left join {{ ref("nba_reg_season_actuals") }} a on a.team = c.team
7 changes: 6 additions & 1 deletion transform/models/nba/analysis/season_summary.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{ config(materialized="table") }}
{{
config(
materialized="table",
post_hook="COPY {{ this }} TO '../data/data_catalog/{{ this.identifier }}_{{ var('nba_start_date') }}.parquet'",
)
}}

select
round(ratings.elo_rating, 0)::int
Expand Down
2 changes: 1 addition & 1 deletion transform/models/nba/raw/nba_raw_results.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
with
cte_base as (select * from {{ source("nba_dlt", "games") }}),
cte_seed as (select * from {{ source("nba", "nba_results") }})

select
coalesce(a.date, strptime(b."Date", '%a %b %-d %Y'))::date as "date",
b."Start (ET)" as "Start (ET)",
Expand Down Expand Up @@ -35,3 +34,4 @@ full outer join
cte_seed b
on strptime(b."Date", '%a %b %-d %Y')::date = a.date
and b."Home/Neutral" = home.team_long
where a.date <= '{{ var( 'nba_start_date' ) }}'
11 changes: 11 additions & 0 deletions utils/load_season_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
import duckdb

# initiate the MotherDuck connection through a service token through
con = duckdb.connect('md:?motherduck_token=' + os.environ.get('MOTHERDUCK_TOKEN'))

con.sql("CREATE TABLE IF NOT EXISTS nba_history_v2.main.season_summary ( elo_rating VARCHAR(15), team VARCHAR(3), conf VARCHAR(4), record VARCHAR(10), avg_wins REAL, vegas_wins REAL, elo_vs_vegas REAL, win_range VARCHAR(15), seed_range VARCHAR(15), made_postseason INT, made_play_in INT, nba_sim_start_date DATETIME, made_playoffs INT, made_conf_semis INT, made_conf_finals INT, made_finals INT, won_finals INT, PRIMARY KEY (team,nba_sim_start_date))")

con.sql("INSERT INTO nba_history_v2.main.season_summary (SELECT * FROM 'data/data_catalog/season_summar*.parquet')")

print("Data Loaded to Motherduck!")
Loading