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

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