Update backend/api/routes/biology.py
Browse files
backend/api/routes/biology.py
CHANGED
|
@@ -83,15 +83,27 @@ async def biology_chill_units(
|
|
| 83 |
start = pd.Timestamp(season_start, tz="UTC")
|
| 84 |
end = pd.Timestamp(datetime.now(timezone.utc))
|
| 85 |
|
| 86 |
-
# Fetch hourly avg temp
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
panels_data, panels_total = _compute_chill(df_panels)
|
| 97 |
open_data, open_total = _compute_chill(df_open)
|
|
|
|
| 83 |
start = pd.Timestamp(season_start, tz="UTC")
|
| 84 |
end = pd.Timestamp(datetime.now(timezone.utc))
|
| 85 |
|
| 86 |
+
# Fetch hourly avg temp in 30-day chunks (TB rejects large ranges)
|
| 87 |
+
def _fetch_chunked(device, start, end):
|
| 88 |
+
import pandas as _pd
|
| 89 |
+
chunks = []
|
| 90 |
+
cursor = start
|
| 91 |
+
while cursor < end:
|
| 92 |
+
chunk_end = min(cursor + pd.Timedelta(days=30), end)
|
| 93 |
+
try:
|
| 94 |
+
chunk = client.get_timeseries(
|
| 95 |
+
device, ["airTemperature"], start=cursor, end=chunk_end,
|
| 96 |
+
interval_ms=3_600_000, agg="AVG", limit=5000,
|
| 97 |
+
)
|
| 98 |
+
if not chunk.empty:
|
| 99 |
+
chunks.append(chunk)
|
| 100 |
+
except Exception:
|
| 101 |
+
pass
|
| 102 |
+
cursor = chunk_end
|
| 103 |
+
return _pd.concat(chunks) if chunks else _pd.DataFrame()
|
| 104 |
+
|
| 105 |
+
df_panels = _fetch_chunked("Air2", start, end)
|
| 106 |
+
df_open = _fetch_chunked("Air1", start, end)
|
| 107 |
|
| 108 |
panels_data, panels_total = _compute_chill(df_panels)
|
| 109 |
open_data, open_total = _compute_chill(df_open)
|