X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/predictops.git/blobdiff_plain/f04d85cc8028a2721d7d5e8ec866ff8022797bb5..refs/heads/master:/predictops/target/target.py diff --git a/predictops/target/target.py b/predictops/target/target.py index b998120..fdff54b 100644 --- a/predictops/target/target.py +++ b/predictops/target/target.py @@ -11,8 +11,8 @@ logger = getLogger() class Target: - def __init__(self, config_file = None, - start = None, end = None, timestep = None): + def __init__(self, config_file=None, + start=None, end=None, timestep=None, cumulative=None): self._config = ConfigParser() self._config.read(config_file) @@ -20,6 +20,7 @@ class Target: self._start = start self._end = end self._timestep = timestep + self._cumulative = cumulative logger.info('Initialization of target variable') self._y = {} @@ -32,8 +33,6 @@ class Target: self._stream_file = eval(self._config['DATA']['csv_file']) self._get_located_interventions() - - @property def start(self): return self._start @@ -42,7 +41,6 @@ class Target: def start(self, x): self._start = x - @property def end(self): return self._end @@ -51,7 +49,6 @@ class Target: def end(self, x): self._end = x - @property def y(self): return self._y @@ -60,44 +57,45 @@ class Target: def end(self, y): self._y = y - - def _get_located_interventions(self): if not self._config['SPECIFICATION'].getboolean('origin')\ and not self._config['SPECIFICATION'].getboolean('destination'): logger.info('Integrating interventions for the whole area') with open(self._stream_file) as f: reader = DictReader(f, delimiter=',') - for row in reader: - if row['start'] != '': - start_interv = datetime.strptime(row['start'], '%d/%m/%Y %H:%M:%S') - start_interv = start_interv.replace(minute=0) - end_interv = datetime.strptime(row['end'], '%d/%m/%Y %H:%M:%S') - end_interv = end_interv.replace(minute=0) - if not (start_interv > self._end or end_interv < self._start): - if start_interv < self._start and end_interv <= self._end: - current = self._start - while current <= end_interv: - self._y[current] += 1 - current += self._timestep - elif start_interv >= self._start and end_interv > self._end: - current = start_interv - while current not in self._y: - current -= timedelta(hours=1) - while current <= self._end: - self._y[current] += 1 - current += self._timestep - elif start_interv >= self._start and end_interv <= self._end: - current = start_interv - while current not in self._y: - current -= timedelta(hours=1) - while current <= end_interv: - self._y[current] += 1 - current += self._timestep - - - - - + if self._cumulative: + for row in reader: + if row['start'] != '': + start_interv = datetime.strptime(row['start'], '%d/%m/%Y %H:%M:%S') + start_interv = start_interv.replace(minute=0) + end_interv = datetime.strptime(row['end'], '%d/%m/%Y %H:%M:%S') + end_interv = end_interv.replace(minute=0) + if not (start_interv > self._end or end_interv < self._start): + if start_interv < self._start and end_interv <= self._end: + current = self._start + while current <= end_interv: + self._y[current] += 1 + current += self._timestep + elif start_interv >= self._start and end_interv > self._end: + current = start_interv + while current not in self._y: + current -= timedelta(hours=1) + while current <= self._end: + self._y[current] += 1 + current += self._timestep + elif start_interv >= self._start and end_interv <= self._end: + current = start_interv + while current not in self._y: + current -= timedelta(hours=1) + while current <= end_interv: + self._y[current] += 1 + current += self._timestep + else: + for row in reader: + if row['start'] != '': + start_interv = datetime.strptime(row['start'], '%d/%m/%Y %H:%M:%S') + start_interv = start_interv.replace(minute=0) + if start_interv in self._y: + self._y[start_interv] += 1