1 from configparser import ConfigParser
2 from convertdate import islamic
3 from datetime import datetime, timedelta
4 from logging import getLogger
5 from logging.config import fileConfig
6 from pathlib import Path
9 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('binary')
26 or self._config[section].getboolean('categorical')
27 or self._config[section].getboolean('numerical')]
29 self._dated_features = {}
48 def dated_features(self):
49 if self._dated_features == {}:
50 logger.info("Adding Ramadan features")
52 while date <= self._end:
53 year, month, day = date.year, date.month, date.day
54 eve = datetime(year, month, day) - timedelta(days=1)
55 tomorrow = datetime(year, month, day) + timedelta(days=1)
56 Hegirian_month = islamic.from_gregorian(year, month, day)[1]
60 'ramadanDayAfter': False
62 if Hegirian_month == 8 and\
63 islamic.from_gregorian(tomorrow.year, tomorrow.month, tomorrow.day)[1] == 9:
64 dict_hour['ramadanEve'] = True
65 elif Hegirian_month == 9:
66 dict_hour['ramadan'] = True
67 elif Hegirian_month == 10 and\
68 islamic.from_gregorian(eve.year, eve.month, eve.day)[1] == 9:
69 dict_hour['ramadanDayAfter'] = True
70 self._dated_features[date] = dict_hour
71 date += timedelta(hours=1)
72 return self._dated_features