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

Private GIT Repository
Refactoring, and categorical / numerical / mixed NaN values are now
[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
11 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
12 logger = getLogger()
13
14
15 class Engine:
16
17     def __init__(self, config_file = (Path.cwd() / 'config') / 'learn.cfg'):
18         self._config = ConfigParser()
19         self._config.read(config_file)
20         self._start = datetime.strptime(self._config['DATETIME']['start'],
21                                         '%m/%d/%Y %H:%M:%S')
22         self._end = datetime.strptime(self._config['DATETIME']['end'],
23                                         '%m/%d/%Y %H:%M:%S')
24
25         self._timestep = timedelta(hours =
26                                    self._config['DATETIME'].getfloat('hourStep'))
27
28         self._X = {}
29         self._Y = {}
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     @property
69     def X(self):
70         return self._X
71
72     @X.setter
73     def X(self, x):
74         self._X = x