Spaces:
Runtime error
Runtime error
Download database/check_db.py from Rathesh07/speed_camera_detector: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/spaces/Rathesh07/speed_camera_detector/resolve/main/database/check_db.py
- Command line
-
hf download hf://spaces/Rathesh07/speed_camera_detector/database/check_db.py
-
curl -L -o check_db.py https://huggingface.co/spaces/Rathesh07/speed_camera_detector/resolve/main/database/check_db.py
1.49 kB
| import asyncio | |
| import sys | |
| from pathlib import Path | |
| from sqlalchemy import select, text | |
| from database.database import AsyncSessionLocal | |
| from database.models import SchoolZone, HospitalZone | |
| # Add parent directory to path | |
| sys.path.insert(0, str(Path(__file__).parent.parent)) | |
| async def check(): | |
| from geoalchemy2 import functions as func | |
| from geoalchemy2.types import Geometry | |
| from sqlalchemy import cast | |
| async with AsyncSessionLocal() as db: | |
| print("Checking School Zones...") | |
| # Get a random school with coordinates | |
| result = await db.execute( | |
| select( | |
| SchoolZone.name, | |
| func.ST_Y(cast(SchoolZone.location, Geometry)).label('lat'), | |
| func.ST_X(cast(SchoolZone.location, Geometry)).label('lon') | |
| ).limit(1) | |
| ) | |
| school = result.first() | |
| if school: | |
| print(f"Sample School: {school.name} at {school.lat}, {school.lon}") | |
| # Get a random hospital | |
| result = await db.execute( | |
| select( | |
| HospitalZone.name, | |
| func.ST_Y(cast(HospitalZone.location, Geometry)).label('lat'), | |
| func.ST_X(cast(HospitalZone.location, Geometry)).label('lon') | |
| ).limit(1) | |
| ) | |
| hospital = result.first() | |
| if hospital: | |
| print(f"Sample Hospital: {hospital.name} at {hospital.lat}, {hospital.lon}") | |
| if __name__ == "__main__": | |
| asyncio.run(check()) | |