2021-04-15 17:28:07 -04:00
|
|
|
"""
|
|
|
|
Helper class for SRA
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
2021-05-26 16:28:38 -04:00
|
|
|
import calendar as cal
|
2021-04-15 17:28:07 -04:00
|
|
|
import helpers.constants as cte
|
|
|
|
|
|
|
|
|
|
|
|
class Helper:
|
|
|
|
def __init__(self):
|
|
|
|
self._month_hour = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def month_hour(self):
|
|
|
|
"""
|
|
|
|
returns a DataFrame that has x values of the month number (January = 1, February = 2...),
|
|
|
|
being x the number of hours of the corresponding month
|
|
|
|
:return: DataFrame(int)
|
|
|
|
"""
|
|
|
|
array = []
|
|
|
|
for i in range(0, 12):
|
2021-05-26 16:28:38 -04:00
|
|
|
days_of_month = cal.monthrange(2015, i+1)
|
|
|
|
total_hours = days_of_month * 24
|
2021-04-15 17:28:07 -04:00
|
|
|
array = np.concatenate((array, np.full(total_hours, i + 1)))
|
2021-05-26 16:28:38 -04:00
|
|
|
self._month_hour = pd.DataFrame(array, columns=cte.MONTH)
|
2021-04-15 17:28:07 -04:00
|
|
|
return self._month_hour
|
|
|
|
|
|
|
|
def get_mean_values(self, values):
|
|
|
|
out = None
|
|
|
|
if values is not None:
|
2021-05-26 16:28:38 -04:00
|
|
|
if cte.MONTH not in values.columns:
|
2021-04-15 17:28:07 -04:00
|
|
|
values = pd.concat([self.month_hour, pd.DataFrame(values)], axis=1)
|
2021-05-26 16:28:38 -04:00
|
|
|
out = values.groupby(cte.MONTH, as_index=False).mean()
|
|
|
|
del out[cte.MONTH]
|
2021-04-15 17:28:07 -04:00
|
|
|
return out
|