Create Toronto Police crime data parser #55

Closed
opened 2026-01-16 15:49:46 +00:00 by lmiranda · 2 comments
Owner

Overview

Create a parser for fetching crime data from Toronto Police (hosted via CKAN).

File to Create

portfolio_app/toronto/parsers/toronto_police.py

API Details

  • Host: https://ckan0.cf.opendata.inter.prod-toronto.ca (hosted by Toronto)
  • Datasets:
    • neighbourhood-crime-rates - Crime rates by neighbourhood
    • major-crime-indicators - MCI detailed data
    • shootings-firearm-discharges - Shooting incidents

Class Structure

class TorontoPoliceParser:
    def __init__(self, cache_dir: Path | None = None):
        ...
    
    def get_crime_rates(self, years: list[int] | None = None) -> list[CrimeRecord]:
        """Fetch neighbourhood crime rates."""
    
    def get_major_crime_indicators(self) -> list[CrimeRecord]:
        """Fetch detailed MCI data."""

Acceptance Criteria

  • Parser fetches crime data from CKAN API
  • Returns validated CrimeRecord schema objects
  • Correctly maps Hood_ID to neighbourhood_id (AREA_ID)
  • Year filtering works correctly
  • Import test passes
  • Linter passes

Technical Notes

  • Hood_ID in police data maps to AREA_ID in neighbourhood data
  • Crime types should map to CrimeType enum

Labels

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

## Overview Create a parser for fetching crime data from Toronto Police (hosted via CKAN). ## File to Create `portfolio_app/toronto/parsers/toronto_police.py` ## API Details - **Host**: `https://ckan0.cf.opendata.inter.prod-toronto.ca` (hosted by Toronto) - **Datasets**: - `neighbourhood-crime-rates` - Crime rates by neighbourhood - `major-crime-indicators` - MCI detailed data - `shootings-firearm-discharges` - Shooting incidents ## Class Structure ```python class TorontoPoliceParser: def __init__(self, cache_dir: Path | None = None): ... def get_crime_rates(self, years: list[int] | None = None) -> list[CrimeRecord]: """Fetch neighbourhood crime rates.""" def get_major_crime_indicators(self) -> list[CrimeRecord]: """Fetch detailed MCI data.""" ``` ## Acceptance Criteria - [ ] Parser fetches crime data from CKAN API - [ ] Returns validated CrimeRecord schema objects - [ ] Correctly maps Hood_ID to neighbourhood_id (AREA_ID) - [ ] Year filtering works correctly - [ ] Import test passes - [ ] Linter passes ## Technical Notes - Hood_ID in police data maps to AREA_ID in neighbourhood data - Crime types should map to CrimeType enum ## Labels `Type/Feature`, `Priority/Medium`, `Component/Backend`, `Component/API`, `Tech/Python`
Author
Owner

Starting implementation of TorontoPoliceParser for crime data via CKAN API.

Starting implementation of TorontoPoliceParser for crime data via CKAN API.
Author
Owner

Implementation complete:

  • Created parsers/toronto_police.py with TorontoPoliceParser
  • Methods: get_crime_rates(), get_major_crime_indicators()
  • Hood_ID to neighbourhood_id mapping implemented
  • Year filtering support
  • Crime type normalization to CrimeType enum
  • Updated parsers/__init__.py with exports
  • Import test passed
Implementation complete: - Created `parsers/toronto_police.py` with `TorontoPoliceParser` - Methods: `get_crime_rates()`, `get_major_crime_indicators()` - Hood_ID to neighbourhood_id mapping implemented - Year filtering support - Crime type normalization to CrimeType enum - Updated `parsers/__init__.py` with exports - Import test 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:48 +00:00
Sign in to join this conversation.