Create crime and amenities loaders #58

Closed
opened 2026-01-16 15:49:54 +00:00 by lmiranda · 1 comment
Owner

Overview

Create database loaders for crime statistics and amenities data.

Files to Create

portfolio_app/toronto/loaders/crime.py

def load_crime_data(
    records: list[CrimeRecord],
    session: Session | None = None,
) -> int:
    """Load crime records to fact_crime, returning count loaded."""

portfolio_app/toronto/loaders/amenities.py

def load_amenities(
    records: list[AmenityRecord],
    session: Session | None = None,
) -> int:
    """Load amenity records to fact_amenities, returning count loaded."""

Acceptance Criteria

  • Loaders follow existing patterns in loaders/dimensions.py
  • Use upsert_by_key for idempotent loading
  • Support optional session parameter
  • Return count of records loaded
  • Import test passes
  • Linter passes

Technical Notes

  • Crime loader should use (neighbourhood_id, year, crime_type) as unique key
  • Amenities loader should use (neighbourhood_id, amenity_type, year) as unique key

Labels

Type/Feature, Priority/Medium, Component/Backend, Component/Database, Tech/Python

## Overview Create database loaders for crime statistics and amenities data. ## Files to Create ### `portfolio_app/toronto/loaders/crime.py` ```python def load_crime_data( records: list[CrimeRecord], session: Session | None = None, ) -> int: """Load crime records to fact_crime, returning count loaded.""" ``` ### `portfolio_app/toronto/loaders/amenities.py` ```python def load_amenities( records: list[AmenityRecord], session: Session | None = None, ) -> int: """Load amenity records to fact_amenities, returning count loaded.""" ``` ## Acceptance Criteria - [ ] Loaders follow existing patterns in `loaders/dimensions.py` - [ ] Use upsert_by_key for idempotent loading - [ ] Support optional session parameter - [ ] Return count of records loaded - [ ] Import test passes - [ ] Linter passes ## Technical Notes - Crime loader should use (neighbourhood_id, year, crime_type) as unique key - Amenities loader should use (neighbourhood_id, amenity_type, year) as unique key ## Labels `Type/Feature`, `Priority/Medium`, `Component/Backend`, `Component/Database`, `Tech/Python`
Author
Owner

Implementation complete:

  • Created loaders/crime.py with load_crime_data() function
  • Created loaders/amenities.py with load_amenities() and load_amenity_counts() functions
  • Crime loader upserts by (neighbourhood_id, year, crime_type)
  • Amenities loader aggregates individual records to counts and upserts by (neighbourhood_id, amenity_type, year)
  • Import tests passed
Implementation complete: - Created `loaders/crime.py` with `load_crime_data()` function - Created `loaders/amenities.py` with `load_amenities()` and `load_amenity_counts()` functions - Crime loader upserts by (neighbourhood_id, year, crime_type) - Amenities loader aggregates individual records to counts and upserts by (neighbourhood_id, amenity_type, year) - Import tests passed
lmiranda added this to the Launch: Host, Bio and Toronto House Market Analysis project 2026-01-16 16:06:20 +00:00
lmiranda self-assigned this 2026-01-16 16:06:30 +00:00
lmiranda moved this to Done in Launch: Host, Bio and Toronto House Market Analysis on 2026-01-16 16:06:52 +00:00
Sign in to join this conversation.