Skip to content

Commit

Permalink
reactivated copy the polare.xml if not existing in user/viewer directory
Browse files Browse the repository at this point in the history
  • Loading branch information
pi committed May 16, 2022
1 parent c5f5127 commit 7c8bf0c
Showing 1 changed file with 51 additions and 47 deletions.
98 changes: 51 additions & 47 deletions Sail_Instrument/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,66 +178,70 @@ def run(self):


#https://stackoverflow.com/questions/4983258/python-how-to-check-list-monotonicity
def strictly_increasing(L):
def strictly_increasing(self, L):
return all(x<y for x, y in zip(L, L[1:]))


def Polare(self, f_name):
#polare_filename = os.path.join(os.path.dirname(__file__), f_name)
polare_filename = os.path.join(self.api.getDataDir(),'user','viewer','polare.xml')
try:
e_str=polare_filename
tree = ET.parse(polare_filename)


root = tree.getroot()
x=ET.tostring(root, encoding='utf8').decode('utf8')
e_str='windspeedvector'
x=root.find('windspeedvector').text
# whitespaces entfernen
x="".join(x.split())
self.polare['windspeedvector']=list(map(float,x.strip('][').split(',')))

e_str='windanglevector'
x=root.find('windanglevector').text
# whitespaces entfernen
x="".join(x.split())
self.polare['windanglevector']=list(map(float,x.strip('][').split(',')))
except:
source=os.path.join(os.path.dirname(__file__), f_name)
dest=os.path.join(self.api.getDataDir(),'user','viewer','polare.xml')
with open(source, 'rb') as src, open(dest, 'wb') as dst: dst.write(src.read())
tree = ET.parse(polare_filename)
finally:
root = tree.getroot()
x=ET.tostring(root, encoding='utf8').decode('utf8')
e_str='windspeedvector'
x=root.find('windspeedvector').text
# whitespaces entfernen
x="".join(x.split())
self.polare['windspeedvector']=list(map(float,x.strip('][').split(',')))
if not self.strictly_increasing(self.polare['windspeedvector']):
raise Exception("windspeedvector in polare.xml IS NOT STRICTLY INCREASING!")
return(False)

e_str='windanglevector'
x=root.find('windanglevector').text
# whitespaces entfernen
x="".join(x.split())
self.polare['windanglevector']=list(map(float,x.strip('][').split(',')))
if not self.strictly_increasing(self.polare['windanglevector']):
raise Exception("windanglevector in polare.xml IS NOT STRICTLY INCREASING!")
return(False)

e_str='boatspeed'
x=root.find('boatspeed').text
# whitespaces entfernen
z="".join(x.split())

e_str='boatspeed'
x=root.find('boatspeed').text
# whitespaces entfernen
z="".join(x.split())
z=z.split('],[')
boatspeed=[]
for elem in z:
zz=elem.strip('][').split(',')
boatspeed.append(list(map(float,zz)))
self.polare['boatspeed']=boatspeed

z=z.split('],[')
boatspeed=[]
for elem in z:
zz=elem.strip('][').split(',')
boatspeed.append(list(map(float,zz)))
self.polare['boatspeed']=boatspeed


e_str='wendewinkel'
x=root.find('wendewinkel')

e_str='upwind'
y=x.find('upwind').text
# whitespaces entfernen
y="".join(y.split())
self.polare['ww_upwind']=list(map(float,y.strip('][').split(',')))

e_str='downwind'
y=x.find('downwind').text
# whitespaces entfernen
y="".join(y.split())
self.polare['ww_downwind']=list(map(float,y.strip('][').split(',')))
except Exception as error:
raise Exception("polare.xml Error: "+error.__str__()+' -> '+e_str)
return(False)

e_str='wendewinkel'
x=root.find('wendewinkel')

e_str='upwind'
y=x.find('upwind').text
# whitespaces entfernen
y="".join(y.split())
self.polare['ww_upwind']=list(map(float,y.strip('][').split(',')))

e_str='downwind'
y=x.find('downwind').text
# whitespaces entfernen
y="".join(y.split())
self.polare['ww_downwind']=list(map(float,y.strip('][').split(',')))
return(True)



#https://appdividend.com/2019/11/12/how-to-convert-python-string-to-list-example/#:~:text=To%20convert%20string%20to%20list,delimiter%E2%80%9D%20as%20the%20delimiter%20string.

Expand Down

0 comments on commit 7c8bf0c

Please sign in to comment.