diff --git a/algorithms.py b/algorithms.py index 1b39fbc..69c6e83 100644 --- a/algorithms.py +++ b/algorithms.py @@ -747,8 +747,8 @@ class IllegalParkingAlgorithm: self, confirm_vehicle_sec: int = 15, parking_countdown_sec: int = 300, - confirm_clear_sec: int = 30, - cooldown_sec: int = 600, + confirm_clear_sec: int = 120, + cooldown_sec: int = 1800, target_classes: Optional[List[str]] = None, alarm_level: Optional[int] = None, ): @@ -905,10 +905,10 @@ class IllegalParkingAlgorithm: logger.debug(f"ROI {roi_id}: PARKED_COUNTDOWN → IDLE (冷却期内)") elif self.state == self.STATE_ALARMED: - if ratio < 0.3: + if ratio < 0.15: self.state = self.STATE_CONFIRMING_CLEAR self.state_start_time = current_time - logger.debug(f"ROI {roi_id}: ALARMED → CONFIRMING_CLEAR") + logger.debug(f"ROI {roi_id}: ALARMED → CONFIRMING_CLEAR (ratio={ratio:.2f}<0.15)") elif self.state == self.STATE_CONFIRMING_CLEAR: if self.state_start_time is None: @@ -1002,8 +1002,8 @@ class VehicleCongestionAlgorithm: self, count_threshold: int = 5, confirm_congestion_sec: int = 60, - confirm_clear_sec: int = 120, - cooldown_sec: int = 600, + confirm_clear_sec: int = 180, + cooldown_sec: int = 1800, target_classes: Optional[List[str]] = None, alarm_level: Optional[int] = None, ): @@ -1140,10 +1140,11 @@ class VehicleCongestionAlgorithm: logger.debug(f"ROI {roi_id}: CONFIRMING_CONGESTION → NORMAL (冷却期内)") elif self.state == self.STATE_CONGESTED: - if avg_count < self.count_threshold: + # 车辆数降到阈值的一半以下才开始确认消散(避免抖动) + if avg_count < self.count_threshold * 0.5: self.state = self.STATE_CONFIRMING_CLEAR self.state_start_time = current_time - logger.debug(f"ROI {roi_id}: CONGESTED → CONFIRMING_CLEAR (avg={avg_count:.1f}<{self.count_threshold})") + logger.debug(f"ROI {roi_id}: CONGESTED → CONFIRMING_CLEAR (avg={avg_count:.1f}<{self.count_threshold * 0.5:.1f})") elif self.state == self.STATE_CONFIRMING_CLEAR: if self.state_start_time is None: