+from configparser import ConfigParser
+from datetime import datetime, timedelta
+from jours_feries_france.compute import JoursFeries
+from logging import getLogger
+from logging.config import fileConfig
+from vacances_scolaires_france import SchoolHolidayDates
+
+import itertools
+
+fileConfig((Path.cwd() / 'config') / 'logging.cfg')
+logger = getLogger()
+
+class Holidays:
+
+ _start = None
+ _end = None
+
+ def __init__(self, config_file):
+
+ self._config = ConfigParser()
+ self._config.read(config_file)
+
+ # Collecting holidays features
+ self._features = [section for section in self._config
+ if self._config[section].getboolean('numerical')
+ or self._config[section].getboolean('categorical')]
+
+ self._dated_features = {}
+
+
+ @property
+ def start(self):
+ return self._start
+
+ @start.setter
+ def start(self, x):
+ self._start = x
+
+
+ @property
+ def end(self):
+ return self._end
+
+ @end.setter
+ 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')
+ }
+ 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)
+ name = self._config['ZONE']['name']
+ date = self._start
+ d = SchoolHolidayDates()
+ while date <= self._end:
+ Date = datetime.date(date)
+ tomorrow = date + timedelta(days=1)
+ Tomorrow = datetime.date(tomorrow)
+ dict_hour = {
+ '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))
+ }
+ self._dated_features[date] = dict_hour
+ date += timedelta(hours=1)
+ return self._dated_features
\ No newline at end of file