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

Private GIT Repository
The module to generate the y variable is now created
authorChristophe Guyeux <christophe.guyeux@univ-fcomte.fr>
Tue, 18 Feb 2020 09:06:15 +0000 (10:06 +0100)
committerChristophe Guyeux <christophe.guyeux@univ-fcomte.fr>
Tue, 18 Feb 2020 09:06:15 +0000 (10:06 +0100)
config/learn.cfg
config/targets/sdis25.cfg [new file with mode: 0644]
main.py
predictops/engine.py
predictops/target/all.py [deleted file]
predictops/target/target.py [new file with mode: 0644]
predictops/target/toarea.py

index 9475c783e083916f0e045820a0e6f528d2d79807..f6b2e430f60debb523bc70bdccac3ab7a8fff8ae 100644 (file)
@@ -16,4 +16,8 @@ ephemeris   = (Path.cwd() / 'config') / 'features' / 'feature_ephemeris.cfg'
 
 [PREPROCESSING]
 fill_method = spline
 
 [PREPROCESSING]
 fill_method = spline
-order       = 3
\ No newline at end of file
+order       = 3
+
+
+[TARGET]
+config = (Path.cwd() / 'config') / 'targets' / 'sdis25.cfg'
diff --git a/config/targets/sdis25.cfg b/config/targets/sdis25.cfg
new file mode 100644 (file)
index 0000000..712e93b
--- /dev/null
@@ -0,0 +1,6 @@
+[SPECIFICATION]
+origin      = False
+destination = False
+
+[DATA]
+csv_file = (Path.cwd() / 'data') / 'targets' / 'sdis25' / 'interventions.csv'
\ No newline at end of file
diff --git a/main.py b/main.py
index 9e35b2da9acf12c39b784454a8c420dae5ce2bb4..969054c7ce186040b11a918c079a32b3a240cf94 100644 (file)
--- a/main.py
+++ b/main.py
@@ -1,7 +1,5 @@
 from predictops.engine import Engine
 from predictops.learn.preprocessing import Preprocessing
 from predictops.engine import Engine
 from predictops.learn.preprocessing import Preprocessing
-from predictops.target.all import All
-from predictops.target.toarea import ToArea
 
 from logging import getLogger
 from logging.config import fileConfig
 
 from logging import getLogger
 from logging.config import fileConfig
@@ -18,16 +16,14 @@ if __name__ == '__main__':
     engine = Engine(config_file = config)
 
     engine.add_features()
     engine = Engine(config_file = config)
 
     engine.add_features()
-    #print(engine.X)
-    process = Preprocessing(config_file = config, dict_features = engine.X)
+    engine.add_target()
 
 
+    process = Preprocessing(config_file = config, dict_features = engine.X)
 
 
-    #print(engine.X[datetime.strptime('06/30/2010 21:00:00', '%m/%d/%Y %H:%M:%S')])
     print(process.dataframe.head(n=20))
     print(process.dataframe.tail(n=20))
 
     print(process.dataframe.head(n=20))
     print(process.dataframe.tail(n=20))
 
-
-    target = All(stream_file = Path.cwd() / 'data' / 'targets' / 'sdis25' / 'interventions.csv')
+    #target = toarea(stream_file = Path.cwd() / 'data' / 'targets' / 'sdis25' / 'interventions.csv')
 
 
     exit()
 
 
     exit()
@@ -36,6 +32,5 @@ if __name__ == '__main__':
     Doubs = depts.loc[depts['nom'] == 'Doubs'].iloc[0]
 
     ToArea(area=Doubs.geometry,
     Doubs = depts.loc[depts['nom'] == 'Doubs'].iloc[0]
 
     ToArea(area=Doubs.geometry,
-           start = start, end = end,
            csv_file = Path.cwd() / 'data' / 'targets' / 'sdis25' / 'interventions.csv')
 
            csv_file = Path.cwd() / 'data' / 'targets' / 'sdis25' / 'interventions.csv')
 
index 8ba5043ebfdec4ef386aef2cf223b7cb52407d0a..dedd2652cdd9efc97eaf24d26c1d3bd66a1398ec 100644 (file)
@@ -7,6 +7,7 @@ from shutil import rmtree
 
 from .source.ephemeris import Ephemeris
 from .source.meteofrance import MeteoFrance
 
 from .source.ephemeris import Ephemeris
 from .source.meteofrance import MeteoFrance
