1 from configparser import ConfigParser
2 from datetime import datetime, timedelta
3 from logging import getLogger
4 from logging.config import fileConfig
5 from pathlib import Path
10 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
18 def __init__(self, config_file):
20 self._config = ConfigParser()
21 self._config.read(config_file)
23 # Collecting ephemeris features
24 self._features = [section for section in self._config
25 if self._config[section].getboolean('numerical')
26 or self._config[section].getboolean('categorical')]
28 self._dated_features = {}
50 def dated_features(self):
51 if self._dated_features == {}:
52 logger.info("Adding ephemeris features")
54 while date <= self._end:
56 Date = time.strptime(datetime.strftime(date, '%m/%d/%Y %H:%M:%S'), '%m/%d/%Y %H:%M:%S')
57 for feature in self._features:
59 dict_hour['hour'] = Date.tm_hour
60 elif feature == 'dayInWeek':
61 dict_hour['dayInWeek'] = Date.tm_wday
62 elif feature == 'dayInMonth':
63 dict_hour['dayInMonth'] = Date.tm_mday
64 elif feature == 'month':
65 dict_hour['month'] = Date.tm_mon
66 elif feature == 'year':
67 dict_hour['year'] = Date.tm_year
68 elif feature == 'dayInYear':
69 # Si c'est une année bissextile et qu'on est après le 29 février, on compte une journée
70 # dans l'année de moins, car on va supprimer les 29 févriers, de sorte que les 14 juillets,
71 # les 24 décembre... tombent toujours
72 if calendar.isleap(Date.tm_year) and Date >= time.strptime("29/02/"+str(Date.tm_year), "%d/%m/%Y"):
73 dict_hour['dayInYear'] = Date.tm_yday -1
75 dict_hour['dayInYear'] = Date.tm_yday
76 elif feature == 'weekInYear':
77 dict_hour['weekInYear'] = date.isocalendar()[1]
78 self._dated_features[date] = dict_hour
79 date += timedelta(hours=1)
80 return self._dated_features