Przejdź do treści
Biblioteka skilli
Dane i analityka · Budowanie i kod

pollen-view-structure

/pollen-view-structure

Strukturyzuje widoki BigQuery we wzorzec widoków Pollen: pliki widoków i konwersja SQL z notebooków na budowniczych widoków, tylko w folderze research/notebooks/policy.

Repozytorium
pulse-data ↗
Licencja
GPL-3.0
Ostatnia zmiana repozytorium
24.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 24.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

GPL-3.0, otwarta.

Co robi i kiedy

Strukturyzuje widoki BigQuery we wzorzec widoków Pollen: pliki widoków i konwersja SQL z notebooków na budowniczych widoków, tylko w folderze research/notebooks/policy.

Wyzwalacze z opisu

structure my viewscreate view filespull views from my notebookset up the view folder structuremake my SQL into view builders
Oryginalny opis (EN)

Use this skill when a user wants to structure BigQuery views into the standard Pollen view pattern. All Pollen analysis is in the research/notebooks/policy folder -- do not apply this skill outside that folder. Triggers include: "structure my views", "create view files", "pull views from my notebook", "set up the view folder structure", "make my SQL into view builders", or any request to convert notebook SQL or .sql files into the SimpleBigQueryViewBuilder pattern used by policy analysis work.

Jak działa

  1. Step 1: Gather Inputs
  2. Step 2: Extract View Candidates
  3. Step 3: Suggest Parameters
  4. Step 4: Write Files
  5. Step 5: Consistency Check + Compile
  6. Step 6: Present Results
Sekcje z nagłówków SKILL.md, w oryginale · 159 linii, 759 słów
Podgląd SKILL.md
---
name: pollen-view-structure
description: >
  Use this skill when a user wants to structure BigQuery views into the standard Pollen view pattern. All Pollen analysis is in the research/notebooks/policy folder -- do not apply this skill outside that folder. Triggers include: "structure my views",
  "create view files", "pull views from my notebook", "set up the view folder structure",
  "make my SQL into view builders", or any request to convert notebook SQL or .sql files
  into the SimpleBigQueryViewBuilder pattern used by policy analysis work.
---

# Pollen View Structure Skill

Converts SQL queries (from notebooks, .sql files, or provided directly) into the standard
Pollen view structure. **Before writing any files, read
[`recidiviz/research/notebooks/policy/CLAUDE.md`](../../../recidiviz/research/notebooks/policy/CLAUDE.md)
for the full file templates and naming conventions.**

---

## Step 1: Gather Inputs

Use `AskUserQuestion` to determine the SQL source, then ask remaining details in prose:

```python
AskUserQuestion(questions=[{
    "question": "Where is the SQL coming from?",
    "header": "SQL source",
    "options": [
        {"label": "Existing notebook", "description": "Extract SQL cells from a .ipynb file"},
        {"label": "Existing .sql files", "description": "Migrate from a queries/ folder"},
        {"label": "Provide directly", "description": "I'll describe or paste the SQL"},
    ],
    "multiSelect": True
}])
```

Then ask (in prose) for anything not already provided:
- **Prefix** — e.g. `us_co_aet`, `us_ar_paa`
- **Folder path** — where `{state_code}/{policy_project}/views/` should be created (e.g. `recidiviz/research/notebooks/policy/us_co/aet/views/`)
- **File path(s)** — notebook and/or .sql directory path(s), if applicable

---

## Step 2: Extract View Candidates

If the source includes **Existing notebook**:

Read the notebook JSON. Find cells containing SQL (`SELECT`, `FROM`, `WITH`, `JOIN`):
- `read_gbq(...)` calls with embedded SQL
- Variables assigned to SQL strings (`query = """SELECT ..."""`)
- Repeated CTEs — good candidates for dedicated views

Present candidates with cell index, 1-sentence description, and suggested view name:

```
Found 4 potential views:

[Cell 3] compartment_sessions — Incarceration sessions joined to person IDs
[Cell 7] credits — Credit records with decoded credit type descriptions
[Cell 12] programs — Program enrollments with decoded status columns
[Cell 19] session_outcomes — Aggregates disciplinaries and earned time per session

Which would you like to promote? (say "all", list specific ones, or adjust)
```

Wait for confirmation before proceeding.

If the source includes **existing .sql files**, copy the queries into `{prefix}_views/` with appropriate renaming and editing. 

If the source includes **provide directly**, ask the user to describe their desired functionality and draw on existing queries to translate that intention into queries. 

---

## Step 3: Suggest Parameters

Scan each view's SQL for hardcoded values worth extracting as named constants:

| Pattern | Example | Suggested name |
|---------|---------|----------------|
| Date literals | `>= '2012-01-01'` | `_START_DATE` |
| Year thresholds | `>= 2018` | `_START_YEAR` |
| Score/rating cutoffs | `>= '2023-01-01'` | `_RATING_CUTOFF_DATE` |
| State codes | `= 'US_CO'` | leave as-is |
| Domain filter strings | `= 'INCARCERATION'` | leave as-is |

