Skip to content

Commit

Permalink
feature: outbox
Browse files Browse the repository at this point in the history
add optional creation date and check if it is a valid date
  • Loading branch information
denniswittich committed Nov 8, 2024
1 parent 87cd3f5 commit 0091ac2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions learning_loop_node/detector/outbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def save(self,
image: bytes,
detections: Optional[ImageMetadata] = None,
tags: Optional[List[str]] = None,
source: Optional[str] = None
source: Optional[str] = None,
creation_date: Optional[str] = None
) -> None:

if not self._is_valid_jpg(image):
Expand All @@ -75,7 +76,10 @@ def save(self,
return
tmp = f'{GLOBALS.data_folder}/tmp/{identifier}'
detections.tags = tags
detections.date = identifier
if creation_date and self._is_valid_isoformat(creation_date):
detections.date = creation_date
else:
detections.date = identifier
detections.source = source or 'unknown'
os.makedirs(tmp, exist_ok=True)

Expand All @@ -90,6 +94,13 @@ def save(self,
else:
self.log.error('Could not rename %s to %s', tmp, self.path + '/' + identifier)

def _is_valid_isoformat(self, date: str) -> bool:
try:
datetime.fromisoformat(date)
return True
except Exception:
return False

def get_data_files(self):
return glob(f'{self.path}/*')

Expand Down

0 comments on commit 0091ac2

Please sign in to comment.