From 38f0f17242f692205bf14d13b081cbbba035c8f6 Mon Sep 17 00:00:00 2001 From: "t.gateau" <thibault.gateau@isae.fr> Date: Thu, 9 Sep 2021 15:41:20 +0200 Subject: [PATCH] [dev] simple example working --- pythonAPI/ExampleSystem.json | 4 ++-- pythonAPI/checkUpToDateJson.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pythonAPI/ExampleSystem.json b/pythonAPI/ExampleSystem.json index bda3800..caa26ad 100644 --- a/pythonAPI/ExampleSystem.json +++ b/pythonAPI/ExampleSystem.json @@ -26,7 +26,7 @@ "softwares":[ {"powerTwo":"s1", "in":[], - "out":[], + "out":[] } ], @@ -37,7 +37,7 @@ { "name":"c1", "id": 2053, - "value":"var(B)<10" + "value":"B<10" } ] } diff --git a/pythonAPI/checkUpToDateJson.py b/pythonAPI/checkUpToDateJson.py index ae01432..939ccb7 100644 --- a/pythonAPI/checkUpToDateJson.py +++ b/pythonAPI/checkUpToDateJson.py @@ -39,9 +39,10 @@ class Var: self.id = nanospace_id self.name = nanospace_name self.val = '?' + self.check = False def __repr__(self): - return "<"+str(self.name)+"|"+str(self.id)+":"+self.val+">" + return "<"+str(self.name)+"|"+str(self.id)+":"+str(self.val)+">" def getVal(self): try: @@ -58,6 +59,7 @@ class Var: print ('-'*60) def setVal(self,newVal): nanospace.update_formula_value(self.id, self.name ,str(newVal)) + self.val = newVal @@ -108,14 +110,33 @@ var_B = lVar[1] def reCompute(): #get list to run var_B.setVal(s1(float(var_A.val))) - print ("done") + print ("reCompute done!") #reCompute() +lReq = [] +for req in dataJson["constraints"]: + myVar_id = req["id"] + myVar_name = req["name"] + myVar = Var(myVar_id,myVar_name) + myVar.getVal() + print(myVar) + lReq.append(myVar) + + +c1 = lReq[0] + +def checkRequirements(): + c1.check = (float(var_B.val)<10) + if c1.check: + print("Requirements OK") + else: + print("Warning! - Violation: "+repr(c1)) +checkRequirements() oldVal = var_A.getVal() @@ -132,6 +153,9 @@ while (True): reCompute() print(var_B) oldVal = newVal + checkRequirements() + + """ -- GitLab