i have ignition 7.9 setup running at my facility, the problem i am facing is that the python script executes without any errors in the script console, but when i run it as a timer based gateway script I get a “Nonetype” error.
The problem occurs at the point where i am trying to subtract two consecutive rows of the dataset inside a for loop. The data in the dataset is a float type, i have tried converting the values to float /int using float()/int() argument, but i still get the same error.
i have also tried initializing two dummy variables as float ( y1 = 10.0 , y2=10.0 ) and later passing the data set values to them, but the result is the same.
Waiting for feedback and suggestions to resolve the issue.
Show your code, and show the full error message from the gateway logs. After you paste into the forum, and lines of just ``` above and below to cause the code/text to be formatted neatly.
# code to generate last 30 days bar graph
import datetime
now = datetime.datetime.now()
# generate end date string
edate = str(now.year)+'-'+str(now.month)+'-'+str(now.day)+" 00:00:00"
#the number of days of past data that we need
pastdata = 32
sdate = str(now.year)+'-'+str((datetime.date.today() - datetime.timedelta(pastdata)).month)+'-'+str((datetime.date.today() - datetime.timedelta(pastdata)).day)+" 00:00:00"
# get tag history data
data = system.tag.queryTagHistory(paths=['L101 EM/Totalpower'], startDate=sdate, endDate=edate, aggregationMode="LastValue", intervalHours= 24, returnFormat='Wide')
#prepare dataset to calculate daily power consumption
data1 = system.dataset.deleteRow(data,0)
# create empty dataset
data2 = []
# columnn manes for the bar chart
header = ["Day","Watts"]
# gather data for daily power consumption calculation
for i in range (0,data.getRowCount()-1):
x = str(data1.getValueAt(i,0))[4:10]
y = data.getValueAt(i+1,1)-data.getValueAt(i,1)
data2.append([x,y])
system.tag.write('Last30days',system.dataset.toDataSet(header,data2))
Error code
Traceback (most recent call last):
File “<TimerScript:Electrical_Scada/daily_usage @30,000ms >”, line 22, in
TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘NoneType’
You didn’t show all of your code. The code you posted doesn’t have 21 lines.
Also, as @pturmel mentioned if you place three back ticks like this ``` above and below your code it will cause the code/text to be formatted neatly.
For instance your code you posted above would then look like this:
import datetime
now = datetime.datetime.now()
#generate end date string
edate = str(now.year)+’-’+str(now.month)+’-’+str(now.day)+" 00:00:00"
#the number of days of past data that we need
pastdata = 32
sdate = str(now.year)+’-’+str((datetime.date.today() - datetime.timedelta(pastdata)).month)+’-’+str((datetime.date.today() - datetime.timedelta(pastdata)).day)+" 00:00:00"
#get tag history data
data = system.tag.queryTagHistory(paths=[‘L101 EM/Totalpower’], startDate=sdate, endDate=edate, aggregationMode=“LastValue”, intervalHours= 24, returnFormat=‘Wide’)
#prepare dataset to calculate daily power consumption
data1 = system.dataset.deleteRow(data,0)
#create empty dataset
data2 = []
#column manes for the bar chart
header = [“Day”,“Watts”]
#gather data for daily power consumption calculation
for i in range (0,data.getRowCount()-1):
Actually i had deleted the empty lines in code, i have updated the above code. Thanks for pointing the formatting, I missed reading @pturmel turmel comments on formatting.
I would say you need to add the tag providers to both the queryTagHistory call and the tag write at the end.
Gateway scoped scripts do not know what tag providers you are pointing at.