@@ 395-421 (lines=27) @@ | ||
392 | maximum = None |
|
393 | counter = 0 |
|
394 | current_datetime_utc = start_datetime_utc.replace(minute=0, second=0, microsecond=0, tzinfo=None) |
|
395 | while current_datetime_utc <= end_datetime_utc: |
|
396 | sub_total = Decimal(0.0) |
|
397 | sub_maximum = None |
|
398 | sub_counter = 0 |
|
399 | for row in rows_hourly: |
|
400 | if current_datetime_utc <= row[0] < current_datetime_utc + \ |
|
401 | timedelta(minutes=config.minutes_to_count): |
|
402 | sub_total += row[1] |
|
403 | if sub_maximum is None: |
|
404 | sub_maximum = row[1] |
|
405 | elif sub_maximum < row[1]: |
|
406 | sub_maximum = row[1] |
|
407 | sub_counter += 1 |
|
408 | ||
409 | sub_average = (sub_total / sub_counter) if sub_counter > 0 else None |
|
410 | result_rows_hourly.append((current_datetime_utc, sub_average, sub_maximum)) |
|
411 | ||
412 | total += sub_total |
|
413 | counter += sub_counter |
|
414 | if sub_maximum is None: |
|
415 | pass |
|
416 | elif maximum is None: |
|
417 | maximum = sub_maximum |
|
418 | elif maximum < sub_maximum: |
|
419 | maximum = sub_maximum |
|
420 | ||
421 | current_datetime_utc += timedelta(minutes=config.minutes_to_count) |
|
422 | ||
423 | average = total / counter if counter > 0 else None |
|
424 | return result_rows_hourly, average, maximum |
|
@@ 436-459 (lines=24) @@ | ||
433 | # calculate the start datetime in utc of the first day in local |
|
434 | start_datetime_local = start_datetime_utc + timedelta(hours=int(config.utc_offset[1:3])) |
|
435 | current_datetime_utc = start_datetime_local.replace(hour=0) - timedelta(hours=int(config.utc_offset[1:3])) |
|
436 | while current_datetime_utc <= end_datetime_utc: |
|
437 | sub_total = Decimal(0.0) |
|
438 | sub_maximum = None |
|
439 | sub_counter = 0 |
|
440 | for row in rows_hourly: |
|
441 | if current_datetime_utc <= row[0] < current_datetime_utc + timedelta(days=1): |
|
442 | sub_total += row[1] |
|
443 | if sub_maximum is None: |
|
444 | sub_maximum = row[1] |
|
445 | elif sub_maximum < row[1]: |
|
446 | sub_maximum = row[1] |
|
447 | sub_counter += 1 |
|
448 | ||
449 | sub_average = (sub_total / sub_counter) if sub_counter > 0 else None |
|
450 | result_rows_daily.append((current_datetime_utc, sub_average, sub_maximum)) |
|
451 | total += sub_total |
|
452 | counter += sub_counter |
|
453 | if sub_maximum is None: |
|
454 | pass |
|
455 | elif maximum is None: |
|
456 | maximum = sub_maximum |
|
457 | elif maximum < sub_maximum: |
|
458 | maximum = sub_maximum |
|
459 | current_datetime_utc += timedelta(days=1) |
|
460 | ||
461 | average = total / counter if counter > 0 else None |
|
462 | return result_rows_daily, average, maximum |