diff --git a/examples/heatmap/adapter/config.env b/examples/heatmap/adapter/config.env index eb150842a..841c4ae7e 100644 --- a/examples/heatmap/adapter/config.env +++ b/examples/heatmap/adapter/config.env @@ -1,2 +1,2 @@ -export NUMERIC_STREAM_NAME=heatmap_point_weight -export LOCATION_STREAM_NAME=heatmap_point_location \ No newline at end of file +export NUMERIC_STREAM_NAME=heatmap.point.weight +export LOCATION_STREAM_NAME=heatmap.point.location \ No newline at end of file diff --git a/examples/heatmap/adapter/heatmap_client.py b/examples/heatmap/adapter/heatmap_client.py index 2d236b44d..c77b6a256 100644 --- a/examples/heatmap/adapter/heatmap_client.py +++ b/examples/heatmap/adapter/heatmap_client.py @@ -1,50 +1,52 @@ -from turtle import st -from formant.sdk.agent.v1 import Client as AgentClient import os +import datetime import time from random import randint +from formant.sdk.agent.v1 import Client as AgentClient + + +LOCATION_STREAM_NAME = "heatmap.point.location" +NUMERIC_STREAM_NAME = "heatmap.point.weight" +PUBLISH_FREQUENCY = 30 class HeatmapClient: def __init__(self) -> None: - agent_url = "unix:///var/lib/formant/agent.sock" - self.agent_url = os.getenv("AGENT_URL", agent_url) self._geolocation_stream_name = os.getenv( - "LOCATION_STREAM_NAME", "heatmap_point_location" + "LOCATION_STREAM_NAME", LOCATION_STREAM_NAME ) self._numeric_stream_name = os.getenv( - "NUMERIC_STREAM_NAME", "heatmap_point_weight" + "NUMERIC_STREAM_NAME", NUMERIC_STREAM_NAME ) - - self._agent_client = AgentClient( - agent_url=self.agent_url, ignore_throttled=True + self._publish_frequency = os.getenv( + "PUBLISH_FREQUENCY", PUBLISH_FREQUENCY ) + self._agent_client = AgentClient(ignore_throttled=True) - def _publish_to_heatmap(self, latitude, longitud, weight): + def _publish_to_heatmap(self, latitude, longitude, weight): + print(f"{datetime.datetime.now()}\nGeolocation: {latitude}, {longitude}") self._agent_client.post_geolocation( - self._geolocation_stream_name, latitude=latitude, longitude=longitud, + self._geolocation_stream_name, latitude=latitude, longitude=longitude, ) - self._agent_client.post_text("test_alert.level.1.condition", "Alert") if weight % 5 == 0: + print(f"Weight: {weight}") self._agent_client.post_numeric(self._numeric_stream_name, weight) - print("numeric") def run(self): try: while True: - latitude = randint(-8678933143615723, -8678791522979736) - latitude = str(latitude) - start_string = latitude[0:3] + "." + latitude[3:] - latitude = float(start_string) - longitud = randint(3614002351236823, 3615648409409885) - longitud = str(longitud) - longitud = longitud[0:2] + "." + longitud[2:] - longitud = float(longitud) + # Around Fort Collins, CO, where Walter is: + # ~ 40.72, -104.77 + latitude = str(randint(40700000, 40800000)) + latitude = latitude[0:2] + "." + latitude[2:] + latitude = float(latitude) + longitude = str(randint(-104800000, -104700000)) + longitude = longitude[0:4] + "." + longitude[4:] + longitude = float(longitude) weight = randint(1, 50) - time.sleep(1) - print("location") self._publish_to_heatmap( - latitude=longitud, longitud=latitude, weight=weight + latitude=latitude, longitude=longitude, weight=weight ) + time.sleep(self._publish_frequency) except KeyboardInterrupt: pass diff --git a/examples/heatmap/adapter/requirements.txt b/examples/heatmap/adapter/requirements.txt index 8f563b310..6bebab6dd 100644 --- a/examples/heatmap/adapter/requirements.txt +++ b/examples/heatmap/adapter/requirements.txt @@ -1 +1 @@ -formant>=1.76.* \ No newline at end of file +formant>=1.111.* \ No newline at end of file