((((( π§ WORK ACTIVELY IN PROGRESS π§ ))))
A smart system that automatically monitors and analyzes real-time traffic conditions on key routes throughout Bangalore city. Perfect for commuters, city planners, and anyone curious about traffic patterns in India's Silicon Valley known best for... its traffic problems!
The system uses Google Maps to check travel times between various locations around Bangalore. It:
- Automatically visits Google Maps for each route
- Extracts current travel time and distance data
- Calculates average speeds and traffic conditions
- Stores everything in CSV files for analysis
- Generates visual reports and insights
All of this happens automatically using web automation - no manual checking required!
- Installation
- Quick Start
- Configuration
- Usage
- Plotting and Visualization
- Route Ranking System
- Troubleshooting
- Advanced Customization
- Python 3.8 or higher
- Chrome browser (for web automation)
- Internet connection (for Google Maps access)
- Clone or download the project files to your computer
- Open terminal/command prompt and navigate to the project folder
- Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Verify installation:
python -c "import pandas, selenium, matplotlib, seaborn; print('All dependencies installed!')"
- Open the main script (
traffic_monitor.py) in your IDE or run it from terminal - Run the script:
python traffic_monitor.py
- The script will:
- Open Chrome browser automatically
- Visit Google Maps for each route
- Extract travel times and distances
- Save data to CSV files
- Generate plots and analysis
- Browser windows opening and closing (this is normal - the script is automating Google Maps)
- CSV files created in the project folder with traffic data
- Plot windows showing traffic analysis
After the first run, you'll have:
- csv-bangalore_traffic.csv - All traffic data
csv-routes.csv- Route definitions and labels- Various plot visualizations
Edit routes_df in traffic_visual.ipynb to add/remove routes:
routes_df = pd.DataFrame({
"route_code": [
"VJRQ+2M|RMJJ+F4", # Kudlu Gate Metro Station β Biocon Campus
"WH5F+26|WJ8X+F5W", # Jaya Prakash Nagar Metro Station β Hemavathi Park, HSR Layout
"XJPW+92|WJP4+FF", # Swami Vivekananda Road Metro Station β Christ University, Hosur Main Road
"2HVW+G8|XJXR+WG", # Bethel AG Church, Hebbal β SMVT Railway Station
"WGG8+G5|XH7P+G6", # The Watering Hole, Rajarajeshwari Nagar β Sir Puttanna Chetty Town Hall, Bangalore
"XPC7+72|XM33+J3", # The Rameshwaram Cafe @ Brookfield β Gawky Goose, Wind Tunnel Rd
"WHCJ+26|XGCP+FV", # RV Road Metro Station, Jayanagar 5th Block β Vijayanagar Metro Station, Chord Road
"XMW9+G8|WMJR+V4", # Benniganahalli Metro Station β Embassy TechVillage, Devarabisanahalli
"XHJ7+MG|WJM6+VC", # Lulu Mall Bengaluru β Nexus Mall Koramangala
"WHR9+R6|XJGF+6J", # Big Bull Temple, Basavanagudi β Shri Someshwara Swamy Temple, Halasuru
]})In traffic_monitor.py, customize:
# How often to check traffic (in seconds)
CHECK_INTERVAL = 3600 # Check every hour
# How many times to run
MAX_ITERATIONS = 100 # Run 100 times (adjust as needed)
# Wait time between route checks
WAIT_BETWEEN_ROUTES = 5 # Wait 5 seconds between routes-
Run the collector:
python traffic_monitor.py
-
Monitor progress - the script will print updates as it collects data
-
Stop anytime - press Ctrl+C to stop early
Open traffic_visual.ipynb in Jupyter Notebook:
-
Load and process data:
# Load raw traffic data master_df = pd.read_csv("csv-bangalore_traffic.csv") # Process into analysis-ready format df = transformed_data(master_df)
-
View data summary:
display(df.describe())
Show traffic speeds over time for all routes:
# Basic plot - last 24 hours, short labels
df_plot = plot_traffic_square(df, days_offset=1, label='short', height='square', dpi=300)
# Advanced - last 7 days, full labels, wide format
df_plot = plot_traffic_square(df, days_offset=7, label='full', height='extrawide', dpi=300)Parameters:
days_offset: How many days back to show (1 = last 24 hours)label: 'short' (Hosur Road) or 'full' (Kudlu Gate Metro Station β Biocon Campus)height: 'square', 'wide', 'extrawide', 'extrawide2' (controls figure size and hour intervals)
Compare route performance distributions:
# Both speed and duration boxplots
plot_route_boxplots(df, avg_speed=True, duration=True, legend=True, show_stats=True)
# Speed only, no x-axis labels, no median annotations
plot_route_boxplots(df, avg_speed=True, duration=False, legend=False, show_stats=False)Parameters:
avg_speed: Include average speed boxplotduration: Include duration boxplotlegend: Show route labels on x-axisshow_stats: Show median values and sample sizes on each box
Use one plot's output as another's input:
# Get time series data for last week
df_plot = plot_traffic_square(df, days_offset=7, label='full', height='extrawide', dpi=300)
# Generate boxplots from that data
plot_route_boxplots(df_plot, avg_speed=True, duration=True, legend=False)Calculate a 10-day rolling performance score:
# Calculate 10-day rolling scores
df_rrs = calculate_rrs(df, DAYS_ROLLING=10)
# Add human-readable route names
df_rrs['route'] = df_rrs['route_code'].map(
lambda x: locate(x.split('|')[0]) + 'β' + locate(x.split('|')[1])
)
df_rrs = df_rrs[['route', 'points']]
display(df_rrs)Change the rolling window:
# 5-day rolling score
df_rrs = calculate_rrs(df, DAYS_ROLLING=5)
# 30-day rolling score
df_rrs = calculate_rrs(df, DAYS_ROLLING=30)


