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