feat(traffic-calls): Add Traffic Calls API and Database Seeding - #15
Open
iacapuca wants to merge 8 commits into
Open
feat(traffic-calls): Add Traffic Calls API and Database Seeding#15iacapuca wants to merge 8 commits into
iacapuca wants to merge 8 commits into
Conversation
- Create new traffic-calls app using create-atlas-app CLI - Implement comprehensive database schema with hybrid approach: - Indexed columns for temporal, location, and classification data - JSONB fields for crash details, environmental conditions, and metadata - Generate database migration (0005_striped_agent_zero.sql) - Implement CSV data seeding with S3 support: - Upload CSV to DigitalOcean Spaces (5.3MB, 20,239 records) - Create seed script with batch processing (100 records/batch) - Add date validation to skip invalid records - Successfully imported 13,855 valid records (6,384 skipped due to invalid dates) - Integrate traffic-calls seed into master seed orchestrator - Add comprehensive documentation (DATA_FORMAT.md) - Configure Docker deployment with health checks - Set up OpenAPI spec generation - Add test infrastructure with Vitest Data source: CTTU Recife traffic incident data (2016-2024) Port: 3020 Database: atlas (shared)
- Fix S3 endpoint URLs in manifest.json to use bucket-specific endpoints - Add fallback mechanism for traffic calls seeding when S3 fails - Fix biome linting issues: - Remove redundant 'use strict' directive - Replace unsafe isNaN with Number.isNaN - Change let to const for non-reassigned variables - Fix unused variable by prefixing with underscore - Organize imports correctly - Fix biome-ignore suppression format - Remove comma operator usage - Fix JSON formatting
- Fix handling of datetime fields that already contain time component - Normalize time format to ensure zero-padded hours/minutes/seconds - Add detailed error tracking to identify skipped records - All 20,239 traffic call records now successfully imported Previously 6,384 records were skipped due to: 1. Date field containing full ISO datetime (e.g., '2023-01-01T00:00:00') 2. Time field with single-digit hours (e.g., '6:05:00' instead of '06:05:00') Results: ✅ 20,239 records successfully imported ✅ 0 records skipped ✅ 0 errors
- Add null coalescing operators to handle potentially undefined array elements - Fix type safety issues with string split operations - Ensure all string operations have proper type guards This fixes the CI build errors: - TS2532: Object is possibly 'undefined' - TS2322: Type 'string | undefined' is not assignable to type 'string'
- Add rootDir, noEmit, and node types to match cyclist-profile pattern - Add exclude array for consistency - Fixes TypeScript configuration for test type checking
- Add @atlas/typescript-config to devDependencies - Update hono from ^4.7.7 to ^4.10.2 to match traffic-deaths - Reorder dependencies alphabetically to match pattern - Now matches traffic-deaths and cyclist-profile exactly
- Update hono from ^4.7.7 to ^4.10.2 to match other apps - Add @atlas/typescript-config to devDependencies - Ensures all new apps created with the CLI have consistent versions - Fixes TypeScript configuration issues in generated apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚦 Traffic Calls API - CTTU Recife Data Integration
This PR introduces a new traffic-calls service to the Atlas monorepo, providing API access to traffic incident data from CTTU (Autarquia de Trânsito e Transporte Urbano do Recife) covering 2016-2024.
📋 Summary
🎯 Key Features
1. New Traffic Calls App
create-atlas-appCLI tool2. Database Schema Design
Implemented a hybrid approach balancing performance with flexibility:
Indexed Columns (for fast queries):
datetime- Timestamp of incidentnature- Incident classification (COM VÍTIMA, VÍTIMA FATAL, SEM VÍTIMA)street_name- Main street addressneighborhood- Neighborhood (bairro)total_victims,injured_victims,fatal_victims- Victim countscoordinates- Future PostGIS supportJSONB Fields (for flexible data):
crash_data- Crash type, description, vehicle detailsenvironmental_data- Weather, traffic lights, signage, road conditionsmetadata- Original ID, protocol, status, verification info3. Data Seeding Infrastructure
Data Quality Fixes:
Fixed two data validation issues that were causing 6,384 records to be skipped:
2023-01-01T00:00:00)6:05:00instead of06:05:00)Solution: Added datetime normalization and extraction logic to handle these edge cases.
4. S3 Configuration
5. Integration with Master Seed
Traffic Calls now appears in the seed summary alongside:
📁 Files Changed
New Files:
apps/traffic-calls/- Complete API servicepackages/database/src/schemas/traffic-calls/- Database schemapackages/database/src/seed-traffic-calls.ts- Seeding scriptpackages/database/src/migrations/0005_striped_agent_zero.sql- Migrationpackages/database/seed-data/traffic-calls/- CSV dataModified Files:
packages/database/src/seed.ts- Added traffic-calls to master seedpackages/database/seed-data/manifest.json- Added dataset metadata with correct S3 endpoints🧪 Testing
📚 Documentation
DATA_FORMAT.mdwith:🐳 Docker Support
🚀 Usage
Run the API:
Seed the database:
Run tests:
pnpm --filter @atlas/traffic-calls test📊 Data Source
🔗 Related
✅ Checklist