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

Private GIT Repository
Bug fixed and starting to work on the target variable
[predictops.git] / lib / source / ephemeris.py
1 from datetime import datetime, timedelta
2 import time
3 import calendar
4
5 class Ephemeris:
6
7     def __init__(self, start = time.strptime('19960101000000', '%Y%m%d%H%M%S'),
8                  end = datetime.now(), features = []):
9         self._start = start
10         self._end = end
11         self._features = features
12
13         self._dated_features = {}
14
15
16
17     def update(self):
18         pass
19
20
21
22     @property
23     def dated_features(self):
24         if self._dated_features == {}:
25             date = self._start
26             while date <= self._end:
27                 dict_hour = {}
28                 Date = time.strptime(datetime.strftime(date, '%m/%d/%Y %H:%M:%S'), '%m/%d/%Y %H:%M:%S')
29                 for feature in self._features:
30                     if feature == 'hour':
31                         dict_hour['hour'] = Date.tm_hour
32                     elif feature == 'dayInWeek':
33                         dict_hour['dayInWeek'] = Date.tm_wday
34                     elif feature == 'dayInMonth':
35                         dict_hour['dayInMonth'] = Date.tm_mday
36                     elif feature == 'month':
37                         dict_hour['month'] = Date.tm_mon
38                     elif feature == 'year':
39                         dict_hour['year'] = Date.tm_year
40                     elif feature == 'dayInYear':
41                         # Si c'est une année bissextile et qu'on est après le 29 février, on compte une journée
42                         # dans l'année de moins, car on va supprimer les 29 févriers, de sorte que les 14 juillets,
43                         # les 24 décembre... tombent toujours
44                         if calendar.isleap(Date.tm_year) and Date >= time.strptime("29/02/"+str(Date.tm_year), "%d/%m/%Y"):
45                             dict_hour['dayInYear'] = Date.tm_yday -1
46                         else:
47                             dict_hour['dayInYear'] = Date.tm_yday
48                     elif feature == 'weekInYear':
49                         dict_hour['weekInYear'] = date.isocalendar()[1]
50                 self._dated_features[date] = dict_hour
51                 date += timedelta(hours=1)
52         return self._dated_features