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 pathlib import Path
7 from vacances_scolaires_france import SchoolHolidayDates
11 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
19 def __init__(self, config_file):
21 self._config = ConfigParser()
22 self._config.read(config_file)
24 # Collecting holidays features
25 self._features = [section for section in self._config
26 if self._config[section].getboolean('numerical')
27 or self._config[section].getboolean('categorical')]
29 self._dated_features = {}
51 def _get_academic_zone(self, name, date):
54 'Clermont-Ferrand' : ('A', 'A'),
55 'Grenoble' : ('A', 'A'),
57 'Montpellier' : ('A', 'C'),
58 'Nancy-Metz' : ('A', 'B'),
59 'Nantes' : ('A', 'B'),
60 'Rennes' : ('A', 'B'),
61 'Toulouse' : ('A', 'C'),
62 'Aix-Marseille' : ('B', 'B'),
63 'Amiens' : ('B', 'B'),
64 'Besançon' : ('B', 'A'),
67 'Limoges' : ('B', 'A'),
69 'Orléans-Tours' : ('B', 'B'),
70 'Poitiers' : ('B', 'A'),
72 'Rouen ' : ('B', 'B'),
73 'Strasbourg' : ('B', 'B'),
74 'Bordeaux' : ('C', 'A'),
75 'Créteil' : ('C', 'C'),
77 'Versailles' : ('C', 'C')
79 if date < datetime(2016, 1, 1):
80 return dict_zones[name][0]
82 return dict_zones[name][1]
86 def dated_features(self):
87 if self._dated_features == {}:
88 logger.info("Adding holidays features")
89 bankHolidays = tuple(itertools.chain.from_iterable(list(JoursFeries.for_year(k).values())
90 for k in range(self.start.year, self.end.year+1)))
91 bankHolidaysEve = tuple(u-timedelta(days=1) for u in bankHolidays)
92 name = self._config['ZONE']['name']
94 Date = datetime.date(date)
95 tomorrow = date + timedelta(days=1)
96 Tomorrow = datetime.date(tomorrow)
97 d = SchoolHolidayDates()
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 while date <= self._end:
105 self._dated_features[date] = dict_hour
107 date += timedelta(hours=1)
108 if date.day != current.day:
109 Date = datetime.date(date)
110 tomorrow = date + timedelta(days=1)
111 Tomorrow = datetime.date(tomorrow)
113 'bankHolidays' : Date in bankHolidays,
114 'bankHolidaysEve': Date in bankHolidaysEve,
115 'holidays': d.is_holiday_for_zone(Date, self._get_academic_zone(name, date)),
116 'holidaysEve': d.is_holiday_for_zone(Tomorrow, self._get_academic_zone(name, tomorrow))
118 return self._dated_features