A sophisticated ride-sharing driver optimization platform that uses Dynamic Programming and Machine Learning to help drivers maximize their earnings by recommending optimal working hours and zones based on historical data, real-time conditions, and driver preferences.
cd server
docker compose build server --no-cache
docker compose up serverThe server will be available at: http://localhost:8000 API Documentation: http://localhost:8000/docs
cd client
npm install
bun x expo startImportant: If you're running the client on a physical device or iOS/Android simulator, update the server IP address in client/config/Config.ts to your machine's local IP (run ipconfig getifaddr en0 on Mac to get it).
The system uses DBSCAN (Density-Based Spatial Clustering of Applications with Noise) to create geographic zones:
- Input: Historical ride pickup and dropoff coordinates
- Parameters:
eps = 250m(maximum distance between points in a cluster)min_samples = 10(minimum points to form a cluster)
- Output: City-specific clusters representing high-demand zones
Each cluster becomes a node in our mobility graph, with averaged latitude/longitude coordinates for map visualization.
For each city, we construct a directed graph where:
- Nodes = Clusters (geographic zones created by DBSCAN)
- Edges = Possible trips between zones, containing:
- Average fare amount
- Average trip duration (minutes)
- Trip counts per hour (0-23)
- Hourly statistics (fares, times, demand)
This creates a city-hour mobility graph that captures how demand, pricing, and travel patterns change throughout the day.
For any given cluster and hour, the system computes the expected earning rate (β¬/hour) using:
earning_rate = (expected_fare Γ surge_multiplier Γ weather_multiplier) / total_time
Where:
- Expected Fare = Weighted average of fares to all reachable zones based on transition probabilities
- Surge Multiplier = Dynamic pricing factor for that hour and zone
- Weather Multiplier = Demand adjustment based on weather conditions
- Total Time = Travel time + Expected wait time (calculated from demand rate)
Transition Probabilities are computed using Laplace smoothing:
P(iβj) = (trips_from_i_to_j[hour] + Ξ΅) / (total_trips_from_i[hour] + Ξ΅ Γ |zones|)
The core algorithm uses backward induction to find the optimal strategy:
V[time_remaining][cluster] = max over all destinations j of:
(fare_to_j Γ surge Γ weather) + Ξ³ Γ V[time_remaining - trip_time][j]Parameters:
Ξ³(gamma) = 0.95 (discount factor for future earnings)time_remaining= Minutes left in the work shifttrip_time= Travel time + wait time at destination
The algorithm:
- Starts with terminal condition:
V[0][any_cluster] = 0(no time left = no earnings) - Works backward through time intervals (5-minute increments)
- For each cluster and time, finds the best next destination
- Stores the optimal path and expected total earnings
Result: For a given start hour and work duration, the system identifies:
- Which zone to start in (highest expected earnings)
- The optimal sequence of zones to move through
- Total expected earnings for the shift
POST /api/v1/drivers/{driver_id}/preferences
Content-Type: application/json
{
"earliest_start_time": "06:00",
"latest_start_time": "18:00",
"nr_hours": 8
}Stores the driver's preferred working time window and shift duration.
GET /api/v1/drivers/{driver_id}/preferencesRetrieves saved preferences.
GET /api/v1/drivers/{driver_id}/recommendations/optimal-timeReturns the best start time within the driver's preferred window, along with:
- Expected score (earnings potential)
- Remaining hours available to work
GET /api/v1/drivers/{driver_id}/recommendations/time-scoresReturns a list of all possible start times with their comparative scores, used to generate the histogram visualization showing earnings potential for each hour.
GET /api/v1/drivers/{driver_id}/recommendations/best-zone?current_time=8Returns the optimal starting zone for a specific hour, including:
- Cluster ID
- Expected score
- Center coordinates for map display
GET /api/v1/drivers/{driver_id}/recommendations/zone-scoresReturns all zones ranked by score for the selected time, enabling comparison visualization.
POST /api/v1/ai/chat/{driver_id}
Content-Type: application/json
{
"message": "Should I take a break now?",
"chat_history": []
}Powered by Google Gemini 2.5 Flash, the AI assistant provides:
- Driving advice based on real-time conditions
- Wellness recommendations
- Tips for maximizing earnings
- Safety guidance
GET /api/v1/ai/wellness/{driver_id}?hours_driven=4.5Automatically triggers a break reminder after 4.5 hours of active driving, promoting driver safety and well-being.
POST /api/v1/drivers/{driver_id}/start-session # Start tracking
POST /api/v1/drivers/{driver_id}/stop-session # Stop tracking
GET /api/v1/drivers/{driver_id}/driving-hours # Get current hoursTracks driving sessions to automatically calculate hours driven for wellness features.
- Driver opens the app and clicks "Schedule Your Drive"
- Selects their preferred start time window (e.g., 06:00 - 18:00)
- Adjusts total work hours (e.g., 8 hours)
- System calculates the optimal start time using dynamic programming
- Driver sees a bar chart histogram showing:
- All possible start times
- Expected earnings as percentages relative to the optimal time
- Color coding: Green (>66%), Orange (33-66%), Gray (<33%)
- Can scroll through and select a different start time if preferred
- Confirms selection to proceed
- System displays the recommended optimal zone for the chosen time
- Driver can tap to see zone comparison histogram:
- All zones ranked by expected earnings
- Percentage scores relative to the best zone
- Visual comparison to help make informed decisions
- Can explore alternative zones while seeing performance trade-offs
- After confirming time and zone:
- Selected zone is highlighted on the map
- Driver sees their current location
- Real-time zone boundaries displayed
- Start driving from the optimal location
-
Proactive Break Reminder: After 4.5 hours of continuous driving, a modal appears:
- "Time for a Break" notification
- Option to open the Wellness Copilot chatbot
- Can dismiss or engage with AI for break suggestions
-
AI Chat Features:
- Ask questions about driving strategy
- Get wellness tips and break recommendations
- Receive context-aware advice based on:
- Current weather conditions
- Surge pricing patterns
- Recent trip performance
- Driver preferences
- Live driving hour counter
- Driver status indicator (Online/Offline)
- AI-generated suggestions based on:
- Time of day (rush hours, late night patterns)
- Weather conditions
- Active surge zones
- Recent performance
- Bun + Expo + React Native + TypeScript
- Cross-platform: iOS, Android, Web
- React Navigation for screens
- Mapbox for map visualization
- ESLint, Prettier for code quality
- Jest for unit testing
- FastAPI (Python 3.11+)
- NetworkX for graph operations
- Pandas for data processing
- scikit-learn (DBSCAN clustering)
- Google Gemini 2.5 Flash for AI chat
- SQLite for persistent storage
- Redis for caching and real-time data
- Hatch for environment management
- Ruff for linting & formatting
server/app/cluster_analysis.py- DBSCAN clustering implementationserver/app/graph_builder.py- Builds city-hour mobility graphsserver/app/dynamic_programming_optimizer.py- DP optimization algorithmserver/app/service.py- Business logic layerserver/app/endpoints.py- REST API endpointsserver/app/ai_agent.py- AI chatbot and wellness features
client/screens/MapHomeScreen.tsx- Main map interfaceclient/components/SchedulePanel.tsx- Working hours selectionclient/components/OptimalDetailsPanel.tsx- Time/zone comparison histogramsclient/components/WellnessNudge.tsx- Break reminder modalclient/screens/AIChatScreen.tsx- AI assistant chatclient/config/Config.ts- API configuration
β Smart Scheduling: ML-powered optimal time recommendations β Zone Optimization: Dynamic programming for best starting locations β Visual Comparisons: Interactive histograms for time/zone analysis β AI Copilot: Context-aware chatbot for driving advice β Wellness Tracking: Automatic break reminders after 4.5 hours β Real-time Data: Surge pricing, weather, and demand integration β Session Tracking: Automatic driving hours calculation β Map Visualization: Highlighted zones and cluster boundaries β Multi-city Support: Independent graphs and recommendations per city β Caching System: Redis caching for fast DP computations
- Historical Data β DBSCAN Clustering β Zone Graph
- Zone Graph + Weather + Surge β Earning Rates
- Earning Rates + DP Algorithm β Optimal Strategies
- Driver Preferences + Optimal Strategies β Recommendations
- Real-time Conditions + AI β Proactive Suggestions
Create a .env file in the root directory:
GEMINI_API_KEY=your_gemini_api_key_here
REDIS_URL=redis://localhost:6379
DATABASE_URL=sqlite:///./data/app.db
API_HOST=0.0.0.0
API_PORT=8000
DEBUG=true- Singleton Pattern: Graph loaded once and reused
- Graph Serialization: Cached to disk for fast startup
- Redis Caching: DP results cached with 1-hour TTL
- Transition Probability Caching: Per (city, hour) to avoid recomputation
- 5-minute Time Intervals: Balance between precision and speed
This project was developed for the JunctionX Uber Challenge hackathon.
This is a hackathon project. For questions or issues, please contact the development team.