fmazzoni/boston311
0
Boston 311 Service Requests Dashboard
An interactive geospatial dashboard for exploring Boston's 311 service request data from 2011-2025, built with modern Python data visualization technologies.

๐ฏ Features
- ๐บ๏ธ Interactive Geospatial Visualization - GPU-accelerated mapping with Lonboard
- ๐ Dynamic Filtering - Time periods, neighborhoods, sources, and service types
- ๐จ Color-coded Analysis - Visual patterns by category with interactive legends
- ๐ Data Selection - Click points or select areas to view detailed records
- โก High Performance - DuckDB for fast analytics on large datasets
- ๐ฑ Modern UI - Responsive design with dark theme
๐๏ธ Architecture
The application follows a modular architecture with clear separation of concerns:
src/boston311/
โโโ app.py # Main application entry point
โโโ config.py # Centralized configuration
โโโ dashboard.py # Main StateViewer dashboard component
โโโ database.py # Database operations and data fetching
โโโ time_periods.py # Dynamic time period utilities
โโโ color_mapping.py # Color mapping and visualization utilities
โโโ sql_utils.py # Safe SQL query construction
โโโ ui_components.py # Reusable UI components
โโโ logging_utils.py # Logging configuration utilities
โโโ extract.py # Data preprocessing scriptKey Design Principles
- ๐ Security First - SQL injection prevention with parameterized queries
- โก Performance - Cached operations and GPU acceleration
- ๐งช Testability - Modular components with clear interfaces
- ๐ Type Safety - Comprehensive type hints throughout
- ๐ Fail-Fast - Standard Python exceptions for clear error handling
๐ Quick Start
Prerequisites
- Python 3.11+
- UV package manager (recommended) or pip
Installation
- Clone the repository
git clone <repository-url>
cd boston311- Install dependencies
# Using UV (recommended)
uv sync
# Or using pip
pip install -e .- Extract and prepare data (see Data Extraction section below)
- Run the dashboard
# Using UV
uv run panel serve src/boston311/app.py --show --autoreload
# Or using Python directly
python -m panel serve src/boston311/app.py --show --autoreload๐ Data Extraction
The dashboard requires Boston 311 service request data to be preprocessed from the city's open data portal.
Automated Data Extraction
The extract.py script automatically downloads and processes the data:
# Run the extraction script
uv run python src/boston311/extract.py
# This will:
# 1. Scrape https://data.boston.gov/dataset/311-service-requests
# 2. Download all available CSV files (2011-2025)
# 3. Convert to Parquet format with spatial geometry processing
# 4. Save to data/raw/ directoryData Processing Steps
- ๐ Web Scraping - Automatically discovers CSV download URLs from the Boston data portal
- ๐ฅ Download - Fetches CSV files for each year (2011-2025)
- ๐บ๏ธ Spatial Processing - Converts WKB geometry to PostGIS-compatible format using DuckDB spatial extension
- ๐พ Parquet Conversion - Saves as efficient Parquet files for fast analytics
- ๐งน Data Cleaning - Filters out records without valid geometry
Manual Data Setup
If you prefer to download data manually:
- Visit Boston 311 Service Requests
- Download CSV files for desired years
- Place files in
data/raw/directory - Run the extraction script to convert to Parquet format
Data Schema
The processed data includes these key fields:
- `open_dt` - Request submission timestamp
- `source` - How the request was submitted (App, Phone, etc.)
- `subject` - Type of service request
- `neighborhood` - Boston neighborhood
- `geometry` - Spatial coordinates (Point geometry)
๐๏ธ Configuration
All configuration is centralized in config.py:
# UI Settings
MAP_HEIGHT = 600
TABLE_HEIGHT = 400
MAX_DISPLAY_RECORDS = 100
# Performance Limits
MAX_SELECTION_RECORDS = 1000
# Color Schemes
DEFAULT_POINT_COLOR = (255, 140, 0, 255)๐ง Development
Project Structure
- `config.py` - Application configuration and constants
- `database.py` - Database operations and data fetching with caching
- `time_periods.py` - Dynamic time period generation (relative dates)
- `color_mapping.py` - Stable color mapping for categorical data
- `sql_utils.py` - Safe SQL query construction (injection prevention)
- `ui_components.py` - Reusable UI components (tables, legends)
- `logging_utils.py` - Centralized logging configuration
- `dashboard.py` - Main StateViewer class with all interaction logic
- `extract.py` - Data preprocessing and extraction utilities
- `app.py` - Application entry point and Panel template setup
Code Quality
- Type Safety - Full type hints with mypy compatibility
- Linting - Ruff for fast Python linting
- Security - SQL injection prevention with parameterized queries
- Performance - Cached database operations and efficient data structures
- Modularity - Clear separation of concerns for maintainability
Adding New Features
- Data Filters - Add new filter options in
database.pyand updatedashboard.py - Visualizations - Extend
color_mapping.pyfor new color schemes - UI Components - Add reusable components in
ui_components.py - Configuration - Add new settings to
config.py
๐ Performance
- โก DuckDB - Columnar analytics engine for fast queries on large datasets
- ๐ฎ GPU Acceleration - Lonboard leverages WebGL for smooth map rendering
- ๐พ Caching - Panel caching for database operations and UI components
- ๐ฆ Parquet - Efficient columnar storage format
- ๐ Lazy Loading - Data loaded on-demand based on user selections
๐ Acknowledgments
- City of Boston - For providing open access to 311 service request data
- Panel - For the excellent dashboard framework
- DuckDB - For high-performance analytics capabilities
- Lonboard - For GPU-accelerated geospatial visualization
๐ Links
- [๐ Interactive Dashboard](https://huggingface.co/spaces/fmazzoni/boston311) - Try the interactive dashboard on Hugging Face Spaces
- Boston Open Data Portal
- Panel Documentation
- DuckDB Documentation
- Lonboard Documentation
