Commit a046c0b4 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

admin device geolocation added

parent 3f724b8e
......@@ -996,3 +996,108 @@ Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2131, in make_response
" {rv.__class__.__name__}.".format(rv=rv)
TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a list.
[2020-07-04 14:03:59,011] ERROR in app: Exception on /administration/admin/recent-activity [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/views_admin.py", line 530, in administration_user_recent_activity
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(ddm.read_data(r[3], dev[3]))+'</th></tr>'
File "./app/helpers/device_data_model.py", line 147, in read_data
return json.loads(data.decode('utf-8'))
AttributeError: 'memoryview' object has no attribute 'decode'
[2020-07-04 14:04:20,424] ERROR in app: Exception on /recent-activity [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/views.py", line 363, in recent_activity
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(ddm.read_data(r[3], dev[3]))+'</th></tr>'
File "./app/helpers/device_data_model.py", line 147, in read_data
return json.loads(data.decode('utf-8'))
AttributeError: 'memoryview' object has no attribute 'decode'
[2020-07-04 14:05:01,799] ERROR in app: Exception on /administration/admin/recent-activity [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/views_admin.py", line 530, in administration_user_recent_activity
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(ddm.read_data(r[3], dev[3]))+'</th></tr>'
File "./app/helpers/device_data_model.py", line 147, in read_data
return json.loads(data.decode('utf-8'))
AttributeError: 'memoryview' object has no attribute 'decode'
[2020-07-04 14:06:11,555] ERROR in app: Exception on /recent-activity [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/views.py", line 363, in recent_activity
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(ddm.read_data(r[3], dev[3]))+'</th></tr>'
File "./app/helpers/device_data_model.py", line 147, in read_data
return json.loads(data.decode('utf-8'))
AttributeError: 'memoryview' object has no attribute 'decode'
[2020-07-04 14:06:28,348] ERROR in app: Exception on /recent-activity [GET]
Traceback (most recent call last):
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/home/pi/thso.server/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "./app/helpers/decorators.py", line 23, in restricted_function
return f(*args, **kwargs)
File "./app/views.py", line 363, in recent_activity
ra += '<tr><th scope="row">'+r[1]+'</th><th>'+r[2]+'</th><th>'+r[0]+'</th><th>'+str(ddm.read_data(r[3], dev[3]))+'</th></tr>'
File "./app/helpers/device_data_model.py", line 147, in read_data
return json.loads(data.decode('utf-8'))
AttributeError: 'memoryview' object has no attribute 'decode'
......@@ -4,6 +4,9 @@
{% block header %}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
{% endblock %}
{% block location %}
......@@ -80,19 +83,27 @@
<p class="card-text">{{ dev[2] }}</p>
</div>
</div>
{% if total > 0 and 'lat' in dev[3]['format'] and 'lon' in dev[3]['format'] %}
<div class="card shadow border-0">
<div id="map" class="map" style="height: 200px;"></div>
</div>
{% endif %}
</div>
{% if total > 0 %}
<div>
<ul class="nav nav-pills" id="pills-tab" role="tablist">
{% for k in dev[3]['format'] %}
{% if k != 'lat' and k != 'lon' %}
<li class="nav-item col-lg-3 col-md-6" role="presentation">
<a class="nav-link" id="tab_{{ k }}" data-toggle="pill" href="#{{ k }}" role="tab" aria-controls="{{ k }}" aria-selected="true" onclick="display_data('{{ k }}')">{{ k }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
<div class="tab-content" id="pills-tabContent">
{% for k in dev[3]['format'] %}
{% if k != 'lat' and k != 'lon' %}
<div class="tab-pane fade card" id="{{ k }}" style="margin-top: 30px;" role="tabpanel" aria-labelledby="tab_{{ k }}">
<div class="card-body">
<h3 class="mb-0 card-header">Last 24 hours data</h3>
......@@ -113,6 +124,7 @@
{% endif %}
</div>
</div>
{% endif %}
{% endfor %}
</div>
</div>
......@@ -211,5 +223,27 @@
);
}
</script>
{% if 'lat' in dev[3]['format'] and 'lon' in dev[3]['format'] %}
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin="">
</script>
<script type="text/javascript">
fetch('/administration/{{ user }}/application/{{ app[1] }}/device/{{ dev[1] }}/geo').then(res => res.text()).then(function (data)
{
var coord = eval(data);
var devmap = L.map('map').setView(coord, 15);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18
}).addTo(devmap);
var devmarker = L.marker(coord).addTo(devmap);
devmarker.bindPopup("{{ dev[0] }}").openPopup();
}
);
</script>
{% endif %}
{% endif %}
{% endblock %}
......@@ -410,6 +410,16 @@ def administration_user_application_device_data(name, appkey, devid, var, dest,
t += '<tr><th>'+d[1]+'</th><th>'+str(d[2][var])+'</th></tr>'
return t
@app.route('/administration/<name>/application/<appkey>/device/<devid>/geo')
@restricted('admin')
def administration_user_application_device_geo(name, appkey, devid):
dev = dd.get(appkey, devid)[1]
if 'lat' in dev[3]['format'] and 'lon' in dev[3]['format']:
ld = data.get_last_n(appkey, devid, 1)[1]
d = ddm.read_data(ld[0][2].tobytes(), dev[3])
return str([d['lat'],d['lon']]), 200
return '', 404
@app.route('/administration/<name>/application/<appkey>/device/<devid>/configure', methods=['GET', 'POST'])
@restricted('admin', True)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment