Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix custom creation date #42

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion learning_loop_node/data_classes/image_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ImageMetadata():
tags: List[str] = field(default_factory=list, metadata={
'description': 'List of tags'})

date: Optional[str] = field(default_factory=current_datetime, metadata={
created: Optional[str] = field(default_factory=current_datetime, metadata={
'description': 'Creation date of the image'})
source: Optional[str] = field(default=None, metadata={
'description': 'Source of the image'})
Expand Down
5 changes: 3 additions & 2 deletions learning_loop_node/detector/detector_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def setup_sio_server(self) -> None:

@self.sio.event
async def detect(sid, data: Dict) -> Dict:
self.log.debug('running detect via socketio')
try:
np_image = np.frombuffer(data['image'], np.uint8)
det = await self.get_detections(
Expand All @@ -153,7 +152,6 @@ async def detect(sid, data: Dict) -> Dict:
if det is None:
return {'error': 'no model loaded'}
detection_dict = jsonable_encoder(asdict(det))
self.log.debug('detect via socketio finished')
return detection_dict
except Exception as e:
self.log.exception('could not detect via socketio')
Expand Down Expand Up @@ -188,6 +186,9 @@ async def upload(sid, data: Dict) -> Optional[Dict]:
source = data.get('source', None)
creation_date = data.get('creation_date', None)

self.log.debug('running upload via socketio. tags: %s, source: %s, creation_date: %s',
tags, source, creation_date)

loop = asyncio.get_event_loop()
try:
await loop.run_in_executor(None, self.outbox.save, data['image'], image_metadata, tags, source, creation_date)
Expand Down
13 changes: 8 additions & 5 deletions learning_loop_node/detector/outbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ def save(self,
return
tmp = f'{GLOBALS.data_folder}/tmp/{identifier}'
image_metadata.tags = tags
if creation_date and self._is_valid_isoformat(creation_date):
image_metadata.date = creation_date
if self._is_valid_isoformat(creation_date):
image_metadata.created = creation_date
else:
image_metadata.date = identifier
image_metadata.created = identifier

image_metadata.source = source or 'unknown'
os.makedirs(tmp, exist_ok=True)

Expand All @@ -94,7 +95,9 @@ 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:
def _is_valid_isoformat(self, date: Optional[str]) -> bool:
if date is None:
return False
try:
datetime.fromisoformat(date)
return True
Expand Down Expand Up @@ -153,7 +156,7 @@ async def _upload_batch(self, items: List[str]):
self.log.exception('Could not upload images')
return
finally:
self.log.info('Closing files')
self.log.debug('Closing files')
for _, file in data:
file.close()

Expand Down
6 changes: 3 additions & 3 deletions learning_loop_node/loop_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self) -> None:
else:
self.async_client = httpx.AsyncClient(base_url=self.base_url, timeout=Timeout(60.0))

logging.info(f'Loop interface initialized with base_url: {self.base_url} / user: {self.username}')
logging.info('Loop interface initialized with base_url: %s / user: %s', self.base_url, self.username)

def websocket_url(self) -> str:
return f'ws{"s" if "learning-loop.ai" in self.host else ""}://' + self.host
Expand All @@ -48,7 +48,7 @@ async def ensure_login(self, relogin=False) -> None:
self.async_client.cookies.clear()
response = await self.async_client.post('/api/login', data={'username': self.username, 'password': self.password})
if response.status_code != 200:
logging.info(f'Login failed with response: {response}')
logging.info('Login failed with response: %s', response)
raise LoopCommunicationException('Login failed with response: ' + str(response))
self.async_client.cookies.update(response.cookies)

Expand All @@ -57,7 +57,7 @@ async def logout(self) -> None:

response = await self.async_client.post('/api/logout')
if response.status_code != 200:
logging.info(f'Logout failed with response: {response}')
logging.info('Logout failed with response: %s', response)
raise LoopCommunicationException('Logout failed with response: ' + str(response))
self.async_client.cookies.clear()

Expand Down
2 changes: 1 addition & 1 deletion mock_detector/app_code/tests/test_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ async def test_sio_detect(test_detector_node: DetectorNode, sio):
assert response['point_detections'] == []
assert response['segmentation_detections'] == []
assert response['tags'] == []
assert 'date' in response
assert 'created' in response
Loading