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:13
Bash
ls -F
capetown_clinics.csv
0:23
Bash
head -n 5 capetown_clinics.csv
clinic_id,name,subdistrict,wkt_geom 1,Mokoena Western Clinic,Western,POINT(18.478309 -33.888756) 2,Ndlovu Western Clinic,Western,POINT(18.421127 -33.924929) 3,Pieterse Western Clinic,Western,POINT(18.389237 -33.976099) 4,van der Merwe Western Clinic,Western,POINT(18.47354 -33.890933)
0:41
Write
/work/solve.py
content · 40 lines · py
import pandas as pd
import json
from shapely import wkt
def main():
# Load the data
df = pd.read_csv('capetown_clinics.csv')
# Convert wkt_geom to shapely geometries
df['geometry'] = df['wkt_geom'].apply(wkt.loads)
# Total clinic count
total_count = len(df)
# Bounding box
# Concatenate all geometries to find the total bounds
# A simpler way is to extract min/max x and y
min_x = df['geometry'].map(lambda g: g.bounds[0]).min()
min_y = df['geometry'].map(lambda g: g.bounds[1]).min()
max_x = df['geometry'].map(lambda g: g.bounds[2]).max()
max_y = df['geometry'].map(lambda g: g.bounds[3]).max()
bbox = [min_x, min_y, max_x, max_y]
# Count per subdistrict
count_per_subdistrict = df['subdistrict'].value_counts().to_dict()
# Prepare JSON data
inventory = {
"count": total_count,
"bbox": bbox,
"count_per_subdistrict": count_per_subdistrict
}
# Write to file
with open('clinic_inventory.json', 'w') as f:
json.dump(inventory, f, indent=4)
if __name__ == "__main__":
main()
Wrote /work/solve.py (1101 chars).
0:43
Bash
python solve.py
(no output)
0:48
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:12