The vast majority of this script is just adjusting a dataset for display.
It appears that the real work occurs in the perspective.mesanalysis.getdowntime()
function. Is it possible to "hard code" the equipment paths?
For instance, something like this in a Gateway Timer Script:
paths = ('EquipmentPath1','EquipmentPath2')
tagPaths = ['Tag\Path\For\EquipmentPath1\DataSet','Tag\Path\For\EquipmentPath2\DataSet']
endDate = system.date.now()
startDate = system.date.addMinutes(endDate,-1)
tagValues = [perspective.mesanalysis.getdowntime(path,startDate,endDate) for path in paths]
system.tag.writeBlocking(tagPaths,tagValues)
On the other hand, is there perhaps an Indentation error in your script? It looks like you are building and sorting a dataset, for every row in the data? You should probably not do that. Not to mention you have two different declarations of row
in the same scope.
Also, you should definitely not use list
as a variable, because you're overwritting the python built-in in that scope.
I would expect something more like this:
states = {}
for row in pydowntimedata:
st=str(row['Equipment State Name'])
if st not in states:
states[st]=[st,0,0.0]
mins=float(row['Unplanned Downtime'])
states[st]=[st,states[st][1]+1,states[st][2]+mins]
tableHeader = ['Equipment States','Occurance','Downtime Mins']
tableData = [val for state,val in states.iteritems()]
tabledata = system.dataset.toDataSet(tableHeader,tableData)
tabledata=system.dataset.sort(tabledata,'Downtime Mins',False)
self.parent.parent.parent.getChild("DashBoard").getChild("Downtime Table").getChild("Table").props.data=tabledata