1 from configparser import ConfigParser
2 from csv import DictReader
3 from datetime import datetime, timedelta
4 from logging import getLogger
5 from logging.config import fileConfig
6 from pathlib import Path
8 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
14 def __init__(self, config_file = None,
15 start = None, end = None, timestep = None):
17 self._config = ConfigParser()
18 self._config.read(config_file)
22 self._timestep = timestep
24 logger.info('Initialization of target variable')
27 while current <= self._end:
29 current += self._timestep
31 self._timestep = timestep
32 self._stream_file = eval(self._config['DATA']['csv_file'])
33 self._get_located_interventions()
65 def _get_located_interventions(self):
66 if not self._config['SPECIFICATION'].getboolean('origin')\
67 and not self._config['SPECIFICATION'].getboolean('destination'):
68 logger.info('Integrating interventions for the whole area')
69 with open(self._stream_file) as f:
70 reader = DictReader(f, delimiter=',')
72 if row['start'] != '':
73 start_interv = datetime.strptime(row['start'], '%d/%m/%Y %H:%M:%S')
74 start_interv = start_interv.replace(minute=0)
75 end_interv = datetime.strptime(row['end'], '%d/%m/%Y %H:%M:%S')
76 end_interv = end_interv.replace(minute=0)
77 if not (start_interv > self._end or end_interv < self._start):
78 if start_interv < self._start and end_interv <= self._end:
80 while current <= end_interv:
82 current += self._timestep
83 elif start_interv >= self._start and end_interv > self._end:
84 current = start_interv
85 while current not in self._y:
86 current -= timedelta(hours=1)
87 while current <= self._end:
89 current += self._timestep
90 elif start_interv >= self._start and end_interv <= self._end:
91 current = start_interv
92 while current not in self._y:
93 current -= timedelta(hours=1)
94 while current <= end_interv:
96 current += self._timestep