1 from configparser import ConfigParser
2 from datetime import datetime, timedelta
3 from logging import getLogger
4 from logging.config import fileConfig
5 from pathlib import Path
6 from shutil import rmtree
8 from .source.ephemeris import Ephemeris
9 from .source.holidays import Holidays
10 from .source.meteofrance import MeteoFrance
11 from .learn.learning import Learning
12 from .learn.preprocessing import Preprocessing
13 from .target.target import Target
15 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
21 def __init__(self, config_file = (Path.cwd() / 'config') / 'learn.cfg'):
22 self._config = ConfigParser()
23 self._config.read(config_file)
24 self._start = datetime.strptime(self._config['DATETIME']['start'],
26 self._end = datetime.strptime(self._config['DATETIME']['end'],
29 self._timestep = timedelta(hours =
30 self._config['DATETIME'].getfloat('hourStep'))
37 # Cleaning the data directory
38 logger.info("Cleaning and restoring data directory")
39 directory = Path.cwd() / 'data'
40 if directory.is_dir():
42 p = Path(Path.cwd() / 'data')
46 def add_features(self):
47 if self._config['FEATURES'].getboolean('meteofrance'):
48 meteofeature = MeteoFrance(config_file =
49 eval(self._config['FEATURE_CONFIG']['meteofrance']))
51 meteofeature.start = self._start
52 meteofeature.end = self._end
55 dated_features = meteofeature.dated_features
56 for date in dated_features:
57 self._X.setdefault(date,{}).update(dated_features[date])
59 if self._config['FEATURES'].getboolean('ephemeris'):
60 ephemerides = Ephemeris(config_file =
61 eval(self._config['FEATURE_CONFIG']['ephemeris']))
63 ephemerides.start = self._start
64 ephemerides.end = self._end
66 dated_features = ephemerides.dated_features
67 for date in dated_features:
68 self._X.setdefault(date,{}).update(dated_features[date])
70 if self._config['FEATURES'].getboolean('holidays'):
71 holidays = Holidays(config_file =
72 eval(self._config['FEATURE_CONFIG']['holidays']))
74 holidays.start = self._start
75 holidays.end = self._end
77 dated_features = holidays.dated_features
78 for date in dated_features:
79 self._X.setdefault(date,{}).update(dated_features[date])
83 self._target = Target(config_file = eval(self._config['TARGET']['config']),
84 start = self._start, end = self._end,
85 timestep = self._timestep)
88 def add_preprocessing(self):
89 self._preproc = Preprocessing(config_file = self._config,
90 dict_features = self.X,
95 history = self._config['HISTORY_KNOWLEDGE'].getint('nb_lines')
96 self._learner = Learning(config_file = eval(self._config['LEARNER']['config']),
97 X = self._preproc.dataframe, y = list(self.y.values())[history:])
111 return self._target.y