|
|
|
@ -125,6 +125,10 @@ 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".' |
|
|
|
@ -140,12 +144,14 @@ def parallel_weekly(): |
|
|
|
|
sql_col_names = ','.join(f'"{x}"' for x in col_names) |
|
|
|
|
|
|
|
|
|
# Complex query to get each day of the week |
|
|
|
|
query = f'SELECT {sql_col_names} FROM {table_name} WHERE' |
|
|
|
|
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) |
|
|
|
@ -173,12 +179,17 @@ 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 |
|
|
|
@ -186,12 +197,14 @@ def parallel_monthly(): |
|
|
|
|
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 = 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]) |
|
|
|
|
cur = conn.execute(query, params) |
|
|
|
@ -217,32 +230,31 @@ def parallel_yearly(): |
|
|
|
|
fam = request.args.get('family', 'MP1_1') |
|
|
|
|
typ = request.args.get('type', 'celsius') |
|
|
|
|
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)] |
|
|
|
|
|
|
|
|
|
# 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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conn = sqlite3.connect(DB_NAMES[hus]) |
|
|
|
|
#cur = conn.execute(f'SELECT {sql_col_names} FROM "{table_name}" WHERE "{date_col}" IN (?,?,?,?,?,?,?,?,?,?,?,?);', days) |
|
|
|
|
cur = conn.execute(f'SELECT {sql_col_names} FROM {table_name}' |
|
|
|
|
' WHERE Year=? GROUP BY Month;', [yea]) |
|
|
|
|
' 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)-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]): |
|
|
|
|
for data_point in res_all: |
|
|
|
|
#data_point = next(g) |
|
|
|
|
# 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' |
|
|
|
|