From a404a8622293818ccc44b7643dac46a29df46caa Mon Sep 17 00:00:00 2001
From: "t.gateau" <thibault.gateau@isae.fr>
Date: Tue, 31 Aug 2021 11:49:06 +0200
Subject: [PATCH] [dev] example checking val change done

---
 pythonAPI/checkUpToDate.py | 47 ++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/pythonAPI/checkUpToDate.py b/pythonAPI/checkUpToDate.py
index 9377214..b75ffd4 100644
--- a/pythonAPI/checkUpToDate.py
+++ b/pythonAPI/checkUpToDate.py
@@ -34,8 +34,9 @@ nanospace = Nanospace(options.server,options.user, options.pwd)
 
 
 class Var:
-    def __init__(self,nanospace_id):
+    def __init__(self,nanospace_id,nanospace_name):
         self.id = nanospace_id
+        self.name = nanospace_name
         self.val = '?'
     def __repr__(self):
         return "<"+str(self.id)+":"+self.val+">"
@@ -44,7 +45,8 @@ class Var:
         try:
             #be carefull between string and formulas !! Check Python API...
             self.val = nanospace.get_formula_value(self.id)
-            print(self)
+            return self.val
+            #print(self)
            
         except ValueError:
         		print ("Are you sure that you're using the right ID ("+str(self.idA)+")?")
@@ -52,31 +54,52 @@ class Var:
         		print ('-'*60)
         		traceback.print_exc(file=sys.stdout)
         		print ('-'*60)          
-    def setVal(self):
-        nanospace.update_formula_value(84, 'multiplication','5*20')
+    def setVal(self,newVal):
+        nanospace.update_formula_value(self.id, self.name ,str(newVal))
 
 idA = 2120
-var_A = Var(idA)
+var_A = Var(idA,"A")
 var_A.getVal()
   
 idB = 2123
-var_B = Var(idB)  
+var_B = Var(idB,"B")  
 var_B.getVal()    
 
 dicoRelation = {var_A:var_B}
 
-def compute():
-    #get list to run
-    var_B.setVal(s1(var_A.val))
-    
-    
 def s1(val):
     return val*val
 
 
-        
+def reCompute():
+    #get list to run
+    var_B.setVal(s1(float(var_A.val)))
+    print ("done")
+reCompute()  
+
+
+oldVal = var_A.getVal()   
+print("waiting")# , end="", flush=False)
+
+
+
 while (True):
+    #print(".      ", end="", flush=True)
     time.sleep(1)
+    newVal = var_A.getVal()   
+    if not (oldVal == newVal):
+        print ("Value changed")
+        print(var_A)
+        reCompute()  
+        print(var_B)
+        oldVal = newVal
+
+
+""" 
+while (True):
+    print(".      ", end="", flush=False)
+    time.sleep(1)
+"""
     
     
     
-- 
GitLab