Present suggestions and wait for approval:

```
Found 2 values to potentially extract:

[compartment_sessions] L42: `>= '2012-01-01'`
  Suggested: _START_DATE = '2012-01-01'  →  used as >= '{_START_DATE}'
  Reason: AET enactment year — likely adjusted for sensitivity analysis

[ratings] L19: `>= '2023-01-01'`
  Suggested: _RATING_CUTOFF_DATE = '2023-01-01'  →  used as >= '{_RATING_CUTOFF_DATE}'
  Reason: Rating coding changed in 2022 — this date may need adjustment

Which would you like to extract? (say "all", list specific ones, or "none")
```

---

## Step 4: Write Files

Before writing, fetch the author's GitHub handle to populate the description warning:

```bash
gh api user --jq .login
```

Create:
1. `{state_code}/{policy_project}/views/__init__.py` — empty (if it doesn't already exist)
2. One `.py` per view — follow the individual view file template in `CLAUDE.md`, substituting
   the actual GitHub handle into the `WARNING: ... don't use without review from <github-handle>` line

SQL formatting: strip leading/trailing blank lines, preserve `--` inline comments, indent
consistently (2 or 4 spaces) within the triple-quoted string.

**Project ID**: use `{project_id}` in plain-string queries, `{{project_id}}` in f-string queries
(see CLAUDE.md for details).

---

## Step 5: Consistency Check + Compile

Verify before running:

- [ ] Every view file has `VIEW_BUILDER = SimpleBigQueryViewBuilder(...)` at top level
- [ ] `description=__doc__` (not a hardcoded string) in every builder
- [ ] `__init__.py` exists in the `views/` folder
- [ ] Views with extracted constants use `f"""..."""` and correct SQL quoting
- [ ] No hardcoded `recidiviz-staging.` — use `{project_id}.` or `{{project_id}}.`

Fix any failures, then verify views compile:

```bash
uv run python -m recidiviz.tools.pollen.refresh_scratch_views \
    --project_id recidiviz-staging \
    --state_code {STATE_CODE} \
    --policy_project {policy_project}
```

If the run fails:
- **Minor errors** (import typo, wrong constant name, missing comma, SQL syntax issues): fix directly and re-run.
- **Logic issues**: flag to the user with the specific error and affected view,
  and ask whether to fix or leave for manual resolution.

---

## Step 6: Present Results

```
Created {state_code}/{policy_project}/views/ with {n} views:
  - {view1}.py  →  view_id: {prefix}_{view1}
  - {view2}.py  →  view_id: {prefix}_{view2}
  ...

All views compiled successfully. To re-deploy all:
  uv run python -m recidiviz.tools.pollen.refresh_scratch_views \
      --project_id recidiviz-staging --state_code {STATE_CODE} --policy_project {policy_project}

To re-deploy a single view:
  uv run python -m recidiviz.tools.pollen.refresh_scratch_views \
      --project_id recidiviz-staging --state_code {STATE_CODE} --policy_project {policy_project} \
      --view_id {view_name}
```

Wersje

W bazie nie ma innych skilli o nazwie pollen-view-structure.

Migawka bazy z 13.11.2026 · wersja paczki 013d832d6e2b (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100bigquery-view-generator
    Prawdopodobnie pomaga generować widoki w BigQuery i uruchamia się automatycznie przy pracy z nimi w kategorii GCP Skills.
  • 100aidp-google-bigquery
    Odczytuje tabele i widoki Google BigQuery z notebooków AIDP wbudowanym konektorem GOOGLE_BIGQUERY z uwierzytelnianiem kontem usługi, pushdownem SQL i catalog.id w AIDP 5.1 i nowszych.
  • 100load-views-to-sandbox
    Ładuje zmienione widoki BigQuery do osobistego zbioru danych sandbox i porównuje wyniki z wdrożonymi widokami, aby przetestować zmiany przed scaleniem.
  • 100sandbox-run
    Uruchamia sandbox BigQuery do sprawdzenia zmian potoku lub widoków przed scaleniem i porównuje wyniki. Przydaje się, gdy zmiana dotyczy ładowania danych lub samych widoków.
  • 100notebook-to-agilab-project
    Migruje lub utrzymuje mały lokalny przepływ notebooków w projekcie AGILAB: reprodukowalny projekt, notebooki w ANALYSIS, import notebooków w WORKFLOW, lab_stages.toml i kontrakty artefaktów.
  • 100bigquery-basics
    Zarządza zbiorami danych, tabelami i zadaniami w BigQuery, uruchamia zapytania SQL, obsługuje zasoby takie jak widoki oraz podstawowe ładowanie i analizę danych.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.