in gemini/agents/research-multi-agents/ev_agent/agent_handler/agent_06_VisualizeAgent.py [0:0]
def create_comprehensive_city_analysis(data):
"""
Creates comprehensive visualizations combining EV infrastructure and city data
Args:
data: Raw data containing city and infrastructure information
Returns:
dict: Dictionary of plotly figures
"""
figures = {}
# Extract city data for the first city
city_data = data.cities_data[0]
city_name = f"{city_data.city}, {city_data.state}"
# 1. EV Infrastructure Overview Dashboard
# Create separate figures for different chart types
# Charging Types
charging_data = pd.DataFrame(
[
{
"type": "DC Fast",
"count": city_data.ev_data.charging_capabilities.by_type[
"dc_fast"
].count,
},
{
"type": "Level 2",
"count": city_data.ev_data.charging_capabilities.by_type[
"level2"
].count,
},
{
"type": "Level 1",
"count": city_data.ev_data.charging_capabilities.by_type[
"level1"
].count,
},
]
)
charging_fig = px.bar(
charging_data,
x="type",
y="count",
title=f"Charging Station Types - {city_name}",
)
figures["charging_types"] = charging_fig
# Connector Distribution (Pie Chart)
connector_data = pd.DataFrame(
[
{"type": c.connector_type, "count": c.count}
for c in city_data.ev_data.charging_capabilities.connector_distribution
]
)
connector_fig = px.pie(
connector_data,
values="count",
names="type",
title=f"Connector Distribution - {city_name}",
)
figures["connector_distribution"] = connector_fig
# Network Distribution
network_data = pd.DataFrame(
[
{"network": n.name, "count": n.station_count}
for n in city_data.ev_data.network_analysis.networks
]
)
network_fig = px.bar(
network_data,
x="network",
y="count",
title=f"Network Distribution - {city_name}",
)
figures["network_distribution"] = network_fig
# Access & Payment Methods
access_data = pd.DataFrame(
[
{
"method": "Credit Card",
"percentage": city_data.ev_data.accessibility.payment_methods[
"credit_card"
]["percentage"],
},
{
"method": "Mobile Pay",
"percentage": city_data.ev_data.accessibility.payment_methods[
"mobile_pay"
]["percentage"],
},
{
"method": "Network Card",
"percentage": city_data.ev_data.accessibility.payment_methods[
"network_card"
]["percentage"],
},
{
"method": "24/7 Access",
"percentage": city_data.ev_data.accessibility.access_type[
"24_7_access"
]["percentage"],
},
]
)
access_fig = px.bar(
access_data,
x="method",
y="percentage",
title=f"Access & Payment Methods - {city_name}",
)
figures["access_methods"] = access_fig
# 2. Transportation Infrastructure Analysis
transport_fig = make_subplots(
rows=2,
cols=2,
subplot_titles=(
"Public Transport Facilities",
"Road Network Distribution",
"Parking Facilities",
"EV vs Traditional Infrastructure",
),
)
# Public Transport
transport_data = pd.DataFrame(
[
{"type": "Bus Stops", "count": city_data.summary.transport.bus_stops},
{
"type": "Train Stations",
"count": city_data.summary.transport.train_stations,
},
{"type": "Bus Stations", "count": city_data.summary.transport.bus_stations},
{"type": "Bike Rental", "count": city_data.summary.transport.bike_rental},
]
)
transport_fig.add_trace(
go.Bar(x=transport_data["type"], y=transport_data["count"]), row=1, col=1
)
# Road Network
road_data = pd.DataFrame(
[
{"type": "Motorways", "count": city_data.summary.roads.motorways},
{"type": "Primary", "count": city_data.summary.roads.primary_roads},
{"type": "Secondary", "count": city_data.summary.roads.secondary_roads},
{"type": "Residential", "count": city_data.summary.roads.residential_roads},
]
)
transport_fig.add_trace(
go.Bar(x=road_data["type"], y=road_data["count"]), row=1, col=2
)
# Parking Facilities
parking_data = pd.DataFrame(
[
{
"type": "Surface Parking",
"count": city_data.summary.parking.surface_parking,
},
{
"type": "Parking Structures",
"count": city_data.summary.parking.parking_structures,
},
{
"type": "Street Parking",
"count": city_data.summary.parking.street_parking,
},
{"type": "EV Charging", "count": city_data.summary.parking.ev_charging},
]
)
transport_fig.add_trace(
go.Bar(x=parking_data["type"], y=parking_data["count"]), row=2, col=1
)
# EV vs Traditional Infrastructure
infra_comparison = pd.DataFrame(
[
{
"type": "EV Charging Stations",
"count": city_data.summary.automotive.ev_charging_stations,
},
{
"type": "Fuel Stations",
"count": city_data.summary.automotive.fuel_stations,
},
{
"type": "Car Dealerships",
"count": city_data.summary.automotive.car_dealerships,
},
{"type": "Car Repair", "count": city_data.summary.automotive.car_repair},
]
)
transport_fig.add_trace(
go.Bar(x=infra_comparison["type"], y=infra_comparison["count"]), row=2, col=2
)
transport_fig.update_layout(
height=800, title_text=f"Transportation Infrastructure - {city_name}"
)
figures["transport"] = transport_fig
# 3. Urban Amenities and Services
amenities_fig = make_subplots(
rows=2,
cols=2,
subplot_titles=(
"Retail and Shopping",
"Food and Entertainment",
"Emergency Services",
"Public Amenities",
),
)
# Retail
retail_data = pd.DataFrame(
[
{
"type": "Shopping Centers",
"count": city_data.summary.retail.shopping_centres,
},
{"type": "Supermarkets", "count": city_data.summary.retail.supermarkets},
{
"type": "Department Stores",
"count": city_data.summary.retail.department_stores,
},
{
"type": "Convenience Stores",
"count": city_data.summary.retail.convenience_stores,
},
]
)
amenities_fig.add_trace(
go.Bar(x=retail_data["type"], y=retail_data["count"]), row=1, col=1
)
# Food and Entertainment
food_ent_data = pd.DataFrame(
[
{"type": "Restaurants", "count": city_data.summary.food.restaurants},
{"type": "Cafes", "count": city_data.summary.food.cafes},
{"type": "Bars", "count": city_data.summary.food.bars},
{"type": "Fast Food", "count": city_data.summary.food.fast_food},
]
)
amenities_fig.add_trace(
go.Bar(x=food_ent_data["type"], y=food_ent_data["count"]), row=1, col=2
)
# Emergency Services
emergency_data = pd.DataFrame(
[
{
"type": "Police Stations",
"count": city_data.summary.emergency.police_stations,
},
{
"type": "Fire Stations",
"count": city_data.summary.emergency.fire_stations,
},
{"type": "Hospitals", "count": city_data.summary.healthcare.hospitals},
{"type": "Clinics", "count": city_data.summary.healthcare.clinics},
]
)
amenities_fig.add_trace(
go.Bar(x=emergency_data["type"], y=emergency_data["count"]), row=2, col=1
)
# Public Amenities
public_data = pd.DataFrame(
[
{"type": "Post Offices", "count": city_data.summary.amenities.post_offices},
{"type": "Banks", "count": city_data.summary.amenities.banks},
{"type": "ATMs", "count": city_data.summary.amenities.atms},
{"type": "Public Toilets", "count": city_data.summary.amenities.toilets},
]
)
amenities_fig.add_trace(
go.Bar(x=public_data["type"], y=public_data["count"]), row=2, col=2
)
amenities_fig.update_layout(
height=800, title_text=f"Urban Amenities and Services - {city_name}"
)
figures["amenities"] = amenities_fig
# 4. Area Analysis (Pie Chart)
area_data = pd.DataFrame(
[
{
"type": "Total Area",
"area": city_data.summary.area_metrics.total_area_sqkm,
},
{
"type": "Water Area",
"area": city_data.summary.area_metrics.water_area_sqkm,
},
{
"type": "Green Area",
"area": city_data.summary.area_metrics.green_area_sqkm,
},
{
"type": "Built Area",
"area": city_data.summary.area_metrics.built_area_sqkm,
},
]
)
area_fig = px.pie(
area_data,
values="area",
names="type",
title=f"Area Distribution (sq km) - {city_name}",
)
figures["area"] = area_fig
return figures