# Choosing a North Star metric for GitHub newcomers

Which first-week metric best predicts whether a new GitHub account is still active three months later, and which
first-week behaviours go with staying? This study builds a newcomer cohort from GH Archive's public event files,
models it in dbt, scores five candidate North Star metrics against week-13 retention, and ships the result as a
Tableau workbook and a Power BI project. The summary page is `index.html`; the detail pages are `results.html`
(the evidence), `dashboard.html` (the dashboard, the semantic model and the style guide) and `method.html` (method
and SQL).

## Data

GH Archive (https://www.gharchive.org/), one gzipped JSON file per hour holding every public GitHub event. The study
reads 15 days of it for each cohort (the day before the cohort day, the cohort day, days 1 to 6 and days 84 to 90):
360 hourly files. The files are not copied here; `tools/extract.py` downloads each hour, keeps the events of the
new-account id band and deletes the download.

## Reproduce

Python 3.12 with `duckdb`, `numpy`, `dbt-duckdb` and, for the Tableau extract, `tableauhyperapi` (the vendor's free
Hyper API). About 36 GB is downloaded per cohort, one hour at a time; the disk holds one hour at most.

```
python3 -B tools/extract.py /path/to/work-a
python3 -B tools/extract.py /path/to/work-b --cohort-day 2024-10-15
python3 -B tools/run_study.py /path/to/work-a 2024-09-10
python3 -B tools/run_study.py /path/to/work-b 2024-10-15
python3 -B tools/score.py
python3 -B tools/after_results.py /path/to/work-a /path/to/work-b
python3 -B tools/added_checks.py /path/to/work-a /path/to/work-b
python3 -B tools/metric_tree.py /path/to/work-a /path/to/work-b
python3 -B tools/combined_check.py /path/to/work-a /path/to/work-b
python3 -B tools/created_check.py /path/to/jh.py /path/to/work-a /path/to/work-b
python3 -B tools/extract.py /path/to/work-c --cohort-day 2024-11-19
python3 -B tools/run_study.py /path/to/work-c 2024-11-19
python3 -B tools/next_cohort.py /path/to/work-c
python3 -B tools/second_day_spread.py /path/to/work-a 2024-09-10 /path/to/work-b 2024-10-15 /path/to/work-c 2024-11-19
python3 -B tools/combined_any_event.py /path/to/work-a /path/to/work-b /path/to/work-c
python3 -B bi/build_dashboard.py /path/to/work-a 2024-09-10
python3 -B tests/test_study.py
python3 -I -B site/render.py
```

`run_study.py` runs `dbt build` (models and tests) on DuckDB, then `tools/analyze.py`. The bootstrap uses a fixed seed,
so every figure reproduces exactly from the same files.

`after_results.py` and `added_checks.py` are checks added after the results (events without stars; every candidate
against the outcome that counts stars too; stayers who never activated; how each score splits into higher, tied and
lower pairs). Their outputs say so in a `label` field. `metric_tree.py`, also added after the results, splits the
declared count into one branch per kind of event (reach times depth) and asserts the branches add back to it
(`results/metric-tree.json`).
`tests/test_study.py` also reads the built Tableau workbook and Power BI project back and checks every table in them
against the dashboard CSVs, and checks that counts show in full in both. The current files lead with the current
call: the first chart is week-13 retention by active days in week 1, the second is the event count that breaks their
ties, the candidates add "Active days, ties broken by events" as the chosen number, and the Power BI page opens on a
card for the share active on two or more days in week 1. They also title each chart a filter redraws by its measure,
show counts in full, and keep the activation filter in the activation rate (0% for Not activated).

The workbook `bi/out/north-star.twbx` is the one published on Tableau Public
(https://public.tableau.com/app/profile/diogo.travassos/viz/GitHubnewcomersNorthStar/NorthStardashboard). Its
published view, `figures/tableau-public-published.png`, shows the same seven titles, charts and filters. Its two
filters, first action and activation, apply to both charts they redraw: in Tableau Public they were set to apply to
every sheet on the Newcomers data source, and the workbook was saved from the app. `bi/tableau_workbook.py` writes one
filter per chart and field, so rebuilding the workbook from code would bring back two pairs of filters, one per
chart. The Power BI project in `bi/out/` was opened in Power BI Desktop and
viewed as both roles (`figures/powerbi-role-executive.png`, `figures/powerbi-role-maintainer01.png`). Viewed as the
maintainer role under a sign-in with no row in the Access table, it showed no newcomer rows. The activation rate's
readings by selection were not checked in the app. `tools/prepare_figures.py` copies the screenshots from `bi/out/`
(not in the download) into
`figures/`, dropping the app's title bar or cutting the window to the report canvas and its role banner. To rebuild
only the Power BI project and leave the published workbook as it is, run `bi/build_dashboard.py` with
`--powerbi-only`.

## The dbt project (`dbt/`)

- `models/sources.yml`: the extracted events and the census of hourly files read.
- `models/staging/stg_events.sql`: one row per event id; duplicates across hourly files dropped; events placed by
  `created_at`; own-repository and making-event flags.
- `models/staging/stg_hours.sql`: one row per hourly file, with missing and short flags.
- `models/marts/dim_account.sql`, `dim_day.sql`, `fct_account_day.sql`, `mart_newcomer.sql`: the dimensional model;
  `mart_newcomer` is one row per cohort member.
- `models/schema.yml` and `tests/`: key, accepted-value and relationship tests, plus three study tests.
- `profiles.yml`: a DuckDB target (used) and a BigQuery target for the same models (not run). Every model is a
  table, because the BigQuery sandbox allows no DML.

## The dashboard (`bi/`)

- `bi/out/north-star.twbx`: a Tableau packaged workbook with Hyper extracts, six sheets and one dashboard, saved
  from Tableau Public with its filters shared across the two charts they redraw.
  Opens in the free Tableau Public desktop app; published at
  https://public.tableau.com/app/profile/diogo.travassos/viz/GitHubnewcomersNorthStar/NorthStardashboard.
  Tableau Public needs the Hyper extract route: a workbook built with `--route csv` was refused there ("Workbooks
  saved to Tableau Public must use extracts", error 3C242D89).
- `bi/out/north-star-powerbi/`: a Power BI project (`north-star.pbip`): the semantic model as `model.bim` and one
  report page. The model holds a fact table (`Newcomers`), two dimensions related to it (`Maintainers`, `EventsBands`),
  a security table (`Access`) and four cohort-wide summary tables; every table states its grain and every DAX
  measure its definition. Two roles filter rows by audience: `Executive` (no filter) and `Maintainer (own rows)`
  (the signed-in user's maintainer, through `Access` and `USERPRINCIPALNAME()`). Both were viewed in Power BI Desktop
  with View as: as `Maintainer (own rows)` for maintainer01@example.com the cards read 96.2%, 71.7% and 53, with
  only Maintainer 01 in the filter; as `Executive`, 21.8%, 5.2% and 21,795. The project is
  not published to the Power BI service. Opens in the free Power BI Desktop; the data is inside the model, so
  there is no file path or credential to set.
- `results/semantic-model.json`: the model as documented on the page, written by `build_dashboard.py` from the
  same objects as the files; `site/render.py` checks it against `model.bim` and `report.json`.
- `results/dashboard/*.csv`: the five tables both files hold, and `maintainers`, `events_bands` and `access`, held by
  the Power BI model only (Tableau Public has no row-level access). Maintainers are codes, Maintainer 01 to Maintainer 10 by size,
  so no file names an account.
- Chart titles in both files follow the style guide on the page: a chart that a filter redraws is titled by its
  measure, one that never redraws names its cohort and states its finding (`TITLES` in `build_dashboard.py`). The
  files lead with active days and their tie-break, the event count, as the call now does.
- `bi/tableau_workbook.py`, `bi/pbip_project.py`, `bi/build_dashboard.py`: the code that writes them.

## Other files

- `DESIGN-r1.md`, `protocol-r1.json`, `predictions-r1.json`: written before any cohort query.
- `results/summary-2024-09-10.json`, `results/summary-2024-10-15.json`, `results/summary-2024-11-19.json`: every
  figure on the page.
- `results/top-number-check.json` (`tools/top_number_check.py`): added after the results, the score of the top number,
  the share active on two or more days, as a yes-or-no cut, against the best single cut of the event count.
- `results/predictions-scored.json`, `results/dbt-build-*.txt`: the predictions as scored and the dbt test results.
- `results/combined-check.json` (`tools/combined_check.py`): added after the results, the combined number (active
  days, ties broken by events) and the share of untied pairs each number ranks the right way round.
- `protocol-next.json`: the next cohort, declared before any query on it, with the rules that would change the call.
- `results/next-cohort-2024-11-19.json` (`tools/next_cohort.py`): that cohort scored as declared, with its decision: its rules switch the call to the combined number (active days, ties broken by events).
- `results/created-check.json` (`tools/created_check.py`): added after the results, the creation dates of 50 sampled
  accounts from GitHub's public API, kept only as counts by day; no account is named.
- `results/second-day-spread.json` (`tools/second_day_spread.py`): added after the results, the share back on a
  second day by the hour block of sign-up, and the clock-free share with an event 24 to 48 hours after the first, by
  hour block and by first action, on all three days.
- `results/combined-any-event.json` (`tools/combined_any_event.py`): added after the results, days then events
  against the event count on the outcome that counts stars too, on all three days, with stars scored on that outcome
  and the two numbers a dashboard shows for the ranking (the share active on two or more days in week 1, and the
  average events of newcomers active on one day).
- `site/render.py`, `site/sections.py`, `site/model_parts.py`, `site/page.css`: the pages; every number comes from
  `results/`. `model_parts.py` draws the metric tree, the semantic model tables and the chart style guide.
- `tests/test_study.py`: the AUC against a brute-force count, the BI files read back against the tables, the
  semantic model and the frozen design files.
- `vendor/viz-design-system/`: the chart kit (version 2.3.0) with its licences.

## Licence of the data

GH Archive is published by Ilya Grigorik; the events are GitHub's public timeline. Results here are aggregates; the
page names no account and no repository.

Some files are packed in north-star-dashboard-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
