refactor(crowd_analysis): simplify table + upgrade YOLO + add regional holidays

- Remove internal YOLO counts (cars/people/buses/total_vehicles) from crowd_analysis table
- Keep only crowd_density and confidence_scores for persistence (no ML training impact)
- Upgrade from YOLOv8n to YOLOv11m for better person detection (fewer false positives)
- Add regional holidays: Día de Castilla y León (4/23), Santiago Apóstol (7/25, shared with Galicia)
- Add Easter Monday (moveable, 2018-2035) for Castilla y León and Galicia
- Update all tests to match simplified crowd_analysis schema

Tests: all 38 SQLite/crowd_analyzer tests + 13 feature tests passing.
This commit is contained in:
dasemu committed 2026-03-13 18:03:15 +01:00
1 parent fa7d61b7db
commit 5e2a22340f
5 files changed
+25 -78

No files matched your search

+1 -38
View File
@@ -274,31 +274,6 @@ class TestAnalyzeImage:
return analyzer.analyze_image(str(img_path))
def test_counts_cars_correctly(self, tmp_path):
"""Three cars in detections must produce cars_detected=3."""
result = self._run(tmp_path, ["car", "car", "car"], [0.9, 0.85, 0.8])
assert result["cars_detected"] == 3
def test_counts_people_correctly(self, tmp_path):
"""Two people detections must produce people_detected=2."""
result = self._run(tmp_path, ["person", "person"], [0.95, 0.88])
assert result["people_detected"] == 2
def test_counts_buses_correctly(self, tmp_path):
"""One bus detection must produce buses_detected=1."""
result = self._run(tmp_path, ["bus"], [0.7])
assert result["buses_detected"] == 1
def test_total_vehicles_excludes_people(self, tmp_path):
"""total_vehicles must count cars + buses + trucks, not people."""
result = self._run(
tmp_path,
["car", "person", "bus", "truck"],
[0.9, 0.9, 0.8, 0.75],
)
assert result["total_vehicles"] == 3 # car + bus + truck
assert result["people_detected"] == 1
def test_confidence_scores_are_included(self, tmp_path):
"""All detection confidence scores must be present in the result."""
result = self._run(tmp_path, ["car", "person"], [0.91, 0.82])
@@ -308,15 +283,7 @@ class TestAnalyzeImage:
def test_result_has_required_keys(self, tmp_path):
"""analyze_image must return all documented keys."""
result = self._run(tmp_path, [], [])
required = {
"cars_detected",
"people_detected",
"buses_detected",
"total_vehicles",
"crowd_density",
"confidence_scores",
"timestamp",
}
required = {"crowd_density", "confidence_scores", "timestamp"}
assert required.issubset(result.keys())
def test_crowd_density_is_valid_string(self, tmp_path):
@@ -455,10 +422,6 @@ class TestAnalyzeAllStations:
return {
"station_id": station_id,
"crowd_density": "low",
"cars_detected": 0,
"people_detected": 0,
"buses_detected": 0,
"total_vehicles": 0,
"confidence_scores": [],
"timestamp": "2026-01-01T12:00:00",
"image_path": None,
-8
View File
@@ -107,10 +107,6 @@ def test_crowd_analysis_roundtrip(tmp_path):
"timestamp": "2026-03-13T11:00:00",
"station_id": "sanisidro",
"image_path": "/tmp/frame.jpg",
"cars_detected": 5,
"people_detected": 2,
"buses_detected": 0,
"total_vehicles": 5,
"crowd_density": "low",
"confidence_scores": [0.91, 0.88],
}
@@ -120,10 +116,6 @@ def test_crowd_analysis_roundtrip(tmp_path):
"timestamp": "2026-03-13T12:00:00",
"station_id": "sanisidro",
"image_path": "/tmp/frame2.jpg",
"cars_detected": 25,
"people_detected": 4,
"buses_detected": 1,
"total_vehicles": 26,
"crowd_density": "medium",
"confidence_scores": [0.77],
}