safraeli commited on
Commit
bdffbe8
·
verified ·
1 Parent(s): 86e8290

Fix phenology: add date param + unpack tuple return

Browse files
Files changed (1) hide show
  1. backend/api/routes/biology.py +12 -7
backend/api/routes/biology.py CHANGED
@@ -3,9 +3,9 @@
3
  from __future__ import annotations
4
 
5
  import logging
 
6
 
7
- from fastapi import APIRouter, Depends
8
- from fastapi.responses import JSONResponse
9
 
10
  from backend.api.deps import get_datahub
11
  from src.data.data_providers import DataHub
@@ -15,15 +15,20 @@ router = APIRouter()
15
 
16
 
17
  @router.get("/phenology")
18
- async def phenology(hub: DataHub = Depends(get_datahub)):
19
  """Current phenological stage (GDD-based)."""
20
  try:
21
  from src.models.phenology import estimate_stage_combined
22
- stage = estimate_stage_combined()
23
- return {"stage": stage.name if hasattr(stage, "name") else str(stage)}
 
 
 
 
 
24
  except Exception as exc:
25
- log.error("Phenology estimation failed: %s", exc)
26
- return JSONResponse(status_code=500, content={"error": "Phenology estimation failed"})
27
 
28
 
29
  @router.get("/rules")
 
3
  from __future__ import annotations
4
 
5
  import logging
6
+ from datetime import date
7
 
8
+ from fastapi import APIRouter, Depends, HTTPException
 
9
 
10
  from backend.api.deps import get_datahub
11
  from src.data.data_providers import DataHub
 
15
 
16
 
17
  @router.get("/phenology")
18
+ async def phenology():
19
  """Current phenological stage (GDD-based)."""
20
  try:
21
  from src.models.phenology import estimate_stage_combined
22
+ stage, metadata = estimate_stage_combined(d=date.today())
23
+ return {
24
+ "stage": stage.id,
25
+ "label": stage.label,
26
+ "description": stage.description,
27
+ "method": metadata.get("method", "calendar"),
28
+ }
29
  except Exception as exc:
30
+ log.error("Phenology estimation failed: %s", exc, exc_info=True)
31
+ raise HTTPException(status_code=500, detail=f"Phenology estimation failed: {exc}")
32
 
33
 
34
  @router.get("/rules")