Using Sample data.xlsx, and just comparing rows. Should give you a start.
from datetime import timedelta
##################################################################
# Read Excel file and put into dataset with millis formatted t_stamp
# This is to simulate the return from a historian query
#
filePath = 'C:/Test/ahawes/Sample data.xlsx'
datasetIn = util.excelToDataSet(filePath, True)
headers = list(datasetIn.getColumnNames())
data = []
for row in range(datasetIn.getRowCount()):
data.append([datasetIn.getValueAt(row,0).toInstant().toEpochMilli(), datasetIn.getValueAt(row,1)])
datasetIn = system.dataset.toDataSet(headers, data)
##################################################################
# Check for rows that have the same quantity and add
# the intervening number of milliseconds.
for i in range(1, datasetIn.getRowCount()):
if datasetIn.getValueAt(i,1) == datasetIn.getValueAt(i-1,1):
millisDown += datasetIn.getValueAt(i,0) - datasetIn.getValueAt(i-1,0)
print millisDown
print timedelta(seconds=millisDown/1000)
Output:
15708174
4:21:48
Alternative for using a PyDataSet. Whichever is easier to understand / maintain.
pyData = system.dataset.toPyDataSet(datasetIn)
millisDown = 0
# Check for rows that have the same quantity and add
# the intervening number of milliseconds.
for row, prevRow in zip(pyData[1:], pyData):
if row[1] == prevRow[1]:
millisDown += row[0] - prevRow[0]