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.meteofrance import MeteoFrance
10 from .learn.learning import Learning
11 from .learn.preprocessing import Preprocessing
12 from .target.target import Target
14 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
20 def __init__(self, config_file = (Path.cwd() / 'config') / 'learn.cfg'):
21 self._config = ConfigParser()
22 self._config.read(config_file)
23 self._start = datetime.strptime(self._config['DATETIME']['start'],
25 self._end = datetime.strptime(self._config['DATETIME']['end'],
28 self._timestep = timedelta(hours =
29 self._config['DATETIME'].getfloat('hourStep'))
36 # Cleaning the data directory
37 logger.info("Cleaning and restoring data directory")
38 directory = Path.cwd() / 'data'
39 if directory.is_dir():
41 p = Path(Path.cwd() / 'data')
45 def add_features(self):
46 if self._config['FEATURES'].getboolean('meteofrance'):
47 meteofeature = MeteoFrance(config_file =
48 eval(self._config['FEATURE_CONFIG']['meteofrance']))
50 meteofeature.start = self._start
51 meteofeature.end = self._end
54 dated_features = meteofeature.dated_features
55 for date in dated_features:
56 self._X.setdefault(date,{}).update(dated_features[date])
58 if self._config['FEATURES'].getboolean('ephemeris'):
59 ephemerides = Ephemeris(config_file =
60 eval(self._config['FEATURE_CONFIG']['ephemeris']))
62 ephemerides.start = self._start
63 ephemerides.end = self._end
65 dated_features = ephemerides.dated_features
66 for date in dated_features:
67 self._X.setdefault(date,{}).update(dated_features[date])
71 self._target = Target(config_file = eval(self._config['TARGET']['config']),
72 start = self._start, end = self._end,
73 timestep = self._timestep)
76 def add_preprocessing(self):
77 self._preproc = Preprocessing(config_file = self._config,
78 dict_features = self.X,
83 history = self._config['HISTORY_KNOWLEDGE'].getint('nb_lines')
84 self._learner = Learning(config_file = eval(self._config['LEARNER']['config']),
85 X = self._preproc.dataframe, y = list(self.y.values())[history:])