Spaces:
Sleeping
Sleeping
| 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] |