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

Private GIT Repository
a6a8d742d6c4c21d1447e92221880bae1dae4632
[predictops.git] / main.py
1 from lib.source.ephemeris import Ephemeris
2 from lib.source.meteofrance import MeteoFrance
3
4 from datetime import datetime
5 from logging import getLogger
6 from logging.config import fileConfig
7 from pathlib import Path
8 from shutil import rmtree
9
10 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
11 logger = getLogger()
12
13
14 class Engine:
15     def __init__(self, start = None, end = None, time_step = None):
16         logger.info("Predictops engine launched")
17         self._X = {}
18         self._Y = {}
19
20
21     def clean(self):
22         # Cleaning the data directory
23         logger.info("Cleaning and restoring data directory")
24         directory  = Path.cwd() / 'data'
25         if directory.is_dir():
26             rmtree(directory)
27         p = Path(Path.cwd() / 'data')
28         p.mkdir()
29
30
31     def add_feature(self, name, **kw):
32
33         if name == 'meteofrance':
34             meteofeature = MeteoFrance(**kw)
35             meteofeature.update()
36             dated_features = meteofeature.dated_features
37             for date in dated_features:
38                 self._X.setdefault(date,{}).update(dated_features[date])
39         elif name == 'ephemeris':
40             ephemerides = Ephemeris(**kw)
41             dated_features = ephemerides.dated_features
42             for date in dated_features:
43                 self._X.setdefault(date,{}).update(dated_features[date])
44
45
46     @property
47     def X(self):
48         return self._X
49
50     @X.setter
51     def X(self, x):
52         self._X = x
53
54
55 start = datetime.strptime('01/01/2010 00:00:00', '%m/%d/%Y %H:%M:%S')
56 end = datetime.strptime('12/31/2010 23:00:00', '%m/%d/%Y %H:%M:%S')
57
58 engine = Engine()
59 engine.add_feature(name = 'meteofrance',
60                    start = start, end = end,
61                    latitude = 47.25, longitude = 6.0333, nb_stations = 3,
62                    features = ['temperature', 'pressure'])
63
64 engine.add_feature(name = 'ephemeris',
65                    start = start, end = end,
66                    features = ['hour', 'dayInWeek', 'dayInMonth', 'dayInYear',
67                                'weekInYear', 'month', 'year'])
68
69
70
71 print(engine.X[datetime.strptime('06/30/2010 21:00:00', '%m/%d/%Y %H:%M:%S')])