Spaces:
Sleeping
Sleeping
Download api/monitoring/metadata.py from donizetti-yoann/agritech-api: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/donizetti-yoann/agritech-api/resolve/main/api/monitoring/metadata.py
- Command line
-
hf download hf://spaces/donizetti-yoann/agritech-api/api/monitoring/metadata.py
-
curl -L -o metadata.py https://huggingface.co/spaces/donizetti-yoann/agritech-api/resolve/main/api/monitoring/metadata.py
1.12 kB
| from src.api.monitoring.db import get_connection | |
| def load_crops_by_area_from_db(): | |
| query = """ | |
| SELECT area, item | |
| FROM country_crop_mapping | |
| ORDER BY area, item; | |
| """ | |
| crops_by_area = {} | |
| with get_connection() as conn: | |
| with conn.cursor() as cursor: | |
| cursor.execute(query) | |
| rows = cursor.fetchall() | |
| for area, item in rows: | |
| crops_by_area.setdefault(item, []).append(area) | |
| return crops_by_area | |
| def get_available_areas(): | |
| query = """ | |
| SELECT DISTINCT area | |
| FROM country_crop_mapping | |
| ORDER BY area; | |
| """ | |
| with get_connection() as conn: | |
| with conn.cursor() as cursor: | |
| cursor.execute(query) | |
| rows = cursor.fetchall() | |
| return [row[0] for row in rows] | |
| def get_available_crops_by_area(area): | |
| query = """ | |
| SELECT item | |
| FROM country_crop_mapping | |
| WHERE area = %s | |
| ORDER BY item; | |
| """ | |
| with get_connection() as conn: | |
| with conn.cursor() as cursor: | |
| cursor.execute(query, (area,)) | |
| rows = cursor.fetchall() | |
| return [row[0] for row in rows] |