TimberVis Flexiboard: Visualization and Exploration Flexiboard for Timber Buildings IoT data sensors.
The pulse of the wood
Monitoring of Wooden houses: Time series of sensors data measuring
humidity, temperatures, vibrations and weather conditions.
https://lnu.se/forskning/forskningsprojekt/projekt-flexiboard-for-visualisering-och-utforskning-av-trabyggnader/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
57 lines
1.6 KiB
import itertools
|
|
from flask import Flask, request
|
|
import sqlite3
|
|
|
|
|
|
DB_NAME = 'charlie.db'
|
|
table_name = 'Hus_Charlie_g1'
|
|
date_col = "SENSOR1 _Date"
|
|
time_col = "0x76ECB432_Time"
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/")
|
|
def root():
|
|
conn = sqlite3.connect(DB_NAME)
|
|
cur = conn.execute(f"PRAGMA table_info('{table_name}')")
|
|
res = cur.fetchall()
|
|
cur.close()
|
|
return res
|
|
|
|
|
|
@app.route("/parallel")
|
|
def parallel():
|
|
# Process parameters
|
|
fam = request.args.get('family', 'S1')
|
|
typ = request.args.get('type', '°')
|
|
day = request.args.get('day', '')
|
|
|
|
if not day:
|
|
return 'ERROR: You need to at least specify the parameter "day".'
|
|
|
|
# Get the right sensors for the family
|
|
conn = sqlite3.connect(DB_NAME)
|
|
cur = conn.execute(f"PRAGMA table_info('{table_name}')")
|
|
res = cur.fetchall()
|
|
filter1 = lambda x: x[1][:len(fam)] == fam and x[1][-len(typ):] == typ
|
|
filter2 = lambda x: x[1] == date_col or x[1] == time_col
|
|
col_names = [x[1] for x in res if filter1(x) or filter2(x)]
|
|
|
|
sql_col_names = ','.join(f'"{x}"' for x in col_names)
|
|
#print(sql_col_names)
|
|
|
|
res = cur.execute(f'SELECT {sql_col_names} FROM "{table_name}" WHERE "{date_col}"=?;', [day])
|
|
res_all = res.fetchall()
|
|
|
|
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-2)]]]
|
|
myxs = {}
|
|
for k, g in itertools.groupby(res_all, lambda x: x[1][:2]):
|
|
data_point = next(g)
|
|
point_id = f'{data_point[0]} {data_point[1]}'
|
|
myxs[point_id] = 'pos1'
|
|
data_point = [point_id, *data_point[2:]]
|
|
sample.append(data_point)
|
|
|
|
return dict(sample=sample, myxs=myxs)
|
|
|
|
|