A modern web application for visualizing and analyzing pre-collision pedestrian data. Built with Flask (Python) backend and React frontend, this platform enables interactive exploration of pedestrian safety modeling and collision risk analysis.
- Map Visualization: Interactive map using Leaflet.js displaying collision events
- Color-Coded Markers: Events color-coded by severity (green to dark red)
- Real-time Statistics: Live stats showing collision rates and average time-to-collision
- Drag & Drop: Easy CSV file upload with drag-and-drop support
- Data Validation: Automatic validation and preview of uploaded data
- Sample Data: Includes synthetic dataset for quick demonstration
- Multiple Models:
- Logistic Regression
- Cox Proportional Hazards
- Random Forest Classifier
- Feature Selection: Interactive feature selection for model training
- Performance Metrics: Comprehensive metrics including accuracy, precision, recall, F1-score, and AUC
- Visual Analytics: Charts showing feature importance and model performance
- Parameter Adjustment: Real-time sliders for modifying input parameters
- Sensitivity Analysis: Visualize how parameters affect collision probability
- Interactive Predictions: See instant predictions as parameters change
- PDF Reports: Professional reports with model summaries and visualizations
- CSV Export: Export results for further analysis in Excel or R/Python
- Academic Format: Reports formatted for research and teaching use
- Python 3.8 or higher
- Node.js 16 or higher
- npm or yarn
- Clone the repository
git clone <repository-url>
cd testing-pedestrians- Backend Setup
# Install Python dependencies
pip install -r requirements.txt
# Generate sample data
cd backend
python generate_sample_data.py
cd ..- Frontend Setup
cd frontend
npm install
cd ..You'll need two terminal windows:
Terminal 1 - Backend (Flask)
cd backend
python app.pyThe backend API will run on http://localhost:5000
Terminal 2 - Frontend (React)
cd frontend
npm run devThe frontend will run on http://localhost:3000
Open your browser and navigate to http://localhost:3000
The application includes a sample dataset generator that creates realistic pedestrian collision data with:
- 500 events with varied parameters
- Location coordinates (latitude/longitude)
- Pedestrian characteristics (age, velocity, distraction status)
- Vehicle characteristics (type, velocity, braking)
- Environmental factors (weather, lighting, road type)
- Collision outcomes with severity ratings (0-5)
- Time-to-collision values
- Avoidance behaviors
To generate new sample data:
cd backend
python generate_sample_data.pyOption A: Use Sample Data (Recommended for First Time)
- Navigate to "Upload Data" in the sidebar
- Click "Load Sample Data" button
- Sample dataset (500 events) loads instantly
- Dashboard and all features become immediately available
Option B: Upload Your Own Data
- Navigate to "Upload Data" in the sidebar
- Drag and drop your CSV file or click to browse
- Review the upload summary
- Data becomes available across all features
Option C: Download Sample for Inspection
- Click "Download Sample CSV" to save the file
- Inspect the format and structure
- Use as a template for your own data
- See all collision events on an interactive map
- Color-coded markers show severity
- Click markers for event details
- View overall statistics
- Go to "Analytics" section
- Select a statistical model (Logistic, Cox, or Random Forest)
- Choose features for analysis
- Click "Train Model"
- Review performance metrics and feature importance
- Navigate to "Simulation"
- Adjust parameters using sliders:
- Pedestrian velocity
- Vehicle velocity
- Time to collision
- Distraction level
- Braking status
- Click "Run Simulation"
- View sensitivity charts showing impact of each parameter
- Go to "Reports" section
- Select your trained model
- Generate PDF report with all metrics and visualizations
- Or export CSV for further analysis
testing-pedestrians/
βββ backend/
β βββ app.py # Flask API server
β βββ models/
β β βββ logistic_regression.py
β β βββ cox_hazards.py
β β βββ random_forest.py
β βββ utils/
β β βββ data_processor.py # Data processing utilities
β β βββ report_generator.py # PDF report generation
β βββ generate_sample_data.py # Sample data generator
β βββ uploads/ # Uploaded files directory
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ Dashboard.jsx # Map and statistics
β β β βββ Upload.jsx # File upload interface
β β β βββ Analytics.jsx # Model training and analysis
β β β βββ Simulation.jsx # Parameter simulation
β β β βββ Reports.jsx # Report generation
β β βββ App.jsx # Main app component
β β βββ main.jsx # Entry point
β βββ package.json
β βββ vite.config.js
βββ requirements.txt # Python dependencies
βββ README.md # This file
POST /api/upload- Upload CSV dataGET /api/data/sample- Get sample of current datasetGET /api/data/map- Get collision events for map
POST /api/model/train- Train a statistical modelPOST /api/model/predict- Make predictions
POST /api/simulate- Run parameter simulationPOST /api/report/generate- Generate PDF reportPOST /api/report/export-csv- Export results as CSV
This platform is designed for:
- Graduate Research: Interactive tool for exploring pedestrian safety datasets
- Teaching: Demonstrate statistical modeling concepts in traffic safety courses
- Policy Analysis: Communicate findings to municipalities and stakeholders
- Hypothesis Testing: Quickly test different model configurations
- Data Exploration: Visual exploration of complex collision datasets
- Flask - Python web framework
- scikit-learn - Machine learning models
- lifelines - Survival analysis (Cox model)
- pandas - Data manipulation
- ReportLab - PDF generation
- React - UI framework
- Vite - Build tool
- Tailwind CSS - Styling
- Leaflet.js - Interactive maps
- Recharts - Data visualization
- Axios - HTTP client
- All data processing happens locally
- No data is sent to external servers
- Uploaded files are stored temporarily
- Clear data management through the interface
Your CSV file should include these columns:
| Column | Description | Type |
|---|---|---|
latitude |
Event latitude | float |
longitude |
Event longitude | float |
pedestrian_velocity |
Pedestrian speed (m/s) | float |
vehicle_velocity |
Vehicle speed (m/s) | float |
ttc |
Time to collision (seconds) | float |
collision |
Collision occurred (0/1) | binary |
severity |
Collision severity (0-5) | integer |
pedestrian_distracted |
Distraction status (0/1) | binary |
vehicle_braking |
Braking status (0/1) | binary |
Optional columns: weather, lighting, road_type, avoidance_behavior, etc.
Quick Deploy (10 minutes):
# Set your Docker Hub username (or use environment variable)
export DOCKER_HUB_USERNAME=your-dockerhub-username
./deploy-azure.shManual Deployment: See detailed guides:
- Quick Start Guide - Step-by-step Azure Portal guide
- Deployment Options - Compare all Azure options & costs
- Full Azure Guide - Comprehensive deployment documentation
Free Option: Use Azure App Service Free Tier ($0/month) - good for testing and demos. See DEPLOYMENT_OPTIONS.md for details.
What you get:
- β Azure Static Web Apps (Frontend) - FREE
- β Azure Container Instances (Backend) - ~$15/month
- β Custom domain support with free SSL
- β Auto-scaling and CDN
- β One-click deployment script
New to Azure? Get $200 free credits for 30 days! Sign up here
- Check Python version:
python --version(should be 3.8+) - Reinstall dependencies:
pip install -r requirements.txt - Check port 5000 is available
- Check Node version:
node --version(should be 16+) - Delete node_modules and reinstall:
rm -rf node_modules && npm install - Check port 3000 is available
- Ensure data is uploaded first
- Check CSV format matches expected structure
- Verify sufficient data points (recommended: 100+ rows)
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
Created by OldAdventurer as an academic research platform for pedestrian safety analysis.
This project uses open-source libraries and tools. We're grateful to all contributors of these projects:
Backend:
- Flask - Web framework
- scikit-learn - Machine learning library
- pandas - Data analysis and manipulation
- lifelines - Survival analysis
- matplotlib & seaborn - Data visualization
- NumPy & SciPy - Scientific computing
Frontend:
- React - UI framework
- Vite - Build tool
- Tailwind CSS - Styling framework
- Victory - Data visualization
- Leaflet - Interactive maps
Infrastructure:
- OpenStreetMap - Map tiles and data
- All the amazing open-source contributors whose work makes projects like this possible
See requirements.txt and package.json for the complete list of dependencies.
Note: This is a research and educational tool. Model predictions should be validated with domain experts before use in policy decisions.