safety#

Crime safety scoring and ward-level data ingestion. This app owns the data pipeline for crime statistics; it uses models from the housing app (Ward, WardSafetySnapshot, Neighbourhood) rather than defining its own.

Models#

No models defined — uses housing.Ward, housing.WardSafetySnapshot, and housing.Neighbourhood.

Helper functions:

Function

Description

score_to_safety_level(score)

Maps 0–10 score → categorical level (Very Safe, Safe, …)

score_to_map_color(score)

Maps 0–10 score → hex color for map markers

Management Commands#

Command

Description

fetch_crime_safety

Ingest crime_safety.json from R2 / local fallback

verify_crime_data

Validate crime data integrity and consistency

Data Flow#

flowchart LR R2[R2: crime_safety.json] -->|fetch_crime_safety| WSS[WardSafetySnapshot] WSS -->|aggregation| NH[Neighbourhood.safety_score] NH --> PORTAL[neighbourhood_portal view] WSS --> REPORTS[reports app]

Key Design Decisions#

  • Shared models with housing — crime data lands in WardSafetySnapshot (owned by housing) to keep the single source of truth in one app.

  • Score → level/color helpers are defined here rather than on the model to keep the housing app free of safety-specific display logic.

  • verify_crime_data is a validation command (not a data fetch) — it checks for missing wards, score outliers, and period gaps.