Skip to content

Commit

Permalink
apply pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarriba committed Oct 2, 2023
1 parent 915aee7 commit 0a9af28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
21 changes: 11 additions & 10 deletions py/examples/multi_client_geoimage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@
from pathlib import Path

from farm_ng.core.event_client import EventClient
from farm_ng.core.event_service_pb2 import EventServiceConfig, EventServiceConfigList, SubscribeRequest
from farm_ng.core.event_service_pb2 import EventServiceConfig
from farm_ng.core.event_service_pb2 import EventServiceConfigList
from farm_ng.core.event_service_pb2 import SubscribeRequest
from farm_ng.core.events_file_reader import proto_from_json_file
from farm_ng.core.stamp import get_stamp_by_semantics_and_clock_type, StampSemantics
from farm_ng.oak import oak_pb2
from farm_ng.core.stamp import get_stamp_by_semantics_and_clock_type
from farm_ng.gps import gps_pb2
from farm_ng.oak import oak_pb2


class GeoTaggedImageSubscriber:
"""Example of subscribing to events from multiple clients."""

def __init__(self, service_config: EventServiceConfigList) -> None:
"""Initialize the multi-client subscriber.
Args:
service_config: The service config.
"""
Expand All @@ -42,10 +45,10 @@ def __init__(self, service_config: EventServiceConfigList) -> None:
self.subscriptions = config.subscriptions
continue
self.clients[config.name] = EventClient(config)

# create a queue to store the images since they come in faster than we can process them
self.image_queue: asyncio.Queue = asyncio.Queue()

async def _subscribe(self, subscription: SubscribeRequest) -> None:
# the client name is the last part of the query
client_name: str = subscription.uri.query.split("=")[-1]
Expand Down Expand Up @@ -81,7 +84,7 @@ async def _subscribe(self, subscription: SubscribeRequest) -> None:
print(f"Synced image and gps data with stamp_diff: {stamp_diff}")
geo_image = ((event_image, image), (event, message))
break

if geo_image is None:
print("Could not sync image and gps data")
continue
Expand All @@ -103,9 +106,7 @@ async def run(self) -> None:
args = parser.parse_args()

# create a client to the camera service
service_config: EventServiceConfigList = proto_from_json_file(
args.config, EventServiceConfigList()
)
service_config: EventServiceConfigList = proto_from_json_file(args.config, EventServiceConfigList())

# create the multi-client subscriber
subscriber = GeoTaggedImageSubscriber(service_config)
Expand Down
15 changes: 8 additions & 7 deletions py/examples/multi_client_subscriber/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
from pathlib import Path

from farm_ng.core.event_client import EventClient
from farm_ng.core.event_service_pb2 import EventServiceConfig, EventServiceConfigList, SubscribeRequest
from farm_ng.core.event_service_pb2 import EventServiceConfig
from farm_ng.core.event_service_pb2 import EventServiceConfigList
from farm_ng.core.event_service_pb2 import SubscribeRequest
from farm_ng.core.events_file_reader import proto_from_json_file


class MultiClientSubscriber:
"""Example of subscribing to events from multiple clients."""

def __init__(self, service_config: EventServiceConfigList) -> None:
"""Initialize the multi-client subscriber.
Args:
service_config: The service config.
"""
Expand All @@ -39,7 +42,7 @@ def __init__(self, service_config: EventServiceConfigList) -> None:
self.subscriptions = config.subscriptions
continue
self.clients[config.name] = EventClient(config)

async def _subscribe(self, subscription: SubscribeRequest) -> None:
# the client name is the last part of the query
client_name: str = subscription.uri.query.split("=")[-1]
Expand All @@ -50,7 +53,7 @@ async def _subscribe(self, subscription: SubscribeRequest) -> None:
# decode the message type
message_type = event.uri.query.split("&")[0].split("=")[-1]
print(f"Received event from {client_name}{event.uri.path}: {message_type}")

async def run(self) -> None:
# start the subscribe routines
tasks: list[asyncio.Task] = []
Expand All @@ -68,9 +71,7 @@ async def run(self) -> None:
args = parser.parse_args()

# create a client to the camera service
service_config: EventServiceConfigList = proto_from_json_file(
args.config, EventServiceConfigList()
)
service_config: EventServiceConfigList = proto_from_json_file(args.config, EventServiceConfigList())

# create the multi-client subscriber
subscriber = MultiClientSubscriber(service_config)
Expand Down

0 comments on commit 0a9af28

Please sign in to comment.