]> AND Private Git Repository - predictops.git/blobdiff - predictops/target/target.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Adding ramadan features, and binary category of feat.
[predictops.git] / predictops / target / target.py
index b998120b1be6b3b5524e8263c155370b6edceb98..9e3d86d31de82f24ad8a8c2bd6abf6e742f446fe 100644 (file)
@@ -12,7 +12,7 @@ logger = getLogger()
 class Target:
 
     def __init__(self, config_file = None,
 class Target:
 
     def __init__(self, config_file = None,
-                 start = None, end = None, timestep = None):
+                 start = None, end = None, timestep = None, cumulative = None):
 
         self._config = ConfigParser()
         self._config.read(config_file)
 
         self._config = ConfigParser()
         self._config.read(config_file)
@@ -20,6 +20,7 @@ class Target:
         self._start = start
         self._end = end
         self._timestep = timestep
         self._start = start
         self._end = end
         self._timestep = timestep
+        self._cumulative = cumulative
 
         logger.info('Initialization of target variable')
         self._y = {}
 
         logger.info('Initialization of target variable')
         self._y = {}
@@ -68,36 +69,39 @@ class Target:
             logger.info('Integrating interventions for the whole area')
             with open(self._stream_file) as f:
                 reader = DictReader(f, delimiter=',')
             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