dd-l1-capetown-clinics-bbox
Map (reference ← swipe → agent)
0:00
I'm about to push the `capetown_clinics.csv` export through to our case-management system and I want a quick inventory check first. Can you produce a small JSON file with the total clinic count, the overall bounding box as a bbox array, and the count per subdistrict, so I can confirm every health subdistrict is represented? Please write it to `clinic_inventory.json` with keys `count`, `bbox`, and `count_per_subdistrict`.
0:00
System info
{
"adapter": "openrouter",
"model": "google/gemma-4-26b-a4b-it",
"base_url": "https://openrouter.ai/api/v1"
}
0:01
Bash
ls -F
capetown_clinics.csv
0:41
Write
/work/solve.py
content · 71 lines · py
import pandas as pd
import json
def main():
file_path = 'capetown_clinics.csv'
try:
df = pd.read_csv(file_path)
except Exception as e:
print(f"Error reading CSV: {e}")
return
# Check columns to ensure we have what we need
# Assuming columns like 'latitude', 'longitude', and 'subdistrict' exist.
# Let's inspect the columns first if needed, but I'll try to be robust.
# 1. Total count
total_count = len(df)
# 2. Bounding Box
# We need to identify the longitude and latitude columns.
# Common names: 'longitude', 'latitude', 'lon', 'lat', 'x', 'y'
lon_col = None
lat_col = None
for col in df.columns:
c = col.lower()
if c in ['longitude', 'lon', 'x']:
lon_col = col
if c in ['latitude', 'lat', 'y']:
lat_col = col
if lon_col and lat_col:
min_lon = df[lon_col].min()
max_lon = df[lon_col].max()
min_lat = df[lat_col].min()
max_lat = df[lat_col].max()
bbox = [min_lon, min_lat, max_lon, max_lat]
else:
bbox = None
print(f"Warning: Could not identify lon/lat columns. Columns found: {df.columns.tolist()}")
# 3. Count per subdistrict
# Assuming 'subdistrict' is the column name.
subdistrict_col = None
for col in df.columns:
if 'subdistrict' in col.lower():
subdistrict_col = col
break
if subdistrict_col:
count_per_subdistrict = df[subdistrict_col].value_counts().to_dict()
else:
count_per_subdistrict = {}
print(f"Warning: Could not identify subdistrict column. Columns found: {df.columns.tolist()}")
# Prepare JSON
inventory = {
"count": int(total_count),
"bbox": bbox,
"count_per_subdistrict": count_per_subdistrict
}
with open('clinic_inventory.json', 'w') as f:
json.dump(inventory, f, indent=4)
print("Successfully created clinic_inventory.json")
if __name__ == "__main__":
main()
Wrote /work/solve.py (2069 chars).
0:43
Bash
python solve.py
Warning: Could not identify lon/lat columns. Columns found: ['clinic_id', 'name', 'subdistrict', 'wkt_geom'] Successfully created clinic_inventory.json
1:06
Write
/work/solve.py
content · 56 lines · py
import pandas as pd
import json
from shapely import wkt
def main():
file_path = 'capetown_clinics.csv'
try:
df = pd.read_csv(file_path)
except Exception as e:
print(f"Error reading CSV: {e}")
return
# 1. Total count
total_count = len(df)
# 2. Bounding Box from WKT
# The columns are: ['clinic_id', 'name', 'subdistrict', 'wkt_geom']
# We use the 'wkt_geom' column
bbox = None
if 'wkt_geom' in df.columns:
# Convert WKT strings to shapely geometries
geoms = df['wkt_geom'].apply(wkt.loads)
# Get the union or individual bounds
# For a bbox of all points/polygons:
min_x = geoms.map(lambda g: g.bounds[0]).min()
min_y = geoms.map(lambda g: g.bounds[1]).min()
max_x = geoms.map(lambda g: g.bounds[2]).max()
max_y = geoms.map(lambda g: g.bounds[3]).max()
bbox = [min_x, min_y, max_x, max_y]
else:
print("Warning: Could not identify wkt_geom column.")
# 3. Count per subdistrict
subdistrict_col = 'subdistrict'
if subdistrict_col in df.columns:
count_per_subdistrict = df[subdistrict_col].value_counts().to_dict()
else:
count_per_subdistrict = {}
print(f"Warning: Could not identify subdistrict column. Columns found: {df.columns.tolist()}")
# Prepare JSON
inventory = {
"count": int(total_count),
"bbox": bbox,
"count_per_subdistrict": count_per_subdistrict
}
with open('clinic_inventory.json', 'w') as f:
json.dump(inventory, f, indent=4)
print("Successfully created clinic_inventory.json")
if __name__ == "__main__":
main()
Wrote /work/solve.py (1687 chars).
1:08
Bash
python solve.py
Successfully created clinic_inventory.json
1:17
Bash
cat clinic_inventory.json
{
"count": 80,
"bbox": [
18.380309,
-34.073855,
18.819549,
-33.701317
],
"count_per_subdistrict": {
"Western": 12,
"Southern": 12,
"Tygerberg": 11,
"Northern": 10,
"Eastern": 10,
"Klipfontein": 9,
"Mitchells Plain": 8,
"Khayelitsha": 8
}
}
1:26