+from itertools import chain
+from logging import getLogger
+from logging.config import fileConfig
+from pathlib import Path
+
+import numpy as np
+import pandas as pd
+
+fileConfig((Path.cwd() / 'config') / 'logging.cfg')
+logger = getLogger()
+
+class Preprocessing:
+ def __init__(self, dict_features,
+ start, end, timestep,
+ features = None):
+ self._dict_features = dict_features
+ self._start = start
+ self._end = end
+ self._timestep = timestep
+ self._dataframe = None
+
+ if features != None:
+ self._features = features
+ else:
+ self._features = set(chain.from_iterable([tuple(u.keys())
+ for u in [*dict_features.values()]]))
+
+
+ def _fill_dict(self):
+ current = self._start
+ while current <= self._end:
+ if current not in self._dict_features:
+ self._dict_features[current] = {feature:np.NaN for feature in self._features}
+ else:
+ null_dict = {feature:np.NaN for feature in self._features}
+ null_dict.update(self._dict_features[current])
+ self._dict_features[current] = null_dict
+ current += self._timestep
+
+
+ @property
+ def full_dict(self):
+ self._fill_dict()
+ return {k: self._dict_features[k] for k in sorted(self._dict_features.keys())}
+
+
+ @property
+ def dataframe(self):
+ if self._dataframe is None:
+ self._dataframe = pd.DataFrame.from_dict(self.full_dict, orient='index')
+ return self._dataframe
+
+ @dataframe.setter
+ def dataframe(self, df):
+ self._dataframe = df
+
+
+ def fill_na(self):
+ self.dataframe = self.dataframe.fillna(method='ffill')
\ No newline at end of file