|
|
|
@ -68,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] |
|
|
|
@ -258,26 +258,26 @@ 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')) |
|
|
|
|
|
|
|
|
|
conn = sqlite3.connect(DB_NAMES[hus]) |
|
|
|
|
yea = request.args.get('year', '2023') |
|
|
|
|
|
|
|
|
|
# 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=?' |
|
|
|
|
query += f' GROUP BY Year,Month,Day;' |
|
|
|
|
|
|
|
|
|
cur = conn.execute(query) |
|
|
|
|
conn = sqlite3.connect(DB_NAMES[hus]) |
|
|
|
|
cur = conn.execute(query, [yea]) |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|