Merge branch 'Rafael-DB-Index' into Rafael

Rafael
Rafael M. Martins 7 months ago
commit c72dd0e4df
  1. 6
      py/README.md
  2. 24
      py/import.py
  3. 353
      py/main.py
  4. 4
      web-html/z_FORMATS_NEEDED.js

@ -57,6 +57,7 @@ Returns data formatted for the 'weekly' parallel coordinates view.
* 'year' [Optional; default: 2023]: year.
* 'family' [Optional; default: 'S1']: name of family of sensors.
* 'type' [Optional; default: 'celsius']: type of sensor.
* 'hour' [Optional; default: 00]: hour of the day.
### /parallel/monthly
@ -66,6 +67,8 @@ Returns data formatted for the 'monthly' parallel coordinates view.
* 'year' [Optional; default: 2023]: year.
* 'family' [Optional; default: 'S1']: name of family of sensors.
* 'type' [Optional; default: 'celsius']: type of sensor.
* 'hour' [Optional; default: 00]: hour of the day.
* 'weekday' [Optional; default: 1]: weekday, 1 (sun) to 7 (sat)
### /parallel/yearly
@ -74,7 +77,8 @@ Returns data formatted for the 'yearly' parallel coordinates view.
* 'year' [Optional; default: 2023]: year.
* 'family' [Optional; default: 'S1']: name of family of sensors.
* 'type' [Optional; default: 'celsius']: type of sensor.
* 'hour' [Optional; default: 00]: hour of the day.
* 'day' [Optional; default: 1]: day of the month (1 to 28)
## Grid

@ -70,13 +70,19 @@ for hus_name in next(os.walk(BASEDIR))[1]:
units = list(compress(units, not_empty))
# Create the table
col_names = ['Date', 'Time']
col_names = ['Year', 'Month', 'Day', 'Hour', 'Minute', 'Second']
col_names.extend(f'{family_names[i]}.{sensor_names[i]}.{units[i]}' for i in range(3, len(family_names)))
#print(col_names)
cur.execute(f"CREATE TABLE {table_name}{*col_names,}")
con.commit()
cur.execute(f'CREATE INDEX idx_{card}_Year ON {table_name} (Year)')
cur.execute(f'CREATE INDEX idx_{card}_Month ON {table_name} (Month)')
cur.execute(f'CREATE INDEX idx_{card}_Day ON {table_name} (Day)')
cur.execute(f'CREATE INDEX idx_{card}_Hour ON {table_name} (Hour)')
con.commit()
#exit()
print(f'Processing {txt}...')
@ -89,11 +95,16 @@ for hus_name in next(os.walk(BASEDIR))[1]:
# Skip two lines; we don't need them anymore
header1 = next(reader)
header2 = next(reader)
else:
data.append(tuple(compress(line, not_empty)))
#print(data)
#exit()
else:
# First split the date into three columns (y,m,d)
row = line[0].split('-')
# Then split the time into three columns (h,m,s)
row.extend(line[1].split(':'))
# Then add the data (without the date, time, and empty columns)
row.extend(tuple(compress(line, not_empty))[2:])
data.append(row)
# Sometimes, some of the lines in a file are the wrong size.
# When that happens, we skip the file.
if len(data[-1]) != len(col_names):
@ -114,4 +125,3 @@ for hus_name in next(os.walk(BASEDIR))[1]:
cur.executemany(query, data)
con.commit()

