Commit 355d9257 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

device data model implemented and tested from pc, todo:tests from devices

parent 81984a30
...@@ -96,7 +96,7 @@ def test_done(): ...@@ -96,7 +96,7 @@ def test_done():
print(read_data_ddm(rdata, ddm)) print(read_data_ddm(rdata, ddm))
@misc.with_psql @misc.with_psql
def insert_test(cur): def mpack_test(cur):
import random import random
m = { m = {
...@@ -113,6 +113,20 @@ def insert_test(cur): ...@@ -113,6 +113,20 @@ def insert_test(cur):
return (True,) return (True,)
@misc.with_psql
def raw_test(cur):
import random
upstr = '<fQ20s?h'
m = struct.pack(upstr, random.random()*1000, random.randint(10000,10000000), 'hello'.encode('utf-8'), random.randint(0,2), random.randint(0, 30000))
query = """
INSERT INTO dev_3b56f3d8_2 VALUES ({}, '{}', {})
""".format(misc.get_utc(), datetime.now().strftime('%H:%M:%S'), Binary(m))
cur.execute(query)
return (True,)
def decode_datum(data, ddm): def decode_datum(data, ddm):
data = [d for d in data] data = [d for d in data]
data[2] = read_data(data[2].tobytes(), ddm) data[2] = read_data(data[2].tobytes(), ddm)
...@@ -154,13 +168,14 @@ def extract(request): ...@@ -154,13 +168,14 @@ def extract(request):
ddmin['format'][k]['type'] = v['size'] + 's' ddmin['format'][k]['type'] = v['size'] + 's'
ddmin['format'][k].pop('size') ddmin['format'][k].pop('size')
# order dict # order dict
od = collections.OrderedDict(sorted(ddmin['format'].items())) od = OrderedDict(sorted(ddmin['format'].items()))
ddmin.pop('format') ddmin.pop('format')
ddmin['format'] = collections.OrderedDict() ddmin['format'] = OrderedDict()
# give it defined ddm format # give it defined ddm format
for k,v in od.items(): for k,v in od.items():
ddmin['format'][v['name']] = v['type'] ddmin['format'][v['name']] = v['type']
return ddmin return ddmin
print('insert', insert_test()) print('mpack insert', mpack_test())
print('raw insert', raw_test())
{% extends 'logged_layout.html' %} {% extends 'logged_layout.html' %}
{% block title %} HPC&amp;A IoT - {{ app[1] }} - Devices {% endblock %} {% block title %} HPC&amp;A IoT - {{ app[0] }} - Devices {% endblock %}
{% block header %} {% block header %}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
...@@ -175,7 +175,7 @@ ...@@ -175,7 +175,7 @@
title: '{{ dev[0] }} > '+dname, title: '{{ dev[0] }} > '+dname,
curveType: 'function', curveType: 'function',
hAxis: { hAxis: {
format: 'dd/MM hh:mm' format: 'dd/MM HH:mm'
}, },
vAxis: { vAxis: {
format: 'decimal', format: 'decimal',
......
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