Skip to content

Add NCSBE ETL pipeline, materialized voter views, and SQL agent (CLI + web)#1

Draft
copelco wants to merge 17 commits intomainfrom
voter-data
Draft

Add NCSBE ETL pipeline, materialized voter views, and SQL agent (CLI + web)#1
copelco wants to merge 17 commits intomainfrom
voter-data

Conversation

@copelco
Copy link
Copy Markdown
Member

@copelco copelco commented Mar 26, 2026

Adds initial end-to-end NC voter data ETL.

Summary

  • NCSBE voter/history models
  • Download + bulk-load ETL commands
  • Materialized views
  • Pydantic AI SQL agent with both Django CLI and web chat interfaces

copelco added 16 commits March 25, 2026 20:48
- Add VoterView (all statuses) and VoterEventView using pg.MaterializedView
- Rename from MvVoterRegistration/MvVoterHistory; remove db_table/app_label
- Fix SQL table refs: ncsbe_voter, ncsbe_voterevent
- Add migration and model tests for both views
- Add LOGGING config; replace print() with logger.info() in loader
- Add elapsed_timer() contextmanager; remove duplicate timing from loaders
- Add --refresh-only flag to ncsbe etl command
- Add conftest.py to sync materialized views in test DB
- Draft README with setup and usage instructions
- Build minimal TSV fixtures (voter + history) and load via real COPY path
- Assert rows appear in VoterView and VoterEventView after refresh
- Test date casting and masked registr_dt → NULL
- Add pydantic-evals to dev dependencies
- Define IsSelectQuery, IsInvalidRequest, NoPiiColumns evaluators
- Define sql_gen_dataset with voter/off-topic test cases
- Add TestSqlGenEvals with 3 focused tests
- Register llm marker in pyproject.toml
- Add test_llm_judge_evals.py with no_pii and on_topic LLMJudge checks
- Use settings.VOTER_REG_MODEL (local ollama) as judge model
- All 3 tests pass against qwen3.5:9b
- Print sql_gen_agent system prompt and voter_agent instructions
- Support --name sql_gen|voter to filter output
- Add TestAgentPromptsCommand with 4 tests
- Add ReadOnlyAdmin base for materialized views (no add/change/delete)
- VoterViewAdmin: exact-match ncid search, show_full_result_count=False
- VoterEventViewAdmin: no search (ncid unindexed), show_full_result_count=False
- Add TestVoterViewAdmin and TestVoterEventViewAdmin (12 tests)
- Add db_comment to key VoterView and VoterEventView columns
- get_view_schema includes db_comment as inline SQL comments for the agent
- Add `ncsbe comments` subcommand to print copy-pasteable db_comment
  suggestions from distinct column values
- Add 6 focused tests covering schema comments and the new command
@copelco copelco changed the title Voter data Add NCSBE ETL pipeline, materialized voter views, and SQL agent (CLI + web) Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant