Skip to content

Commit

Permalink
remove detectors upload routine (#244)
Browse files Browse the repository at this point in the history
* remove detectors upload mechanism via internal queue

* mark the field tags from rosys.image as deprecated

* review adjustments

* remove obsolete step method

* make sure deprecation warnings are printed

---------

Co-authored-by: Niklas Neugebauer <niklas@zauberzeug.com>
Co-authored-by: Falko Schindler <falko@zauberzeug.com>
  • Loading branch information
3 people authored Jan 20, 2025
1 parent 660021f commit 5f19006
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 63 deletions.
3 changes: 3 additions & 0 deletions rosys/rosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import signal
import threading
import time as pytime
import warnings
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import Any, ClassVar, Literal
Expand All @@ -21,6 +22,8 @@
from .helpers import is_test as is_test_
from .persistence.registry import backup, restore, sync_backup

warnings.filterwarnings('once', category=DeprecationWarning, module='rosys')

log = logging.getLogger('rosys.core')

config = Config()
Expand Down
2 changes: 0 additions & 2 deletions rosys/vision/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ..event import Event
from .detections import Category, Detections
from .image import Image
from .uploads import Uploads


class Autoupload(Enum):
Expand Down Expand Up @@ -93,7 +92,6 @@ def __init__(self, *, name: str | None = None) -> None:
"""detection on an image is completed (argument: image)"""

self.log = logging.getLogger('rosys.detector')
self.uploads = Uploads()

@abc.abstractmethod
async def detect(self,
Expand Down
31 changes: 3 additions & 28 deletions rosys/vision/detector_hardware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from datetime import datetime, timedelta
from datetime import datetime
from typing import Any, Literal

import socketio
Expand Down Expand Up @@ -46,22 +46,17 @@ def on_sio_disconnect() -> None:
def on_sio_connect_error(err) -> None:
self.log.warning('sio connect error on %s: %s', port, err)

rosys.on_repeat(self.step, 1.0)
rosys.on_repeat(self._ensure_connection, 10.0)

@property
def is_connected(self) -> bool:
return self.sio.connected

async def step(self) -> None:
async def _ensure_connection(self) -> None:
if not self.is_connected:
self.log.info('trying reconnect %s', self.name)
if not await self.connect():
self.log.error('connection to %s at port %s failed; trying again', self.name, self.port)
await rosys.sleep(3.0)
return

await self.try_start_one_upload()
await self.upload_priority_queue()

async def connect(self) -> bool:
try:
Expand All @@ -76,25 +71,6 @@ async def connect(self) -> bool:
async def disconnect(self) -> None:
await self.sio.disconnect()

async def try_start_one_upload(self) -> None:
if datetime.now() < self.uploads.last_upload + timedelta(minutes=self.uploads.minimal_minutes_between_uploads):
return

upload_images = self.uploads.get_queued()
if upload_images:
rosys.background_tasks.create(self.upload(upload_images[0]), name='upload_image')
self.uploads.queue.clear() # old images should not be uploaded later when the robot is inactive
self.uploads.last_upload = datetime.now()

async def upload_priority_queue(self) -> None:
upload_images = self.uploads.get_priority_queued()
if upload_images:
async def upload_priority_images():
for image in upload_images:
await self.upload(image)
rosys.background_tasks.create(upload_priority_images(), name='upload_priority_images')
self.uploads.priority_queue.clear()

async def upload(self,
image: Image,
*,
Expand Down Expand Up @@ -125,7 +101,6 @@ async def upload(self,
detections_dict['point_detections'] = detections_dict.pop('points')
detections_dict['segmentation_detections'] = detections_dict.pop('segmentations')
data_dict['detections'] = detections_dict
data_dict['tags'] = list(image.tags.union(tags))
data_dict['source'] = source
data_dict['creation_date'] = _creation_date_to_isoformat(creation_date)
await self.sio.emit('upload', data_dict)
Expand Down
6 changes: 0 additions & 6 deletions rosys/vision/detector_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ def __init__(self,
self.simulated_objects: list[SimulatedObject] = []
self.detection_delay = detection_delay

rosys.on_repeat(self.step, 0.1)

def step(self) -> None:
self.uploads.queue.clear()
self.uploads.priority_queue.clear()

async def detect(self,
image: Image,
*,
Expand Down
6 changes: 6 additions & 0 deletions rosys/vision/image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import warnings
from dataclasses import dataclass, field
from typing import ClassVar

Expand Down Expand Up @@ -34,6 +35,11 @@ class Image:

DEFAULT_PLACEHOLDER_SIZE: ClassVar[tuple[int, int]] = (320, 240)

def __post_init__(self) -> None:
if self.tags:
warnings.warn('The "tags" field is deprecated and will be removed in a future version.',
DeprecationWarning, stacklevel=2)

@property
def detections(self) -> Detections | None:
if not self._detections:
Expand Down
27 changes: 0 additions & 27 deletions rosys/vision/uploads.py

This file was deleted.

0 comments on commit 5f19006

Please sign in to comment.