safraeli commited on
Commit
a667669
·
verified ·
1 Parent(s): c3a9627

Update backend/api/routes/biology.py

Browse files
Files changed (1) hide show
  1. backend/api/routes/biology.py +21 -9
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 from Air2 (under panels) and Air1 (open field)
87
- df_panels = client.get_timeseries(
88
- "Air2", ["airTemperature"], start=start, end=end,
89
- interval_ms=3_600_000, agg="AVG", limit=10000,
90
- )
91
- df_open = client.get_timeseries(
92
- "Air1", ["airTemperature"], start=start, end=end,
93
- interval_ms=3_600_000, agg="AVG", limit=10000,
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)