I am using the tag historian to save the data into a property variable.
I am using the historical date range on it, with the start and end date bound to a date range component
This data is used directly in a line graph
It is also referenced in the following code (I cannot post from the computer the code is on, so this is rewritten here)
import datetime
import time
data = self.historianData
#create dataset
tempDataHeaders = ["t_stamp", "total"]
tempDataData = []
barDuration = self.getComponent('Dropdown').selectedLabel
#for each row in data, get date component
for i in range(data.getRowCount()):
dateStamp = data.getValueAt(i, 't_stamp')
total - data.getValueAt(i, 'total')
#convert total based on selected units
if self.getComponent('CheckBox').selected:
total = total / 3.6 #1MWs is 1/3.6 kwh
#create date that matches each of the dropdown capabilites
year = system.date.getYear(datestamp)
#set date to first day of year
dateYear = system.date.getDate(year, 0, 1)
month = system.date.getMonth(datestamp)
#set date to first day of month
dateMonth = system.date.getDate(year, month, 1)
day = system.date.getDayOfMonth(dateStamp)
#set date to day
dateDay = system.date.getDate(year, month, day)
#get week of year using datetime library
#month is +1 due to datetime being index 1 while ignition is index 0 for Jan
#%U is for sunday as first day of week, Days before first sunday in year are week 0
weekNum - datetime.date(year, month+1, day).strftime("%U")
#get date of the sunday, Y is year 4 digits, U is week number with sunday as start, %w is day of week, sunday as 0
dateweek = time.asctime(time.strptime(str(year) + " " + str(weekNum) + " 0", "%Y %U %w"))
#set date to check against
checkDate = ""
if barDuration == "Years":
checkDate = dateYear
elif barDuration == "Months":
checkDate = dateMonth
elif barDuration == "Weeks":
checkDate = dateWeek
else:
checkDate = dateDay
#find check date index if it already exists
barIndex = -1
if len(tempDataData) != 0:
for i in range(len(tempDataData)):
#column 0 is timestamp
rowDate = tempDataData[i][0]
if rowDate == checkDate:
barIndex = i
#if checkDate index does not exist, add it
if barIndex == -1:
tepDataData.append([checkDate, total])
#else sum over it
else:
#column 1 is total
tempDataData[barIndex][1] += total
#compile dataset
tempData = system.dataset.toDataSet(tempDataHeaders, tempDataData)
#set dataset to bar data
self.barData = tempData
this barData is then used to populate a bar chart.
While writing this, the amount of data logged in the historian is now so large that it maxes out ignition memory, causing ignition gateway to switch to backup temporarily as it resets itself.
I am pretty sure a query can do exactly what I am doing in a fraction of the time without maxing memory, I just don’t know where or how to scoop data out of it, if it is even possible