+from .target.target import Target
 
 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
 logger = getLogger()
 
 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
 logger = getLogger()
@@ -26,7 +27,6 @@ class Engine:
                                    self._config['DATETIME'].getfloat('hourStep'))
 
         self._X = {}
                                    self._config['DATETIME'].getfloat('hourStep'))
 
         self._X = {}
-        self._Y = {}
 
 
 
 
 
 
@@ -65,10 +65,25 @@ class Engine:
                 self._X.setdefault(date,{}).update(dated_features[date])
 
 
                 self._X.setdefault(date,{}).update(dated_features[date])
 
 
+    def add_target(self):
+        self._target = Target(config_file = eval(self._config['TARGET']['config']),
+                              start = self._start, end = self._end,
+                              timestep = self._timestep)
+
+
     @property
     def X(self):
         return self._X
 
     @X.setter
     def X(self, x):
     @property
     def X(self):
         return self._X
 
     @X.setter
     def X(self, x):
-        self._X = x
\ No newline at end of file
+        self._X = x
+
+
+    @property
+    def y(self):
+        return self._target.y
+
+    @y.setter
+    def end(self, y):
+        self._target.y = y
diff --git a/predictops/target/all.py b/predictops/target/all.py
deleted file mode 100644 (file)
index 0d9d72b..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-from csv import DictReader
-
-class All:
-
-    _start = None
-    _end   = None
-
-    def __init__(self, stream_file = None):
-        self._stream_file = stream_file
-        self._get_located_interventions()
-
-
-    def _get_located_interventions(self):
-        with open(self._stream_file) as f:
-            reader = DictReader(f, delimiter=',')
-            for row in reader:
-                print(row)
-
diff --git a/predictops/target/target.py b/predictops/target/target.py
new file mode 100644 (file)
index 0000000..b998120
--- /dev/null
@@ -0,0 +1,103 @@
+from configparser import ConfigParser
+from csv import DictReader
+from datetime import datetime, timedelta
+from logging import getLogger
+from logging.config import fileConfig
+from pathlib import Path
+
+fileConfig((Path.cwd() / 'config') / 'logging.cfg')
+logger = getLogger()
+
+
+class Target:
+
+    def __init__(self, config_file = None,
+                 start = None, end = None, timestep = None):
+
+        self._config = ConfigParser()
+        self._config.read(config_file)
+
+        self._start = start
+        self._end = end
+        self._timestep = timestep
+
+        logger.info('Initialization of target variable')
+        self._y = {}
+        current = self._start
+        while current <= self._end:
+            self._y[current] = 0
+            current += self._timestep
+
+        self._timestep = timestep
+        self._stream_file = eval(self._config['DATA']['csv_file'])
+        self._get_located_interventions()
+
+
+
+    @property
+    def start(self):
+        return self._start
+
+    @start.setter
+    def start(self, x):
+        self._start = x
+
+
+    @property
+    def end(self):
+        return self._end
+
+    @end.setter
+    def end(self, x):
+        self._end = x
+
+
+    @property
+    def y(self):
+        return self._y
+
+    @y.setter
+    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
+
+
+
+
+
+
+
index 1454e9d862a54d3d03ddf5acbbe7a597439ed6e9..aa6911bb38c632b06eff3c4cca81748ae8067d3a 100644 (file)
@@ -3,21 +3,22 @@ from datetime import datetime
 
 class ToArea:
 
 
 class ToArea:
 
-    def __init__(self, area = None,
-                 start = datetime.strptime('19960101000000', '%Y%m%d%H%M%S'),
-                 end = datetime.now(),
-                 csv_file = None):
+    def __init__(self, area = None, stream_file = None):
 
         self._area = area
 
         self._area = area
-        self._csv_file = csv_file
+        self._stream_file = stream_file
         self._get_located_interventions()
 
 
     def _get_located_interventions(self):
         self._get_located_interventions()
 
 
     def _get_located_interventions(self):
-        with open(self._csv_file) as f:
+        with open(self._stream_file) as f:
             reader = DictReader(f, delimiter=',')
             for row in reader:
             reader = DictReader(f, delimiter=',')
             for row in reader:
-                print(row)
+                start = datetime.strptime(row['start'], '%d/%m/%Y %H:%M:%S')
+                start.minute = 0
+                end   = datetime.strptime(row['end'], '%d/%m/%Y %H:%M:%S')
+                end.minute = 0
+