Skip to content
Open
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
4 changes: 2 additions & 2 deletions examples/heatmap/adapter/config.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export NUMERIC_STREAM_NAME=heatmap_point_weight
export LOCATION_STREAM_NAME=heatmap_point_location
export NUMERIC_STREAM_NAME=heatmap.point.weight
export LOCATION_STREAM_NAME=heatmap.point.location
50 changes: 26 additions & 24 deletions examples/heatmap/adapter/heatmap_client.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/heatmap/adapter/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
formant>=1.76.*
formant>=1.111.*