Hi All,
I believe I have come across a bug in Ignition 8.1.19 (an upgrade is possible but only if this issue was resolved) when using system.tag.queryTagHistory() and using a date range that starts on one side of a partition and ends on the other a 0 is added to the dataset. From there I am adding the values to a list and calculating the range from minimum and maximum. I haven't been able to find a work around for the above using any of the additional parameters in queryTagHistory() or using the range, or minimum and maximum with queryTagCalculations().
I have also verified that in either partition for the last hour there is no 0 value to be returned from the database tables so my assumption is somewhere in the query its detecting there is no data for that timestamp in the current partition and rather than moving to the next returns a 0.
The script I am using is below:
#Gather parameters
graphType = "Electrical"
meterName = "Abar Vacuum"
tagArea = "Duablock"
startDate = system.date.getDate(2023, 8, 30)
startDate = system.date.setTime(startDate, 20, 0, 0)
endDate = system.date.getDate(2023, 9, 1)
endDate = system.date.setTime(endDate, 4, 0, 0)
aggregation = "Hour"
returnSize = 1
if aggregation == "Hour":
#Calculate required dates for Hour intervals
tempHourSD = system.date.getHour24(startDate)
startDate = system.date.setTime(startDate, tempHourSD,0,0)
tempHourED = system.date.getHour24(endDate)
endDate = system.date.setTime(endDate, tempHourED,0,0)
returnSize = system.date.hoursBetween(startDate,endDate)
elif aggregation == "Day":
#Calculate required dates for Day intervals
startDate = system.date.setTime(startDate, 0,0,0)
endDate = system.date.addDays(system.date.setTime(endDate, 0,0,0),1)
returnSize = system.date.daysBetween(startDate,endDate)
elif aggregation == "Month":
#Calculate required dates for month intervals
tempYearSD = system.date.getYear(startDate)
tempMonthSD = system.date.getMonth(startDate) #Jan is 0
startDate = system.date.getDate(tempYearSD,tempMonthSD,1)
tempYearED = system.date.getYear(endDate)
tempMonthED = system.date.getMonth(endDate) #Jan is 0
endDate = system.date.getDate(tempYearED,tempMonthED+1,1)
returnSize = system.date.monthsBetween(startDate,endDate)
tag = []
#Create tag path
if graphType == "Electrical":
tag.append("[Sub_Metering]" + tagArea + "/" + meterName + "/Active Energy Delivered")
elif graphType == "Water":
tag.append("[Sub_Metering]" + tagArea + "/" + meterName + "/Water Usage")
else:
tag.append("[Sub_Metering]" + tagArea + "/" + meterName + "/Gas Usage")
idx = 0
headers = ["X","Y"]
data = []
while idx < returnSize:
if aggregation == "Hour":
startDateTemp = system.date.addHours(startDate,idx)
endDateTemp = (system.date.addHours(startDate,idx+1))
if returnSize > 24:
formattedDate = system.date.format(startDateTemp,"dd HH:mm")
else:
formattedDate = system.date.format(startDateTemp,"HH:mm")
elif aggregation == "Day":
startDateTemp = system.date.addDays(startDate,idx)
endDateTemp = system.date.addDays(startDate,idx+1)
formattedDate = system.date.format(startDateTemp,"E dd")
elif aggregation == "Month":
startDateTemp = system.date.addMonths(startDate,idx)
endDateTemp = system.date.addMonths(startDate,idx+1)
formattedDate = system.date.format(startDateTemp,"dd-MMM-yy")
DS = system.tag.queryTagHistory(tag, startDateTemp, endDateTemp)
#create individual intervals for each hour/day/month and grab the data.
dataRange = 0
if DS.getRowCount() != 0:
tempList = []
for row in range(DS.getRowCount()):
tempList.append(DS.getValueAt(row,1))
minVal = min(tempList)
maxVal = max(tempList)
dataRange = maxVal - minVal
data.append([formattedDate,dataRange])
idx = idx + 1
DS2 = system.dataset.toDataSet(headers,data)
I have tried using all combinations of includeBoundingValues, noInterpolation, and ignoreBadQuality on both queryTagHistory and queryTagCalculations, and setting the date so the date range doesn't cross the partition but approaches the bounds, and setting the returnSize to -1 and 0 to remove seed values.
Hopefully someone has come across this before.
Tim