Added the time scale of weekly

pull/77/head
Caozhenhui 2021-11-03 11:09:48 +08:00
parent 4a44727a0a
commit 88e33fa9c6
1 changed files with 24 additions and 25 deletions

View File

@ -508,33 +508,32 @@ def averaging_hourly_data_by_period(rows_hourly, start_datetime_utc, end_datetim
current_datetime_utc = \
start_datetime_local.replace(hour=0) - timedelta(days=weekday, hours=int(config.utc_offset[1:3]))
while current_datetime_utc <= end_datetime_utc:
while current_datetime_utc <= end_datetime_utc:
sub_total = Decimal(0.0)
sub_maximum = None
sub_counter = 0
for row in rows_hourly:
if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=7):
sub_total += row[1]
if sub_maximum is None:
sub_maximum = row[1]
elif sub_maximum < row[1]:
sub_maximum = row[1]
sub_counter += 1
sub_total = Decimal(0.0)
sub_maximum = None
sub_counter = 0
for row in rows_hourly:
if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=7):
sub_total += row[1]
if sub_maximum is None:
sub_maximum = row[1]
elif sub_maximum < row[1]:
sub_maximum = row[1]
sub_counter += 1
sub_average = (sub_total / sub_counter) if sub_counter > 0 else None
result_rows_weekly.append((current_datetime_utc, sub_average, sub_maximum))
total += sub_total
counter += sub_counter
if sub_maximum is None:
pass
elif maximum is None:
maximum = sub_maximum
elif maximum < sub_maximum:
maximum = sub_maximum
current_datetime_utc += timedelta(days=7)
sub_average = (sub_total / sub_counter) if sub_counter > 0 else None
result_rows_weekly.append((current_datetime_utc, sub_average, sub_maximum))
total += sub_total
counter += sub_counter
if sub_maximum is None:
pass
elif maximum is None:
maximum = sub_maximum
elif maximum < sub_maximum:
maximum = sub_maximum
current_datetime_utc += timedelta(days=7)
average = total / counter if counter > 0 else None
return result_rows_weekly, average, maximum
average = total / counter if counter > 0 else None
return result_rows_weekly, average, maximum
elif period_type == "monthly":
result_rows_monthly = list()