KSvend Claude Sonnet 4.6 commited on
Commit
5d58ffc
·
1 Parent(s): 4ba0929

feat: filter fires chart data by season_months

Browse files

Pass season_months through to _build_chart_data so only detections in the
selected season are included in the monthly chart output. Adds two unit tests
covering filtered and unfiltered behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

app/indicators/fires.py CHANGED
@@ -37,7 +37,7 @@ class FiresIndicator(BaseIndicator):
37
  status = self._classify(count)
38
  trend = self._compute_trend(rows, time_range)
39
  confidence = self._compute_confidence(rows)
40
- chart_data = self._build_chart_data(rows)
41
 
42
  if count == 0:
43
  headline = "No active fires detected"
@@ -187,13 +187,15 @@ class FiresIndicator(BaseIndicator):
187
  return ConfidenceLevel.LOW
188
 
189
  @staticmethod
190
- def _build_chart_data(rows: list[dict]) -> dict[str, Any]:
191
  monthly: dict[str, int] = defaultdict(int)
192
  for row in rows:
193
  acq = row.get("acq_date", "")
194
  if acq and len(acq) >= 7:
195
  month_key = acq[:7] # "YYYY-MM"
196
- monthly[month_key] += 1
 
 
197
 
198
  sorted_months = sorted(monthly.keys())
199
  return {
 
37
  status = self._classify(count)
38
  trend = self._compute_trend(rows, time_range)
39
  confidence = self._compute_confidence(rows)
40
+ chart_data = self._build_chart_data(rows, season_months)
41
 
42
  if count == 0:
43
  headline = "No active fires detected"
 
187
  return ConfidenceLevel.LOW
188
 
189
  @staticmethod
190
+ def _build_chart_data(rows: list[dict], season_months: list[int] | None = None) -> dict[str, Any]:
191
  monthly: dict[str, int] = defaultdict(int)
192
  for row in rows:
193
  acq = row.get("acq_date", "")
194
  if acq and len(acq) >= 7:
195
  month_key = acq[:7] # "YYYY-MM"
196
+ month_num = int(month_key[5:7])
197
+ if season_months is None or month_num in season_months:
198
+ monthly[month_key] += 1
199
 
200
  sorted_months = sorted(monthly.keys())
201
  return {
tests/test_indicator_fires.py CHANGED
@@ -73,3 +73,19 @@ async def test_fires_indicator_green_when_no_fires(fires_indicator, sample_aoi,
73
 
74
  assert result.status == StatusLevel.GREEN
75
  assert "0" in result.headline or "no" in result.headline.lower()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  assert result.status == StatusLevel.GREEN
75
  assert "0" in result.headline or "no" in result.headline.lower()
76
+
77
+
78
+ def test_build_chart_data_filters_by_season():
79
+ rows = [{"acq_date": f"2025-{m:02d}-15"} for m in range(1, 13) for _ in range(3)]
80
+ season_months = [6, 7, 8, 9]
81
+ result = FiresIndicator._build_chart_data(rows, season_months)
82
+ assert len(result["dates"]) == 4
83
+ assert result["dates"][0] == "2025-06"
84
+ assert result["dates"][-1] == "2025-09"
85
+ assert all(v == 3 for v in result["values"])
86
+
87
+
88
+ def test_build_chart_data_no_season_returns_all():
89
+ rows = [{"acq_date": f"2025-{m:02d}-15"} for m in range(1, 13)]
90
+ result = FiresIndicator._build_chart_data(rows, None)
91
+ assert len(result["dates"]) == 12