Skip to content
Snippets Groups Projects
Commit ea9c2e10 authored by GATEAU Thibault's avatar GATEAU Thibault
Browse files

[dev] using class

parent ee3bb2f6
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,8 @@ Created on Tue Aug 3 12:06:08 2021
from optparse import OptionParser
import sys, traceback
import time
defaultAltitudeID = 1295
defaultAltitudeValue = 424.0370523579581
#defaultServer = 'http://dcas-devel-1/api/'
defaultServer = 'https://dcas-nanostar.isae.fr/api/'
defaultUser = 'user'
......@@ -33,46 +32,51 @@ parser.add_option("-p", "--pwd", dest="pwd",
from nanospace import Nanospace
nanospace = Nanospace(options.server,options.user, options.pwd)
marginDownId = 1734
try:
#be carefull between string and formulas !! Check Python API...
oldAltitude = nanospace.get_formula_value(options.altitudeID)
#print("Altitude value in Nanospace UI was (formula): "+str(oldAltitude))
except ValueError:
print ("Are you sure that you're using the right ID ("+str(options.altitudeID)+")?")
print( "Exception in user code:")
print ('-'*60)
traceback.print_exc(file=sys.stdout)
print ('-'*60)
try:
#be carefull between string and formulas !! Check Python API...
marginDown = nanospace.get_formula_value(marginDownId)
#print("marginDownId value in Nanospace UI was (formula): "+str(marginDown))
except ValueError:
print ("Are you sure that you're using the right ID ("+str(marginDownId)+")?")
print( "Exception in user code:")
print ('-'*60)
traceback.print_exc(file=sys.stdout)
print ('-'*60)
class Var:
def __init__(self,nanospace_id):
self.id = nanospace_id
self.val = '?'
def __repr__(self):
return "<"+str(self.id)+":"+self.val+">"
def getVal(self):
try:
#be carefull between string and formulas !! Check Python API...
self.val = nanospace.get_formula_value(self.id)
print(self)
except ValueError:
print ("Are you sure that you're using the right ID ("+str(self.idA)+")?")
print( "Exception in user code:")
print ('-'*60)
traceback.print_exc(file=sys.stdout)
print ('-'*60)
def setVal(self):
nanospace.update_formula_value(84, 'multiplication','5*20')
oldAltitude = oldAltitude.replace('*', '')
oldAltitude = oldAltitude.replace('[km]', '')
idA = 2120
var_A = Var(idA)
var_A.getVal()
idB = 2123
var_B = Var(idB)
var_B.getVal()
res=True
if (float(oldAltitude) >= 750):
print("Warning: LOS requirements may be violated due to field ID ("+str(options.altitudeID)+"): altitude <"+oldAltitude+">")
res=False
if (float(marginDown)<10):
print("Warning: margins requirements may be violated due to field ID ("+str(marginDownId)+"): marginDown <"+marginDown+">")
res=False
if res:
print("All seem OK!")
dicoRelation = {var_A:var_B}
def compute():
#get list to run
var_B.setVal(s1(var_A.val))
def s1(val):
return val*val
while (True):
time.sleep(1)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment