1 from configparser import ConfigParser
2 from csv import DictReader
3 from datetime import datetime, timedelta
4 from pathlib import Path
9 CSV_FILE = Path.cwd() / 'config' / 'features' / 'ephemeris_features.csv'
16 def __init__(self, config_file):
18 self._config = ConfigParser()
19 self._config.read(config_file)
21 # Collecting ephemeris features
22 with open(CSV_FILE, "r") as f:
23 reader = DictReader(f, delimiter=',')
24 self._features = [row['name'] for row in reader
25 if self._config['FEATURES'].getboolean(row['name'])]
27 self._dated_features = {}
50 def dated_features(self):
51 if self._dated_features == {}:
53 while date <= self._end:
55 Date = time.strptime(datetime.strftime(date, '%m/%d/%Y %H:%M:%S'), '%m/%d/%Y %H:%M:%S')
56 for feature in self._features:
58 dict_hour['hour'] = Date.tm_hour
59 elif feature == 'dayInWeek':
60 dict_hour['dayInWeek'] = Date.tm_wday
61 elif feature == 'dayInMonth':
62 dict_hour['dayInMonth'] = Date.tm_mday
63 elif feature == 'month':
64 dict_hour['month'] = Date.tm_mon
65 elif feature == 'year':
66 dict_hour['year'] = Date.tm_year
67 elif feature == 'dayInYear':
68 # Si c'est une année bissextile et qu'on est après le 29 février, on compte une journée
69 # dans l'année de moins, car on va supprimer les 29 févriers, de sorte que les 14 juillets,
70 # les 24 décembre... tombent toujours
71 if calendar.isleap(Date.tm_year) and Date >= time.strptime("29/02/"+str(Date.tm_year), "%d/%m/%Y"):
72 dict_hour['dayInYear'] = Date.tm_yday -1
74 dict_hour['dayInYear'] = Date.tm_yday
75 elif feature == 'weekInYear':
76 dict_hour['weekInYear'] = date.isocalendar()[1]
77 self._dated_features[date] = dict_hour
78 date += timedelta(hours=1)
79 return self._dated_features