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 # Check for the integrity of feature names
19 super(Source, self).__init__()
21 self._config = ConfigParser()
22 self._config.read(config_file)
24 # Collecting ephemeris features
25 with open(CSV_FILE, "r") as f:
26 reader = DictReader(f, delimiter=',')
27 self._features = [row['name'] for row in reader
28 if self._config['FEATURES'].getboolean(row['name'])]
30 self._dated_features = {}
53 def dated_features(self):
54 if self._dated_features == {}:
56 while date <= self._end:
58 Date = time.strptime(datetime.strftime(date, '%m/%d/%Y %H:%M:%S'), '%m/%d/%Y %H:%M:%S')
59 for feature in self._features:
61 dict_hour['hour'] = Date.tm_hour
62 elif feature == 'dayInWeek':
63 dict_hour['dayInWeek'] = Date.tm_wday
64 elif feature == 'dayInMonth':
65 dict_hour['dayInMonth'] = Date.tm_mday
66 elif feature == 'month':
67 dict_hour['month'] = Date.tm_mon
68 elif feature == 'year':
69 dict_hour['year'] = Date.tm_year
70 elif feature == 'dayInYear':
71 # Si c'est une année bissextile et qu'on est après le 29 février, on compte une journée
72 # dans l'année de moins, car on va supprimer les 29 févriers, de sorte que les 14 juillets,
73 # les 24 décembre... tombent toujours
74 if calendar.isleap(Date.tm_year) and Date >= time.strptime("29/02/"+str(Date.tm_year), "%d/%m/%Y"):
75 dict_hour['dayInYear'] = Date.tm_yday -1
77 dict_hour['dayInYear'] = Date.tm_yday
78 elif feature == 'weekInYear':
79 dict_hour['weekInYear'] = date.isocalendar()[1]
80 self._dated_features[date] = dict_hour
81 date += timedelta(hours=1)
82 return self._dated_features