X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/predictops.git/blobdiff_plain/90e69cb2125d4bae76a27b9c38defb4f70bf2ca6..7ee7381044cbe0539ec18052a77b9f6600678bb9:/predictops/source/holidays.py diff --git a/predictops/source/holidays.py b/predictops/source/holidays.py index 6893db0..db61f01 100644 --- a/predictops/source/holidays.py +++ b/predictops/source/holidays.py @@ -11,10 +11,11 @@ import itertools fileConfig((Path.cwd() / 'config') / 'logging.cfg') logger = getLogger() + class Holidays: _start = None - _end = None + _end = None def __init__(self, config_file): @@ -23,12 +24,12 @@ class Holidays: # Collecting holidays features self._features = [section for section in self._config - if self._config[section].getboolean('numerical') - or self._config[section].getboolean('categorical')] + if self._config[section].getboolean('binary') + or self._config[section].getboolean('categorical') + or self._config[section].getboolean('numerical')] self._dated_features = {} - @property def start(self): return self._start @@ -37,7 +38,6 @@ class Holidays: def start(self, x): self._start = x - @property def end(self): return self._end @@ -46,49 +46,46 @@ class Holidays: def end(self, x): self._end = x - - def _get_academic_zone(self, name, date): dict_zones = { - 'Caen' : ('A', 'B'), - 'Clermont-Ferrand' : ('A', 'A'), - 'Grenoble' : ('A', 'A'), - 'Lyon' : ('A', 'A'), - 'Montpellier' : ('A', 'C'), - 'Nancy-Metz' : ('A', 'B'), - 'Nantes' : ('A', 'B'), - 'Rennes' : ('A', 'B'), - 'Toulouse' : ('A', 'C'), - 'Aix-Marseille' : ('B', 'B'), - 'Amiens' : ('B', 'B'), - 'Besançon' : ('B', 'A'), - 'Dijon' : ('B', 'A'), - 'Lille' : ('B', 'B'), - 'Limoges' : ('B', 'A'), - 'Nice' : ('B', 'B'), - 'Orléans-Tours' : ('B', 'B'), - 'Poitiers' : ('B', 'A'), - 'Reims' : ('B', 'B'), - 'Rouen ' : ('B', 'B'), - 'Strasbourg' : ('B', 'B'), - 'Bordeaux' : ('C', 'A'), - 'Créteil' : ('C', 'C'), - 'Paris' : ('C', 'C'), - 'Versailles' : ('C', 'C') + 'Caen': ('A', 'B'), + 'Clermont-Ferrand': ('A', 'A'), + 'Grenoble': ('A', 'A'), + 'Lyon': ('A', 'A'), + 'Montpellier': ('A', 'C'), + 'Nancy-Metz': ('A', 'B'), + 'Nantes': ('A', 'B'), + 'Rennes': ('A', 'B'), + 'Toulouse': ('A', 'C'), + 'Aix-Marseille': ('B', 'B'), + 'Amiens': ('B', 'B'), + 'Besançon': ('B', 'A'), + 'Dijon': ('B', 'A'), + 'Lille': ('B', 'B'), + 'Limoges': ('B', 'A'), + 'Nice': ('B', 'B'), + 'Orléans-Tours': ('B', 'B'), + 'Poitiers': ('B', 'A'), + 'Reims': ('B', 'B'), + 'Rouen ': ('B', 'B'), + 'Strasbourg': ('B', 'B'), + 'Bordeaux': ('C', 'A'), + 'Créteil': ('C', 'C'), + 'Paris': ('C', 'C'), + 'Versailles': ('C', 'C') } if date < datetime(2016, 1, 1): return dict_zones[name][0] else: return dict_zones[name][1] - @property def dated_features(self): if self._dated_features == {}: logger.info("Adding holidays features") bankHolidays = tuple(itertools.chain.from_iterable(list(JoursFeries.for_year(k).values()) - for k in range(self.start.year, self.end.year+1))) - bankHolidaysEve = tuple(u-timedelta(days=1) for u in bankHolidays) + for k in range(self.start.year, self.end.year + 1))) + bankHolidaysEve = tuple(u - timedelta(days=1) for u in bankHolidays) name = self._config['ZONE']['name'] date = self._start Date = datetime.date(date) @@ -96,7 +93,7 @@ class Holidays: Tomorrow = datetime.date(tomorrow) d = SchoolHolidayDates() dict_hour = { - 'bankHolidays' : Date in bankHolidays, + 'bankHolidays': Date in bankHolidays, 'bankHolidaysEve': Date in bankHolidaysEve, 'holidays': d.is_holiday_for_zone(Date, self._get_academic_zone(name, date)), 'holidaysEve': d.is_holiday_for_zone(Tomorrow, self._get_academic_zone(name, tomorrow)) @@ -110,9 +107,9 @@ class Holidays: tomorrow = date + timedelta(days=1) Tomorrow = datetime.date(tomorrow) dict_hour = { - 'bankHolidays' : Date in bankHolidays, + 'bankHolidays': Date in bankHolidays, 'bankHolidaysEve': Date in bankHolidaysEve, 'holidays': d.is_holiday_for_zone(Date, self._get_academic_zone(name, date)), 'holidaysEve': d.is_holiday_for_zone(Tomorrow, self._get_academic_zone(name, tomorrow)) } - return self._dated_features \ No newline at end of file + return self._dated_features