|
|
|
@ -133,25 +133,35 @@ def parallel_weekly(): |
|
|
|
|
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)} |
|
|
|
|
print(weekdays) |
|
|
|
|
#print(weekdays) |
|
|
|
|
|
|
|
|
|
# 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 (?,?,?,?,?,?,?);', 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=?)' for _ in range(len(weekdays))) |
|
|
|
|
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('-')] |
|
|
|
|
|
|
|
|
|
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]})' |
|
|
|
|
#for k, g in itertools.groupby(res_all, lambda x: x[0]): |
|
|
|
|
for i, data_point in enumerate(res_all): |
|
|
|
|
#data_point = next(g) |
|
|
|
|
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) |
|
|
|
|