Implement full 5-tab Toronto Neighbourhood Dashboard with real data connectivity: Dashboard Structure: - Overview tab with livability scores and rankings - Housing tab with affordability metrics - Safety tab with crime statistics - Demographics tab with population/income data - Amenities tab with parks, schools, transit Figure Factories (portfolio_app/figures/): - bar_charts.py: ranking, stacked, horizontal bars - scatter.py: scatter plots, bubble charts - radar.py: spider/radar charts - demographics.py: donut, age pyramid, income distribution Service Layer (portfolio_app/toronto/services/): - neighbourhood_service.py: queries dbt marts for all tab data - geometry_service.py: generates GeoJSON from PostGIS - Graceful error handling when database unavailable Callbacks (portfolio_app/pages/toronto/callbacks/): - map_callbacks.py: choropleth updates, map click handling - chart_callbacks.py: supporting chart updates - selection_callbacks.py: dropdown handlers, KPI updates Data Pipeline (scripts/data/): - load_toronto_data.py: orchestration script with CLI flags Lessons Learned: - Graceful error handling in service layers - Modular callback structure for multi-tab dashboards - Figure factory pattern for reusable charts Closes: #64, #65, #66, #67, #68, #69, #70 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
166 lines
5.3 KiB
Makefile
166 lines
5.3 KiB
Makefile
.PHONY: setup docker-up docker-down db-init load-data run test dbt-run dbt-test lint format ci deploy clean help
|
|
|
|
# Default target
|
|
.DEFAULT_GOAL := help
|
|
|
|
# Environment
|
|
PYTHON := python3
|
|
PIP := pip
|
|
DOCKER_COMPOSE := docker compose
|
|
|
|
# Colors for output
|
|
BLUE := \033[0;34m
|
|
GREEN := \033[0;32m
|
|
YELLOW := \033[0;33m
|
|
NC := \033[0m
|
|
|
|
help: ## Show this help message
|
|
@echo "Usage: make [target]"
|
|
@echo ""
|
|
@echo "Targets:"
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(BLUE)%-15s$(NC) %s\n", $$1, $$2}'
|
|
|
|
# =============================================================================
|
|
# Setup
|
|
# =============================================================================
|
|
|
|
setup: ## Install dependencies, create .env, init pre-commit
|
|
@echo "$(GREEN)Installing dependencies...$(NC)"
|
|
$(PIP) install -e ".[dev,dbt]"
|
|
@echo "$(GREEN)Setting up environment...$(NC)"
|
|
@if [ ! -f .env ]; then cp .env.example .env; echo "$(YELLOW)Created .env from .env.example - please update values$(NC)"; fi
|
|
@echo "$(GREEN)Installing pre-commit hooks...$(NC)"
|
|
pre-commit install
|
|
@echo "$(GREEN)Setup complete!$(NC)"
|
|
|
|
# =============================================================================
|
|
# Docker
|
|
# =============================================================================
|
|
|
|
docker-up: ## Start PostgreSQL + PostGIS containers
|
|
@echo "$(GREEN)Starting database containers...$(NC)"
|
|
$(DOCKER_COMPOSE) up -d
|
|
@echo "$(GREEN)Waiting for database to be ready...$(NC)"
|
|
@sleep 3
|
|
@echo "$(GREEN)Database containers started!$(NC)"
|
|
|
|
docker-down: ## Stop containers
|
|
@echo "$(YELLOW)Stopping containers...$(NC)"
|
|
$(DOCKER_COMPOSE) down
|
|
|
|
docker-logs: ## View container logs
|
|
$(DOCKER_COMPOSE) logs -f
|
|
|
|
# =============================================================================
|
|
# Database
|
|
# =============================================================================
|
|
|
|
db-init: ## Initialize database schema
|
|
@echo "$(GREEN)Initializing database schema...$(NC)"
|
|
@if [ -f scripts/db/init.sh ]; then \
|
|
bash scripts/db/init.sh; \
|
|
else \
|
|
echo "$(YELLOW)scripts/db/init.sh not found - skipping$(NC)"; \
|
|
fi
|
|
|
|
db-reset: ## Drop and recreate database (DESTRUCTIVE)
|
|
@echo "$(YELLOW)WARNING: This will delete all data!$(NC)"
|
|
@read -p "Are you sure? [y/N] " confirm && [ "$$confirm" = "y" ] || exit 1
|
|
$(DOCKER_COMPOSE) down -v
|
|
$(DOCKER_COMPOSE) up -d
|
|
@sleep 3
|
|
$(MAKE) db-init
|
|
|
|
load-data: ## Load Toronto data from APIs and run dbt
|
|
@echo "$(GREEN)Loading Toronto neighbourhood data...$(NC)"
|
|
$(PYTHON) scripts/data/load_toronto_data.py
|
|
|
|
load-data-only: ## Load Toronto data without running dbt
|
|
@echo "$(GREEN)Loading Toronto data (skip dbt)...$(NC)"
|
|
$(PYTHON) scripts/data/load_toronto_data.py --skip-dbt
|
|
|
|
# =============================================================================
|
|
# Application
|
|
# =============================================================================
|
|
|
|
run: ## Start Dash development server
|
|
@echo "$(GREEN)Starting Dash server...$(NC)"
|
|
$(PYTHON) -m portfolio_app.app
|
|
|
|
# =============================================================================
|
|
# Testing
|
|
# =============================================================================
|
|
|
|
test: ## Run pytest
|
|
@echo "$(GREEN)Running tests...$(NC)"
|
|
pytest
|
|
|
|
test-cov: ## Run pytest with coverage
|
|
@echo "$(GREEN)Running tests with coverage...$(NC)"
|
|
pytest --cov=portfolio_app --cov-report=html --cov-report=term
|
|
|
|
# =============================================================================
|
|
# dbt
|
|
# =============================================================================
|
|
|
|
dbt-run: ## Run dbt models
|
|
@echo "$(GREEN)Running dbt models...$(NC)"
|
|
cd dbt && dbt run
|
|
|
|
dbt-test: ## Run dbt tests
|
|
@echo "$(GREEN)Running dbt tests...$(NC)"
|
|
cd dbt && dbt test
|
|
|
|
dbt-docs: ## Generate dbt documentation
|
|
@echo "$(GREEN)Generating dbt docs...$(NC)"
|
|
cd dbt && dbt docs generate && dbt docs serve
|
|
|
|
# =============================================================================
|
|
# Code Quality
|
|
# =============================================================================
|
|
|
|
lint: ## Run ruff linter
|
|
@echo "$(GREEN)Running linter...$(NC)"
|
|
ruff check .
|
|
|
|
format: ## Run ruff formatter
|
|
@echo "$(GREEN)Formatting code...$(NC)"
|
|
ruff format .
|
|
ruff check --fix .
|
|
|
|
typecheck: ## Run mypy type checker
|
|
@echo "$(GREEN)Running type checker...$(NC)"
|
|
mypy portfolio_app
|
|
|
|
ci: ## Run all checks (lint, typecheck, test)
|
|
@echo "$(GREEN)Running CI checks...$(NC)"
|
|
$(MAKE) lint
|
|
$(MAKE) typecheck
|
|
$(MAKE) test
|
|
@echo "$(GREEN)All checks passed!$(NC)"
|
|
|
|
# =============================================================================
|
|
# Deployment
|
|
# =============================================================================
|
|
|
|
deploy: ## Deploy to production
|
|
@echo "$(YELLOW)Deployment not yet configured$(NC)"
|
|
@echo "TODO: Add deployment script"
|
|
|
|
# =============================================================================
|
|
# Cleanup
|
|
# =============================================================================
|
|
|
|
clean: ## Remove build artifacts and caches
|
|
@echo "$(YELLOW)Cleaning up...$(NC)"
|
|
rm -rf build/
|
|
rm -rf dist/
|
|
rm -rf *.egg-info/
|
|
rm -rf .pytest_cache/
|
|
rm -rf .ruff_cache/
|
|
rm -rf .mypy_cache/
|
|
rm -rf htmlcov/
|
|
rm -rf .coverage
|
|
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
@echo "$(GREEN)Clean complete!$(NC)"
|