diff --git a/app/history.py b/app/history.py index 3ddb09a..39dd57e 100644 --- a/app/history.py +++ b/app/history.py @@ -1,5 +1,6 @@ import asyncio import base64 +import logging from collections import Counter from datetime import datetime from io import BytesIO @@ -12,6 +13,8 @@ from app.config import settings from model.detect import Detection, DetectionResult +logging.basicConfig(level=logging.INFO) + class HistorySaveRequest(BaseModel): localDateTime: str @@ -33,10 +36,13 @@ def summary_detections(): counter = Counter(list(map(lambda d: d.class_name, detections))) return ' '.join(f'{k} {v}' for k, v in counter.items()) - super().__init__(localDateTime=datetime.now().isoformat(), label=summary_detections(), base64Image=convert_base64()) + super().__init__(localDateTime=datetime.now().isoformat(), label=summary_detections(), + base64Image=convert_base64()) async def async_save_history(result: DetectionResult): + logging.info("이상상황이 발생하여 이력을 저장합니다") + asyncio.create_task( save_history(HistorySaveRequest(image=result.get_image(), detections=result.detections)) )