1 from configparser import ConfigParser
2 from datetime import datetime, timedelta
3 from jours_feries_france.compute import JoursFeries
4 from logging import getLogger
5 from logging.config import fileConfig
6 from vacances_scolaires_france import SchoolHolidayDates
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 holidays 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 _get_academic_zone(self, name, date):
53 'Clermont-Ferrand' : ('A', 'A'),
54 'Grenoble' : ('A', 'A'),
56 'Montpellier' : ('A', 'C'),
57 'Nancy-Metz' : ('A', 'B'),
58 'Nantes' : ('A', 'B'),
59 'Rennes' : ('A', 'B'),
60 'Toulouse' : ('A', 'C'),
61 'Aix-Marseille' : ('B', 'B'),
62 'Amiens' : ('B', 'B'),
63 'Besançon' : ('B', 'A'),
66 'Limoges' : ('B', 'A'),
68 'Orléans-Tours' : ('B', 'B'),
69 'Poitiers' : ('B', 'A'),
71 'Rouen ' : ('B', 'B'),
72 'Strasbourg' : ('B', 'B'),
73 'Bordeaux' : ('C', 'A'),
74 'Créteil' : ('C', 'C'),
76 'Versailles' : ('C', 'C')
78 if date < datetime(2016, 1, 1):
79 return dict_zones[name][0]
81 return dict_zones[name][1]
85 def dated_features(self):
86 if self._dated_features == {}:
87 logger.info("Adding holidays features")
88 bankHolidays = tuple(itertools.chain.from_iterable(list(JoursFeries.for_year(k).values())
89 for k in range(self.start.year, self.end.year+1)))
90 bankHolidaysEve = tuple(u-timedelta(days=1) for u in bankHolidays)
91 name = self._config['ZONE']['name']
93 d = SchoolHolidayDates()
94 while date <= self._end:
95 Date = datetime.date(date)
96 tomorrow = date + timedelta(days=1)
97 Tomorrow = datetime.date(tomorrow)
99 'bankHolidays' : Date in bankHolidays,
100 'bankHolidaysEve': Date in bankHolidaysEve,
101 'holidays': d.is_holiday_for_zone(Date, self._get_academic_zone(name, date)),
102 'holidaysEve': d.is_holiday_for_zone(Tomorrow, self._get_academic_zone(name, tomorrow))
104 self._dated_features[date] = dict_hour
105 date += timedelta(hours=1)
106 return self._dated_features