Skip to content

Commit

Permalink
add verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
MateoLostanlen committed Nov 21, 2023
1 parent 9c3f834 commit ec912de
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pyroengine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ def __init__(
backup_size: int = 30,
jpeg_quality: int = 80,
day_time_strategy: Optional[str] = None,
verbose: Optional[bool] = True,
**kwargs: Any,
) -> None:
"""Init engine"""
# Engine Setup

self.model = Classifier(model_path)
self.conf_thresh = conf_thresh
self.verbose = verbose

# API Setup
if isinstance(api_url, str):
Expand Down Expand Up @@ -302,7 +304,8 @@ def predict(self, frame: Image.Image, cam_id: Optional[str] = None) -> float:
# Log analysis result
device_str = f"Camera '{cam_id}' - " if isinstance(cam_id, str) else ""
pred_str = "Wildfire detected" if conf > self.conf_thresh else "No wildfire"
logging.info(f"{device_str}{pred_str} (confidence: {conf:.2%})")
if self.verbose:
logging.info(f"{device_str}{pred_str} (confidence: {conf:.2%})")

# Alert
if conf > self.conf_thresh and len(self.api_client) > 0 and isinstance(cam_id, str):
Expand Down Expand Up @@ -347,7 +350,8 @@ def predict(self, frame: Image.Image, cam_id: Optional[str] = None) -> float:

def _upload_frame(self, cam_id: str, media_data: bytes) -> Response:
"""Save frame"""
logging.info(f"Camera '{cam_id}' - Uploading media...")
if self.verbose:
logging.info(f"Camera '{cam_id}' - Uploading media...")
# Create a media
response = self.api_client[cam_id].create_media_from_device()
if response.status_code // 100 == 2:
Expand Down Expand Up @@ -375,7 +379,8 @@ def _process_alerts(self) -> None:
# try to upload the oldest element
frame_info = self._alerts[0]
cam_id = frame_info["cam_id"]
logging.info(f"Camera '{cam_id}' - Sending alert from {frame_info['ts']}...")
if self.verbose:
logging.info(f"Camera '{cam_id}' - Sending alert from {frame_info['ts']}...")

# Save alert on device
self._local_backup(frame_info["frame"], cam_id, is_alert=True)
Expand Down Expand Up @@ -409,7 +414,8 @@ def _process_alerts(self) -> None:
response.json()["id"]
# Clear
self._alerts.popleft()
logging.info(f"Camera '{cam_id}' - alert sent")
if self.verbose:
logging.info(f"Camera '{cam_id}' - alert sent")
stream.seek(0) # "Rewind" the stream to the beginning so we can read its content
except (KeyError, ConnectionError):
logging.warning(f"Camera '{cam_id}' - unable to upload cache")
Expand Down

0 comments on commit ec912de

Please sign in to comment.