@ -11,16 +11,18 @@ import glob
DB_NAMES = {
'Charlie': 'Charlie.db',
'Pilgatan': 'Pilgatan.db',
#'Pilgatan': 'Pilgatan.db',
}
table_names = {
'Charlie': ['Hus_Charlie_card_1', 'Hus_Charlie_card_4'],
'Pilgatan': ['Hus_Pilgatan_card_v1', 'Hus_Pilgatan_card_v6'],
#'Pilgatan': ['Hus_Pilgatan_card_v1', 'Hus_Pilgatan_card_v6'],
}
date_col = "Date"
time_col = "Time"
#date_col = "Date"
date_cols = ['Year', 'Month', 'Day']
#time_col = "Time"
time_cols = ['Hour', 'Minute', 'Second']
# Startup
@ -44,7 +46,7 @@ for hus in DB_NAMES:
TABLE_FAMILIES_SENSORS[hus] = {}
for table_name, col_names in TABLE_COLS[hus].items():
TABLE_FAMILIES_SENSORS[hus][table_name] = {}
for col_name in col_names[2:]:
for col_name in col_names[6:]:
match = re.search(r'(.*)\.(.*)\..*', col_name)
fam, sen = match[1], match[2]
if fam not in TABLE_FAMILIES_SENSORS[hus][table_name]:
@ -57,7 +59,7 @@ def get_table_cols(hus, fam, typ):
for table_name in TABLE_FAMILIES_SENSORS[hus]:
if fam in TABLE_FAMILIES_SENSORS[hus][table_name]:
sen_cols = [col for col in TABLE_COLS[hus][table_name] if re.match(f'{fam}\.(.*)\.{typ}', col)]
col_names = [date_col, time_col]
col_names = [*date_cols, *time_cols]
col_names.extend(sen_cols)
return table_name, col_names
return None
@ -66,7 +68,7 @@ def get_table_cols(hus, fam, typ):
def get_table_col_fam(hus, sen, typ):
for table_name in TABLE_FAMILIES_SENSORS[hus]:
for col in TABLE_COLS[hus][table_name]:
print(table_name, col)
#print(table_name, col)
match = re.match(f'(.*)\.{sen}\.{typ}', col)
if match:
return table_name, col, match[1]
@ -88,21 +90,28 @@ def parallel_daily():
# Get the right sensors for the family
table_name, col_names = get_table_cols(hus, fam, typ)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
# Split date
yea, mon, day = day.split('-')
query = (f'SELECT {sql_col_names} FROM {table_name}'
f' WHERE Year=? AND Month=? AND Day=?'
f' GROUP BY Hour;')
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(f'SELECT {sql_col_names} FROM "{table_name}" WHERE "{date_col}"=?;', [day])
cur = conn.execute(query, [yea, mon, day])
res_all = cur.fetchall()
cur.close()
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-2)]]]
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-6)]]]
myxs = {}
for k, g in itertools.groupby(res_all, lambda x: x[1][:2]):
data_point = next(g)
point_id = f'{data_point[1]}'
for data_point in res_all:
point_id = ':'.join(data_point[3:6])
myxs[point_id] = 'pos1'
data_point = [point_id, *data_point[2:]]
data_point = [point_id, *data_point[6:]]
sample.append(data_point)
return dict(sample=sample, myxs=myxs)
@ -116,10 +125,15 @@ def parallel_weekly():
typ = request.args.get('type', 'celsius')
wee = int(request.args.get('week', '1'))
yea = int(request.args.get('year', '2023'))
hou = int(request.args.get('hour', '0'))
# Make sure format is right
hou = f'{hou:02d}'
#if not wee or not yea:
# return 'ERROR: You need to at least specify the parameters "week" and "year".'
# Find monday from the given week
monday = date.fromisocalendar(yea, wee, 1)
weekday_names = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
weekdays = {str(monday + timedelta(days=x)):weekday_names[x] for x in range(7)}
@ -129,19 +143,29 @@ def parallel_weekly():
table_name, col_names = get_table_cols(hus, fam, typ)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(f'SELECT {sql_col_names} FROM "{table_name}" WHERE "{date_col}" IN (?,?,?,?,?,?,?);', list(weekdays.keys()))
# Complex query to get each day of the week
query = f'SELECT {sql_col_names} FROM {table_name} WHERE ('
query += 'OR'.join(['(Year=? AND Month=? AND Day=?)'] * len(weekdays))
query += ') AND Hour=?'
query += ' GROUP BY Day;'
# Break each date into three components then merge them all (in a flat list)
params = [y for d in list(weekdays.keys()) for y in d.split('-')]
params.append(hou)
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(query, params)
res_all = cur.fetchall()
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-2)]]]
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-6)]]]
myxs = {}
# group by day; take first of each group
for k, g in itertools.groupby(res_all, lambda x: x[0]):
data_point = next(g)
point_id = f'{weekdays[data_point[0]]} ({data_point[0]})'
# group by day; take first of each group
for i, data_point in enumerate(res_all):
wd = list(weekdays.items())[i]
point_id = f'{wd[1]} ({wd[0]})'
myxs[point_id] = 'pos1'
data_point = [point_id, *data_point[2:]]
data_point = [point_id, *data_point[6:]]
sample.append(data_point)
return dict(sample=sample, myxs=myxs)
@ -155,34 +179,45 @@ def parallel_monthly():
typ = request.args.get('type', 'celsius')
mon = int(request.args.get('month', '1'))
yea = int(request.args.get('year', '2023'))
wda = int(request.args.get('weekday', 1))
hou = int(request.args.get('hour', '0'))
# Make sure format is right
hou = f'{hou:02d}'
#if not wee or not yea:
# return 'ERROR: You need to at least specify the parameters "week" and "year".'
# first days of the 4 weeks
first = date(yea, mon, 1)
first = date(yea, mon, wda)
days = [str(first + timedelta(days=7*x)) for x in range(4)]
# Get the right sensors for the family
table_name, col_names = get_table_cols(hus, fam, typ)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
# Complex query to get each day separately
query = f'SELECT {sql_col_names} FROM {table_name} WHERE ('
query += 'OR'.join(['(Year=? AND Month=? AND Day=?)'] * len(days))
query += ') AND Hour=?'
query += ' GROUP BY Day;'
# Break each date into three components then merge them all (in a flat list)
params = [y for d in days for y in d.split('-')]
params.append(hou)
conn = sqlite3.connect(DB_NAMES[hus])
query = f'SELECT {sql_col_names} FROM "{table_name}" WHERE "{date_col}" IN (?,?,?,?);'
print(query)
cur = conn.execute(query, days)
cur = conn.execute(query, params)
res_all = cur.fetchall()
print(res_all)
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-2)]]]
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-6)]]]
myxs = {}
# group by day; take first of each group
for k, g in itertools.groupby(res_all, lambda x: x[0]):
data_point = next(g)
point_id = f'{data_point[0]}'
# group by day; take first of each group
for data_point in res_all:
point_id = '-'.join(data_point[:3])
myxs[point_id] = 'pos1'
data_point = [point_id, *data_point[2:]]
data_point = [point_id, *data_point[6:]]
sample.append(data_point)
return dict(sample=sample, myxs=myxs)
@ -194,34 +229,36 @@ def parallel_yearly():
hus = request.args.get('hus', 'Charlie')
fam = request.args.get('family', 'MP1_1')
typ = request.args.get('type', 'celsius')
yea = int(request.args.get('year', '2023'))
yea = request.args.get('year', '2023')
day = int(request.args.get('day', '1'))
hou = int(request.args.get('hour', '0'))
# Make sure format is right
day = f'{day:02d}'
hou = f'{hou:02d}'
#if not wee or not yea:
# return 'ERROR: You need to at least specify the parameters "week" and "year".'
# first days of each of the 12 months
days = [str(date(yea, x, 1)) for x in range(1, 13)]
conn = sqlite3.connect(DB_NAMES[hus])
# Get the right sensors for the family
table_name, col_names = get_table_cols(hus, fam, typ)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
cur = conn.execute(f'SELECT {sql_col_names} FROM "{table_name}" WHERE "{date_col}" IN (?,?,?,?,?,?,?,?,?,?,?,?);', days)
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(f'SELECT {sql_col_names} FROM {table_name}'
' WHERE Year=? AND Day=? AND Hour=? GROUP BY Month;', [yea, day, hou])
res_all = cur.fetchall()
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-2)]]]
sample = [["pos1", *[x*10+10 for x in range(len(col_names)-6)]]]
myxs = {}
month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
# group by day; take first of each group
for k, g in itertools.groupby(res_all, lambda x: x[0]):
data_point = next(g)
month_num = int(data_point[0][5:7])-1
# group by day; take first of each group
for data_point in res_all:
month_num = int(data_point[1])-1
point_id = f'{month_names[month_num]}'
myxs[point_id] = 'pos1'
data_point = [point_id, *data_point[2:]]
data_point = [point_id, *data_point[6:]]
sample.append(data_point)
return dict(sample=sample, myxs=myxs)
@ -233,26 +270,30 @@ def grid_yearly():
# Process parameters
sen = request.args.get('sensor', 'Temp_MP1_1_Pos1')
typ = request.args.get('type', 'celsius')
yea = int(request.args.get('year', '2023'))
yea = request.args.get('year', '2023')
hou = int(request.args.get('hour', '0'))
conn = sqlite3.connect(DB_NAMES[hus])
# Make sure format is right
hou = f'{hou:02d}'
# Get the columns for the sensor
table_name, col_name, fam = get_table_col_fam(hus, sen, typ)
sql_col_names = f'"{date_col}","{time_col}","{col_name}"'
col_names = [*date_cols, *time_cols, col_name]
sql_col_names = ','.join(f'"{x}"' for x in col_names)
query = f'SELECT {sql_col_names} FROM "{table_name}"'
query += f'WHERE "{date_col}" LIKE "{yea}-%"'
query += f' GROUP BY "{date_col}"'
query += ';'
query = f'SELECT {sql_col_names} FROM {table_name}'
query += f' WHERE Year=? AND Hour=?'
query += f' GROUP BY Year,Month,Day;'
cur = conn.execute(query)
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(query, [yea, hou])
res_all = cur.fetchall()
out = []
for i in range(len(res_all[0])):
out.append([x[i] for x in res_all])
out.append(['-'.join(x[:3]) for x in res_all])
out.append([':'.join(x[3:6]) for x in res_all])
out.append([x[6] for x in res_all])
return out
@ -262,26 +303,31 @@ def grid_monthly():
# Process parameters
sen = request.args.get('sensor', 'Temp_MP1_1_Pos1')
typ = request.args.get('type', 'celsius')
yea = int(request.args.get('year', '2023'))
yea = request.args.get('year', '2023')
mon = int(request.args.get('month', '1'))
hou = int(request.args.get('hour', '0'))
conn = sqlite3.connect(DB_NAMES[hus])
# Make sure format is right
hou = f'{hou:02d}'
mon = f'{mon:02d}'
# Get the columns for the sensor
table_name, col_name, fam = get_table_col_fam(hus, sen, typ)
sql_col_names = f'"{date_col}","{time_col}","{col_name}"'
col_names = [*date_cols, *time_cols, col_name]
sql_col_names = ','.join(f'"{x}"' for x in col_names)
query = f'SELECT {sql_col_names} FROM "{table_name}" '
query += f'WHERE "{date_col}" LIKE "{yea}-{mon:02d}%"'
query += f'GROUP BY "{date_col}" '
query += ';'
query = f'SELECT {sql_col_names} FROM {table_name}'
query += f' WHERE Year=? AND Month=? AND Hour=?'
query += f' GROUP BY Year,Month,Day;'
cur = conn.execute(query)
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(query, [yea, mon, hou])
res_all = cur.fetchall()
out = []
for i in range(len(res_all[0])):
out.append([x[i] for x in res_all])
out.append(['-'.join(x[:3]) for x in res_all])
out.append([':'.join(x[3:6]) for x in res_all])
out.append([x[6] for x in res_all])
return out
@ -294,8 +340,10 @@ def grid_weekly():
typ = request.args.get('type', 'celsius')
yea = int(request.args.get('year', '2023'))
wee = int(request.args.get('week', '1'))
hou = int(request.args.get('hour', '0'))
conn = sqlite3.connect(DB_NAMES[hus])
# Make sure format is right
hou = f'{hou:02d}'
monday = date.fromisocalendar(yea, wee, 1)
weekday_names = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
@ -304,19 +352,27 @@ def grid_weekly():
# Get the columns for the sensor
table_name, col_name, fam = get_table_col_fam(hus, sen, typ)
sql_col_names = f'"{date_col}","{time_col}","{col_name}"'
col_names = [*date_cols, *time_cols, col_name]
sql_col_names = ','.join(f'"{x}"' for x in col_names)
# Complex query to get each day separately
query = f'SELECT {sql_col_names} FROM {table_name} WHERE ('
query += 'OR'.join(['(Year=? AND Month=? AND Day=?)'] * len(weekdays))
query += ') AND Hour=?'
query += f' GROUP BY Year,Month,Day;'
query = f'SELECT {sql_col_names} FROM "{table_name}" '
query += f'WHERE "{date_col}" IN (?,?,?,?,?,?,?) '
query += f'GROUP BY "{date_col}" '
query += ';'
# Break each date into three components then merge them all (in a flat list)
params = [y for d in list(weekdays.keys()) for y in d.split('-')]
params.append(hou)
cur = conn.execute(query, list(weekdays.keys()))
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(query, params)
res_all = cur.fetchall()
out = []
for i in range(len(res_all[0])):
out.append([x[i] for x in res_all])
out.append(['-'.join(x[:3]) for x in res_all])
out.append([':'.join(x[3:6]) for x in res_all])
out.append([x[6] for x in res_all])
return out
@ -335,18 +391,20 @@ def horizon_yearly():
table_name, col_names = get_table_cols(hus, fam, typ)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
# Important: this code is outdated when compared to the other horizon endpoints
out = {}
out['sensor_names'] = col_names[2:]
out['sensor_names'] = col_names[6:]
aux_data = {}
for sensor_name in out['sensor_names']:
aux_data[sensor_name] = []
for hour in ['00','06','12','18']:
for hour in ['00','06','12','18']:
query = f'SELECT {sql_col_names} FROM "{table_name}"'
query += f'WHERE "{date_col}" LIKE "{yea}-%"'
query += f'AND "{time_col}" LIKE "{hour}:%"'
query += f' GROUP BY "{date_col}"'
query += f' WHERE "Year" = "{yea}"'
query += f' AND "Hour" = "{hour}"'
query += f' GROUP BY "Month", "Day"'
query += ';'
cur = conn.execute(query)
@ -354,14 +412,14 @@ def horizon_yearly():
for row in res_all:
for i, sensor_name in enumerate(out['sensor_names']):
aux_data[sensor_name].append((row[0], row[1], row[i+2]))
aux_data[sensor_name].append((*row[:6], row[i+6]))
for i, sensor_name in enumerate(out['sensor_names']):
sensor_data_sorted = sorted(aux_data[sensor_name])
sensor_data_sorted = sorted(aux_data[sensor_name])
if i == 0:
out['days'] = [x[0] for x in sensor_data_sorted]
out['times'] = [x[1] for x in sensor_data_sorted]
out[sensor_name] = [x[2] for x in sensor_data_sorted]
out['days'] = ['-'.join(x[:3]) for x in sensor_data_sorted]
out['times'] = [':'.join(x[3:6]) for x in sensor_data_sorted]
out[sensor_name] = [x[6] for x in sensor_data_sorted]
return out
@ -372,42 +430,39 @@ def horizon_monthly():
# Process parameters
fam = request.args.get('family', 'MP1_1')
typ = request.args.get('type', 'celsius')
yea = int(request.args.get('year', '2023'))
yea = request.args.get('year', '2023')
mon = int(request.args.get('month', '1'))
conn = sqlite3.connect(DB_NAMES[hus])
# Make sure the format is right
mon = f'{mon:02d}'
# Get the right sensors for the family
table_name, col_names = get_table_cols(hus, fam, typ)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
#print(sql_col_names)
out = {}
out['sensor_names'] = col_names[2:]
aux_data = {}
for sensor_name in out['sensor_names']:
aux_data[sensor_name] = []
out['sensor_names'] = col_names[6:]
out['days'] = []
out['times'] = []
for s in out['sensor_names']:
out[s] = []
for hour in range(24):
query = f'SELECT {sql_col_names} FROM "{table_name}"'
query += f'WHERE "{date_col}" LIKE "{yea}-{mon:02d}-%"'
query += f'AND "{time_col}" LIKE "{hour:02d}:%"'
query += f' GROUP BY "{date_col}"'
query += ';'
query = (f'SELECT {sql_col_names} FROM {table_name}'
f' WHERE Year=? AND Month=?'
f' GROUP BY Day, Hour')
cur = conn.execute(query)
res_all = cur.fetchall()
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(query, [yea, mon])
res_all = cur.fetchall()
for row in res_all:
for i, sensor_name in enumerate(out['sensor_names']):
aux_data[sensor_name].append((row[0], row[1], row[i+2]))
# Important: this only works assuming that res_all is correctly sorted
for i, sensor_name in enumerate(out['sensor_names']):
sensor_data_sorted = sorted(aux_data[sensor_name])
if i == 0:
out['days'] = [x[0] for x in sensor_data_sorted]
out['times'] = [x[1] for x in sensor_data_sorted]
out[sensor_name] = [x[2] for x in sensor_data_sorted]
for row in res_all:
out['days'].append('-'.join(row[:3]))
out['times'].append(':'.join(row[3:6]))
for i in range(6, len(row)):
out[out['sensor_names'][i-6]].append(row[i])
return out
@ -418,9 +473,7 @@ def horizon_weekly():
fam = request.args.get('family', 'MP1_1')
typ = request.args.get('type', 'celsius')
yea = int(request.args.get('year', '2023'))
wee = int(request.args.get('week', '1'))
conn = sqlite3.connect(DB_NAMES[hus])
wee = int(request.args.get('week', '1'))
# Get the right sensors for the family
table_name, col_names = get_table_cols(hus, fam, typ)
@ -432,32 +485,30 @@ def horizon_weekly():
#print(weekdays)
out = {}
out['sensor_names'] = col_names[2:]
aux_data = {}
for sensor_name in out['sensor_names']:
aux_data[sensor_name] = []
for hour in range(24):
query = f'SELECT {sql_col_names} FROM "{table_name}"'
query += f'WHERE "{date_col}" IN (?,?,?,?,?,?,?) '
query += f'AND "{time_col}" LIKE "{hour:02d}:%"'
query += f' GROUP BY "{date_col}"'
query += ';'
out['sensor_names'] = col_names[6:]
out['days'] = []
out['times'] = []
for s in out['sensor_names']:
out[s] = []
query = f'SELECT {sql_col_names} FROM {table_name} WHERE '
query += 'OR'.join(['(Year=? AND Month=? AND Day=?)'] * len(weekdays))
query += ' GROUP BY Year, Month, Day, Hour'
cur = conn.execute(query, list(weekdays.keys()))
res_all = cur.fetchall()
# Break each date into three components then merge them all (in a flat list)
params = [y for d in list(weekdays.keys()) for y in d.split('-')]
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(query, params)
res_all = cur.fetchall()
for row in res_all:
for i, sensor_name in enumerate(out['sensor_names']):
aux_data[sensor_name].append((row[0], row[1], row[i+2]))
# Important: this only works assuming that res_all is correctly sorted
for i, sensor_name in enumerate(out['sensor_names']):
sensor_data_sorted = sorted(aux_data[sensor_name])
if i == 0:
out['days'] = [x[0] for x in sensor_data_sorted]
out['times'] = [x[1] for x in sensor_data_sorted]
out[sensor_name] = [x[2] for x in sensor_data_sorted]
for row in res_all:
out['days'].append('-'.join(row[:3]))
out['times'].append(':'.join(row[3:6]))
for i in range(6, len(row)):
out[out['sensor_names'][i-6]].append(row[i])
return out
@ -470,31 +521,35 @@ def horizon_daily():
typ = request.args.get('type', 'celsius')
day = request.args.get('day', '2023-01-01')
conn = sqlite3.connect(DB_NAMES[hus])
yea, mon, day = day.split('-')
# Get the right sensors for the family
table_name, col_names = get_table_cols(hus, fam, typ)
sql_col_names = ','.join(f'"{x}"' for x in col_names)
query = f'SELECT {sql_col_names} FROM "{table_name}"'
query += f'WHERE "{date_col}"=? '
query += ';'
cur = conn.execute(query, [day])
res_all = cur.fetchall()
sql_col_names = ','.join(f'"{x}"' for x in col_names)
out = {}
out['sensor_names'] = col_names[2:]
out['sensor_names'] = col_names[6:]
out['days'] = []
out['times'] = []
for s in out['sensor_names']:
out[s] = []
query = f'SELECT {sql_col_names} FROM "{table_name}"'
query += f'WHERE Year=? AND Month=? AND Day=?;'
conn = sqlite3.connect(DB_NAMES[hus])
cur = conn.execute(query, [yea, mon, day])
res_all = cur.fetchall()
# Important: this only works assuming that res_all is correctly sorted
for row in res_all:
out['days'].append(row[0])
out['times'].append(row[1])
for i, s in enumerate(out['sensor_names']):
out[s].append(row[i+2])
out['days'].append('-'.join(row[:3]))
out['times'].append(':'.join(row[3:6]))
for i in range(6, len(row)):
out[out['sensor_names'][i-6]].append(row[i])
return out

@ -61,7 +61,7 @@ myxs = {
// allow for chosing a different date/time
// monthly: date: choose days 1/8/15/22/29; time; 12:00;
// allow for chosing different date/time
// daily: time: 0-1-2-3-...-24;
// daily: time: 0-1-2-3-...-23;
// allow for chosing different date/time
//
// Is it possible to allow to supress a line then (hide it)?
@ -89,7 +89,7 @@ var Temp_MP1_1_Pos4 = [
// - yearly - 365 days; 12 rows with 28-31 days; at 12:00;
// - monthly - 28 days; 4 rows with 7 days; at 12:00;
// - can this be arranged like in calendar view?
// - weekly - 7 days; 4 rows with 24 hours; at ##:00;
// - weekly - 7 days; one per day at ##:00;
//
// Scale: is it possible here to chose if an actual time is shown or to have the max/min value within a day for the yearly/monthly versions?
//

Loading…
Cancel
Save