Hi I write the function to create a tag , I have test the script, I have successful get two output, but when I try the third input, it said :
File "<input>", line 1, in <module>
File "<module:waterfall.handler2>", line 106, in rainflow_calc
TypeError: Unable to convert row 1, column 3 to type class java.lang.Integer
could you please help to fix it? thanks
outputfeb1=[]
for i in range(len(LocalCycles1)):
outputfeb1.append([i+1,LocalCycles1[i],LocalCycles2[i],LocalCycles3[i]])
system.tag.writeBlocking("[default]outputfeb1", system.dataset.toDataSet(['Index','Range','Mean','Cycles'],outputfeb1))
Without insight into what that value actually is, your help will be limited. I’ve seen similar issues when casting strings to integers, but your issue looks to be coming from the toDataSet
function. I suspect a value in outputFeb1
is being assigned to an int column (Cycles) but is not something which can be cast as an int.
def rainflow_calc():
print("Starting RainFlow Calculation")
dataset = system.tag.read("[default]outputfeb").value
number_of_loads = dataset.getRowCount()
pyds =system.dataset.toPyDataSet(dataset)
My_list=[]
for column in pyds:
load=column[0]
My_list.append(load)
Index=range(1,number_of_loads)
# for column in pyds:
# index=column[0]
# Index.append(index)
LocalCycles1=[]
LocalCycles2=[]
LocalCycles3=[]
Isactive=[True] * number_of_loads
StartIndex = 0
counter= 1
Index[0]=0
Index[1]=1
rangeprevious=abs(My_list[1]-My_list[0])
for J in range(2,number_of_loads):
Index[2]=J
rangecurrent=abs(My_list[Index[2]]-My_list[Index[1]])
if rangecurrent<rangeprevious:
Index[0]=Index[1]
Index[1]=Index[2]
rangeprevious=rangecurrent
elif Index[0]==StartIndex:
LocalCycles1.append(rangeprevious)
LocalCycles2.append((My_list[Index[0]]+My_list[Index[1]])/2)
LocalCycles3.append(0.5)
Isactive[Index[0]]=False
counter=counter+1
StartIndex=Index[1]
Index[0]=Index[1]
Index[1]=Index[2]
rangeprevious=rangecurrent
else:
LocalCycles1.append(rangeprevious)
LocalCycles2.append((My_list[Index[0]]+My_list[Index[1]])/2)
LocalCycles3.append(1)
Isactive[Index[0]]=False
Isactive[Index[1]]=False
counter=counter+1
Index[1]=NextLowest_Index(Index[2], Isactive)
if Index[1]==StartIndex:
Index[0]=Index[1]
Index[1]=Index[2]
rangeprevious=abs(My_list[Index[1]]-My_list[Index[0]])
else:
Index[0]=NextLowest_Index(Index[1],Isactive)
Done=False
while Done==False:
rangeprevious=abs(My_list[Index[1]]-My_list[Index[0]])
rangecurrent=abs(My_list[Index[2]]-My_list[Index[1]])
if rangecurrent< rangeprevious:
Index[0]=Index[1]
Index[1]=Index[2]
rangeprevious=rangecurrent
Done=True
elif Index[0]==StartIndex:
LocalCycles1.append(rangeprevious)
LocalCycles2.append((My_list[Index[0]]+My_list[Index[1]])/2)
LocalCycles3.append(0.5)
Isactive[Index[0]]=False
counter=counter+1
StartIndex=Index[1]
Index[0]=Index[1]
Index[1]=Index[2]
rangeprevious=rangecurrent
Done=True
else:
LocalCycles1.append(rangeprevious)
LocalCycles2.append((My_list[Index[0]]+My_list[Index[1]])/2)
LocalCycles3.append(1)
Isactive[Index[0]]=False
Isactive[Index[1]]=False
counter=counter+1
Index[1]=NextLowest_Index(Index[2], Isactive)
if Index[1]==StartIndex:
Index[0]=Index[1]
Index[1]=Index[2]
rangeprevious=abs(My_list[Index[1]]-My_list[Index[0]])
Done =True
else:
Index[0]=NextLowest_Index(Index[1], Isactive)
if StartIndex<J:
Index[0]=StartIndex
Index[1]=NextHighest_Index(Index[0], Isactive)
Done=False
while Done==False:
LocalCycles1.append(abs(My_list[Index[1]]-My_list[Index[0]]))
LocalCycles2.append((My_list[Index[0]]+My_list[Index[1]])/2)
LocalCycles3.append(0.5)
if Index[1]==number_of_loads-1:
Done=True
else:
Index[0]=Index[1]
Index[1]=NextHighest_Index(Index[0], Isactive)
counter=counter+1
outputfeb1=[]
for i in range(len(LocalCycles1)):
outputfeb1.append([i+1,LocalCycles1[i],LocalCycles2[i],LocalCycles3[i]])
system.tag.writeBlocking("[default]outputfeb1", system.dataset.toDataSet(['Index','Range','Mean','Cycles'],outputfeb1))
def NextLowest_Index(I,Isactive):
Done=False
J=I-1
while Done==False:
if Isactive[J]==True:
Done=True
else:
J=J-1
returnval=J
return returnval
def NextHighest_Index(I, Isactive):
Done=False
J=I+1
while Done==False:
if Isactive[J]==True:
Done=True
else:
J=J+1
returnval=J
return returnval
that is my script, I could not figure out, thanks
jill.zhao:
LocalCycles3.append(0.5)
it seems you are passing a double to an integer column
change the integer columns in [default]outputfeb1 to double