forked from smk762/Dragonhound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_GPS.py
executable file
·164 lines (150 loc) · 4.99 KB
/
demo_GPS.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python3
import cherrypy
from cherrypy.lib import auth_digest
import sys
import os
import json
import getconf
import colorTable
import enc
from datetime import datetime
USERS = {'test': 'gps'}
HOME = os.environ['HOME']
CONFIGDIR = str(HOME+'/.DragonhoundDemo/')
HTMLDIR = str(HOME+'/Dragonhound/html/')
def selectRange(low,high, msg):
while True:
try:
number = int(input(msg))
except ValueError:
print("integer only, try again")
continue
if low <= number <= high:
return number
else:
print("input outside range, try again")
def makeLines(trackvar, trackname, points, col, wt, alpha, sf, classname):
trackvar = """var """+trackvar+""" = """+str(points)+""";
var """+trackname+""" = new L.Polyline("""+trackvar+""", {
color: '"""+col+"""',
weight: """+wt+""",
opacity: """+alpha+""",
smoothFactor: """+sf+""",
className: '"""+classname+"""'
});
map.addLayer("""+trackname+""");"""
return trackvar
def makePoint(point, icon, tip, classname, alpha):
pointvar ="""
L.marker("""+str(point)+""", {className: '"""+classname+"""', icon: """+icon+""", opacity: """+alpha+"""}).bindTooltip('"""+tip+"""').addTo(map)
""";
return pointvar
class MapPage:
@cherrypy.expose
def default(self, token):
gpsdata = "";
try:
with open(CONFIGDIR+'gps.pgs', 'r') as file:
pword = file.read()
except IOError as e:
print("Password not set or access denied!")
try:
with open(CONFIGDIR+'orclid.gps', 'r') as file:
ORCLID = file.read()
except IOError as e:
print("Oracle Tx ID not set!")
try:
with open(CONFIGDIR+'chain.gps', 'r') as file:
CHAIN = file.read()
except IOError as e:
print("CHAIN not set!")
chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)
batonutxo=chosen_info['registered'][0]['batontxid']
name=chosen_info['name']
funds='{:.2f}'.format(float(chosen_info['registered'][0]['funds']))
publisher=chosen_info['registered'][0]['publisher']
print("name: "+str(name))
print("funds: "+str(funds))
print("publisher: "+str(publisher))
if float(funds) < 200:
amount = 50
result = getconf.oraclessubscribe_rpc(CHAIN, ORCLID, publisher, amount)
print("oracle funds added!")
chosen_info = getconf.oraclesinfo_rpc(CHAIN, ORCLID)
funds='{:.2f}'.format(float(chosen_info['registered'][0]['funds']))
print("Oracle funds: "+funds)
num = 99
samples = getconf.oraclessamples_rpc(CHAIN, ORCLID, batonutxo, num)
num_samples = len(samples['samples'])
print("num_samples: "+str(num_samples))
leaflet_data = []
points = []
lastpoint =""
lastcharge = ""
bounds =""
view = ""
point_var=""
opac = 0.99;
i = 0;
for sample in samples['samples']:
try:
dec = enc.decrypt(str.encode(sample[0]), pword)
msg = bytes.decode(dec)
msg2 = msg.replace("'","\"")
data = json.loads(msg2)
dataList = data['data'].split(',')
timestamp = data['published_at']
#print('time: '+timestamp)
timestamp = datetime.utcfromtimestamp(float(timestamp)).strftime('%Y-%m-%d %H:%M:%S')+" UTC"
#print('time: '+str(timestamp))
if lastpoint == "":
print("adding last point")
print('time: '+str(timestamp))
print('lon: '+dataList[0])
print('lat: '+dataList[1])
print('c: '+dataList[2])
lastpoint = makePoint([dataList[0],dataList[1]], 'skrunch', str(timestamp), 'lastping', '1')
bounds = ""+str(dataList[0])+","+str(dataList[1])+","+str(dataList[0])+","+str(dataList[1])+""
view = ""+dataList[0]+","+dataList[1]+""
lastcharge = dataList[2]
else:
point_var += makePoint([dataList[0],dataList[1]], 'paw', str(timestamp), 'paws', str(opac) )
leaflet_data.append(json.loads('{"time":"'+timestamp+'", "lat":'+dataList[1]+', "lon":'+dataList[0]+',"charge":'+dataList[2]+'}'))
opac -= 0.01;
points.append([dataList[0],dataList[1]])
except Exception as e:
print(e)
numPoints = len(points)
print("numPoints: "+str(numPoints))
try:
with open(HTMLDIR+'demo.html', 'r') as file:
dh_map = file.read()
dh_map = dh_map.replace('BOUNDS_VAR',bounds)
dh_map = dh_map.replace('SETVEIW_VAR',view)
dh_map = dh_map.replace('CHARGE_VAR',lastcharge)
dh_map = dh_map.replace('POINTS_VAR',point_var)
dh_map = dh_map.replace('LASTPOINT_VAR',lastpoint)
dh_map = dh_map.replace('FUNDS_VAR',funds)
#print(dh_map)
except IOError as e:
print("Password not set or access denied!")
return dh_map
conf = {
'global': {
'server.socket_host': "127.0.0.1",
'server.socket_port': 5050,
'server.thread_pool': 10,
'tools.staticdir.root':'/home/smk762/DragonhoundDemo/'
},
'/DragonhoundDemo': {
'tools.auth_digest.on': True,
'tools.auth_digest.realm': 'localhost',
'tools.auth_digest.get_ha1': auth_digest.get_ha1_dict_plain(USERS),
'tools.auth_digest.key': 'a565c27146791cfb',
'tools.auth_digest.accept_charset': 'UTF-8',
'tools.staticdir.on': True,
'tools.staticdir.dir': 'html',
}
}
if __name__ == '__main__':
cherrypy.quickstart(MapPage(), '/', conf)