-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathplot_locations.py
65 lines (47 loc) · 1.69 KB
/
plot_locations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import logging
import time
import arc852.cli_args as cli
import plotly.graph_objs as go
import plotly.plotly as py
import plotly.tools as tls
from arc852.cli_args import LOG_LEVEL, GRPC_HOST
from arc852.cli_args import setup_cli_args
from arc852.utils import setup_logging
from location_client import LocationClient
logger = logging.getLogger(__name__)
def main():
# Parse CLI args
args = setup_cli_args(cli.grpc_host, cli.log_level)
# Setup logging
setup_logging(level=args[LOG_LEVEL])
# Start location client
with LocationClient(args[GRPC_HOST]) as client:
stream_ids = tls.get_credentials_file()['stream_ids']
stream_id = stream_ids[0]
# Declare graph
graph = go.Scatter(x=[], y=[], mode='lines+markers', stream=dict(token=stream_id, maxpoints=80))
data = go.Data([graph])
layout = go.Layout(title='Target Locations', xaxis=go.XAxis(range=[0, 800]), yaxis=go.YAxis(range=[0, 450]))
fig = go.Figure(data=data, layout=layout)
py.plot(fig, filename='plot-locations')
# Write data
stream = py.Stream(stream_id)
stream.open()
logger.info("Opening plot.ly tab")
time.sleep(5)
try:
while True:
x_val, y_val = client.get_xy()
if x_val[0] == -1 or y_val[0] == -1:
continue
x = x_val[1] - abs(x_val[1] - x_val[0])
y = abs(y_val[1] - y_val[0])
stream.write(dict(x=x, y=y))
time.sleep(.10)
except KeyboardInterrupt:
pass
finally:
stream.close()
logger.info("Exiting...")
if __name__ == "__main__":
main()