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

Private GIT Repository
a42ce0f11cb9b42feae17fa17e1abcdf513b8570
[predictops.git] / main.py
1 from predictops.source.ephemeris import Ephemeris
2 from predictops.source.meteofrance import MeteoFrance
3 from predictops.learn.preprocessing import Preprocessing
4 from predictops.target.toarea import ToArea
5
6 from datetime import datetime, timedelta
7 from logging import getLogger
8 from logging.config import fileConfig
9 from pathlib import Path
10 from shutil import rmtree
11
12 import geopandas as gpd
13
14 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
15 logger = getLogger()
16
17
18 class Engine:
19     def __init__(self, start = None, end = None, time_step = None):
20         self._X = {}
21         self._Y = {}
22
23
24     def clean(self):
25         # Cleaning the data directory
26         logger.info("Cleaning and restoring data directory")
27         directory  = Path.cwd() / 'data'
28         if directory.is_dir():
29             rmtree(directory)
30         p = Path(Path.cwd() / 'data')
31         p.mkdir()
32
33
34     def add_feature(self, name, **kw):
35
36         if name == 'meteofrance':
37             meteofeature = MeteoFrance(**kw)
38             meteofeature.update()
39             dated_features = meteofeature.dated_features
40             for date in dated_features:
41                 self._X.setdefault(date,{}).update(dated_features[date])
42         elif name == 'ephemeris':
43             ephemerides = Ephemeris(**kw)
44             dated_features = ephemerides.dated_features
45             for date in dated_features:
46                 self._X.setdefault(date,{}).update(dated_features[date])
47
48
49     @property
50     def X(self):
51         return self._X
52
53     @X.setter
54     def X(self, x):
55         self._X = x
56
57
58 start = datetime.strptime('01/01/2010 01:00:00', '%m/%d/%Y %H:%M:%S')
59 end = datetime.strptime('12/31/2010 23:00:00', '%m/%d/%Y %H:%M:%S')
60
61 engine = Engine()
62 engine.add_feature(name = 'meteofrance',
63                    start = start, end = end,
64                    latitude = 47.25, longitude = 6.0333, nb_stations = 3,
65                    features = ['temperature', 'pressure'])
66
67
68 engine.add_feature(name = 'ephemeris',
69                    start = start, end = end,
70                    features = ['hour', 'dayInWeek', 'dayInMonth', 'dayInYear',
71                                'weekInYear', 'month', 'year'])
72
73
74 process = Preprocessing(dict_features = engine.X,
75                    start = start, end = end, timestep = timedelta(hours=6))
76
77
78 df = process.dataframe.head(n=20)
79 #print(engine.X[datetime.strptime('06/30/2010 21:00:00', '%m/%d/%Y %H:%M:%S')])
80 print(df)
81 exit()
82
83 depts = gpd.read_file( Path.cwd() / 'data' / 'targets' / 'departments' / "departements-20180101.shp")
84 Doubs = depts.loc[depts['nom'] == 'Doubs'].iloc[0]
85
86 ToArea(area=Doubs.geometry,
87        start = start, end = end,
88        csv_file = Path.cwd() / 'data' / 'targets' / 'sdis25' / 'interventions.csv')
89