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.preprocessing import Preprocessing
11 from .target.target import Target
13 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
19 def __init__(self, config_file = (Path.cwd() / 'config') / 'learn.cfg'):
20 self._config = ConfigParser()
21 self._config.read(config_file)
22 self._start = datetime.strptime(self._config['DATETIME']['start'],
24 self._end = datetime.strptime(self._config['DATETIME']['end'],
27 self._timestep = timedelta(hours =
28 self._config['DATETIME'].getfloat('hourStep'))
35 # Cleaning the data directory
36 logger.info("Cleaning and restoring data directory")
37 directory = Path.cwd() / 'data'
38 if directory.is_dir():
40 p = Path(Path.cwd() / 'data')
44 def add_features(self):
45 if self._config['FEATURES'].getboolean('meteofrance'):
46 meteofeature = MeteoFrance(config_file =
47 eval(self._config['FEATURE_CONFIG']['meteofrance']))
49 meteofeature.start = self._start
50 meteofeature.end = self._end
53 dated_features = meteofeature.dated_features
54 for date in dated_features:
55 self._X.setdefault(date,{}).update(dated_features[date])
57 if self._config['FEATURES'].getboolean('ephemeris'):
58 ephemerides = Ephemeris(config_file =
59 eval(self._config['FEATURE_CONFIG']['ephemeris']))
61 ephemerides.start = self._start
62 ephemerides.end = self._end
64 dated_features = ephemerides.dated_features
65 for date in dated_features:
66 self._X.setdefault(date,{}).update(dated_features[date])
70 self._target = Target(config_file = eval(self._config['TARGET']['config']),
71 start = self._start, end = self._end,
72 timestep = self._timestep)
75 def add_preprocessing(self):
76 process = Preprocessing(config_file = self._config,
77 dict_features = self.X,
79 print(process.dataframe.head(n=2))