added covarage

This commit is contained in:
2026-06-24 07:50:00 +03:00
parent 89ca1ee945
commit bc9b70764d
41 changed files with 1306 additions and 79 deletions
+58 -2
View File
@@ -1,11 +1,67 @@
from __future__ import annotations
from app.config import get_settings
from app.core.coverage import compute_coverage as run_coverage
from app.core.viewshed import compute_viewshed as run_viewshed
from app.models.coverage import CoverageRequest
from app.models.viewshed import ViewshedRequest
from app.services.jobs import get_job_record, update_job
from app.workers.celery_app import celery_app
@celery_app.task(name="coverage.compute")
def compute_coverage(job_id: str) -> dict[str, str]:
return {"job_id": job_id, "status": "not_implemented"}
record = get_job_record(job_id)
if record is None:
return {"job_id": job_id, "status": "error", "error": "job not found"}
settings = get_settings()
try:
update_job(job_id, status="running")
request = CoverageRequest.model_validate(record["payload"])
result = run_coverage(request, dem_path=str(settings.dem_path))
update_job(
job_id,
status="done",
result={
"kind": "coverage",
"model": request.model,
"format": request.format,
"data": result,
},
)
return {"job_id": job_id, "status": "done"}
except Exception as exc:
update_job(job_id, status="error", error=str(exc))
return {"job_id": job_id, "status": "error", "error": str(exc)}
@celery_app.task(name="viewshed.compute")
def compute_viewshed(job_id: str) -> dict[str, str]:
return {"job_id": job_id, "status": "not_implemented"}
record = get_job_record(job_id)
if record is None:
return {"job_id": job_id, "status": "error", "error": "job not found"}
settings = get_settings()
try:
update_job(job_id, status="running")
request = ViewshedRequest.model_validate(record["payload"])
raster = run_viewshed(
request,
dem_path=settings.dem_path,
output_dir=settings.jobs_output_path,
gdal_viewshed_bin=settings.gdal_viewshed_bin,
)
update_job(
job_id,
status="done",
result={
"kind": "viewshed",
"uri": raster.uri,
"metadata": raster.metadata,
},
)
return {"job_id": job_id, "status": "done"}
except Exception as exc:
update_job(job_id, status="error", error=str(exc))
return {"job_id": job_id, "status": "error", "error": str(exc)}