Displaying differences for changeset
 
display as  

src/java/python_Scripts/erosionServiceCall.py

@@ -1,5 +1,6 @@
 from multiprocessing import Pool, Lock, Manager, cpu_count, Process, Value
 import pandas as pd
+from numpy import isnan
 import csip
 from csip.utils import Client
 import logging
@@ -14,7 +15,9 @@
     try:
         return [ el[value] for el in json_list if el['name'] == key ][0]
     except Exception as e:
-        raise ValueError(f"{key} not present: " + e)
+        logging.error(f"{key} not present: " + e)
+        return None
+        # raise ValueError(f"{key} not present: " + e)
 
 class Results:
     def __init__(self, idx, lat, lon):
@@ -60,22 +63,58 @@
         self.soilLossTolrFactor = float(soilLossTolrFactor)
     
     def add_wepp_clay(self, wepp_clay):
-        self.wepp_clay = float(wepp_clay)
+        try:
+            self.wepp_clay = float(wepp_clay)
+            if isnan(self.wepp_clay):
+                raise
+        except:
+            logging.warning("wepp_clay empty!")
+            self.wepp_clay = None
     
     def add_weps_clay(self, weps_clay):
-        self.weps_clay = float(weps_clay)
+        try:
+            self.weps_clay = float(weps_clay)
+            if isnan(self.weps_clay):
+                raise
+        except:
+            logging.warning("weps_clay empty!")
+            self.weps_clay = None
     
     def add_wepp_sand(self, wepp_sand):
-        self.wepp_sand = float(wepp_sand)
+        try:
+            self.wepp_sand = float(wepp_sand)
+            if isnan(self.wepp_sand):
+                raise
+        except:
+            logging.warning("wepp_sand empty!")
+            self.wepp_sand = None
     
     def add_weps_sand(self, weps_sand):
-        self.weps_sand = float(weps_sand)
+        try:
+            self.weps_sand = float(weps_sand)
+            if isnan(self.weps_sand):
+                raise
+        except:
+            logging.warning("weps_sand empty!")
+            self.weps_sand = None
     
     def add_weps_silt(self, weps_silt):
-        self.weps_silt = float(weps_silt)
+        try:
+            self.weps_silt = float(weps_silt)
+            if isnan(self.weps_silt):
+                raise
+        except:
+            logging.warning("weps_silt empty!")
+            self.weps_silt = None
     
     def add_weps_wp(self, weps_wp):
-        self.weps_wp = float(weps_wp)
+        try:
+            self.weps_wp = float(weps_wp)
+            if isnan(self.weps_wp):
+                raise
+        except:
+            logging.warning("weps_wp empty!")
+            self.weps_wp = None
 
     # water erosion
     def add_legacyRfactor(self, legacyRfactor):
@@ -224,7 +263,7 @@
 #                raise MaxFailuresException()
             resq_erosion = erosion_service_call(multipolygon, attempt+1)
         else:
-            logging.info(f"{service_name} | Attempt #{attempt} succeded: {resq_erosion.data}")
+            logging.info(f"{service_name} | Attempt #{attempt} succeded on {multipolygon}: {resq_erosion.data}")
             return resq_erosion
 
 def execute(arg):
@@ -334,8 +373,8 @@
 
 ## service attempts
 max_attempts = 4
-# repo_basepath = '/home/daniele/documents/codebeamer/csip-crp1/'
-repo_basepath = '/home/eramscloud/vcs/hg/csip/csip-crp1/'
+repo_basepath = '/home/daniele/documents/codebeamer/csip-crp1/'
+# repo_basepath = '/home/eramscloud/vcs/hg/csip/csip-crp1/'
 ## reference datetime for log and results
 ref_datetime = dt.datetime.now()
 
@@ -351,8 +390,8 @@
 output_file = '''{repo_basepath}data/{datetime:%Y%m%dT%H%M%S}.csv'''.format(repo_basepath=repo_basepath, datetime=ref_datetime)
 
 #read coordinates csv file
-d = pd.read_csv('''{repo_basepath}data/Results.csv'''.format(repo_basepath=repo_basepath))
-# d = pd.read_csv('''{repo_basepath}data/test.csv'''.format(repo_basepath=repo_basepath))
+# d = pd.read_csv('''{repo_basepath}data/Results.csv'''.format(repo_basepath=repo_basepath))
+d = pd.read_csv('''{repo_basepath}data/test.csv'''.format(repo_basepath=repo_basepath))
 df = pd.DataFrame(data = d)
 points_num = df.shape[0]
 #acceptable_failure_percentage = 20