-
Notifications
You must be signed in to change notification settings - Fork 5
Heatmap demo Colorado #61
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
Open
nbinford-formant
wants to merge
8
commits into
master
Choose a base branch
from
heatmap-demo-ca
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+29
−27
Open
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
10a7a2f
Geolocation that is easier to see in a demo
nbinford-formant 539bb7a
Line spacing
nbinford-formant 4e84093
Change geolocation to where Walter is
nbinford-formant 1e979e0
Change Formant stream names
nbinford-formant 7bbccd1
Change Formant stream names part 2
nbinford-formant c69ed83
Clean up and make more generic
nbinford-formant 6e3b1a5
Remove agent URL requirement
nbinford-formant b2e9fcd
Forgot one line
nbinford-formant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
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 | ||
|
||
|
||
AGENT_URL = "unix:///var/lib/formant/agent.sock" | ||
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.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._publish_frequency = os.getenv( | ||
"PUBLISH_FREQUENCY", PUBLISH_FREQUENCY | ||
) | ||
|
||
self._agent_client = AgentClient( | ||
agent_url=self.agent_url, ignore_throttled=True | ||
nbinford-formant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.