]> AND Private Git Repository - predictops.git/blob - predictops/engine.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Integrating historical features
[predictops.git] / predictops / engine.py
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
7
8 from .source.ephemeris import Ephemeris
9 from .source.meteofrance import MeteoFrance
10 from .learn.preprocessing import Preprocessing
11 from .target.target import Target
12
13 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
14 logger = getLogger()
15
16
17 class Engine:
18
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'],
23                                         '%m/%d/%Y %H:%M:%S')
24         self._end = datetime.strptime(self._config['DATETIME']['end'],
25                                         '%m/%d/%Y %H:%M:%S')
26
27         self._timestep = timedelta(hours =
28                                    self._config['DATETIME'].getfloat('hourStep'))
29
30         self._X = {}
31
32
33
34     def clean(self):
35         # Cleaning the data directory
36         logger.info("Cleaning and restoring data directory")
37         directory  = Path.cwd() / 'data'
38         if directory.is_dir():
39             rmtree(directory)
40         p = Path(Path.cwd() / 'data')
41         p.mkdir()
42
43
44     def add_features(self):
45         if self._config['FEATURES'].getboolean('meteofrance'):
46             meteofeature = MeteoFrance(config_file =
47                                        eval(self._config['FEATURE_CONFIG']['meteofrance']))
48
49             meteofeature.start = self._start
50             meteofeature.end = self._end
51
52             meteofeature.update()
53             dated_features = meteofeature.dated_features
54             for date in dated_features:
55                 self._X.setdefault(date,{}).update(dated_features[date])
56
57         if self._config['FEATURES'].getboolean('ephemeris'):
58             ephemerides = Ephemeris(config_file =
59                                     eval(self._config['FEATURE_CONFIG']['ephemeris']))
60
61             ephemerides.start = self._start
62             ephemerides.end = self._end
63
64             dated_features = ephemerides.dated_features
65             for date in dated_features:
66                 self._X.setdefault(date,{}).update(dated_features[date])
67
68
69     def add_target(self):
70         self._target = Target(config_file = eval(self._config['TARGET']['config']),
71                               start = self._start, end = self._end,
72                               timestep = self._timestep)
73
74
75     def add_preprocessing(self):
76         process = Preprocessing(config_file = self._config,
77                                 dict_features = self.X,
78                                 dict_target = self.y)
79         print(process.dataframe.head(n=2))
80
81
82
83     @property
84     def X(self):
85         return self._X
86
87     @X.setter
88     def X(self, x):
89         self._X = x
90
91
92     @property
93     def y(self):
94         return self._target.y
95
96     @y.setter
97     def end(self, y):
98         self._target.y = y