Chart Data if the accumulated data resets to zero

Hello! I'm having a problem with my chart data. I have a simulated tag which is a ramp up to 1.9M. When it resets to zero my chart data that time it becomes zero.

Here my Data in Power table:

Heres my chart:
bc

Here's my code:
def dataDaily(self):
def sumOfList(list, size):
if (size == 0):
return 0
else:
return list[size - 1] + sumOfList(list, size - 1)

f = lambda x : x if x > 0 else 0        

param2 = self.dateStt
param3 = self.dateEnd
window = system.gui.getWindow('Dashboard/Deep Well Summary/Deep Well Summary')

header1 = ['Label','Power']
header2 = ['Label','Water']
header3 = ['Label','Efficiency']
header4 = ['Label','Power','Water']
data1 = []
data2 = []
data3 = []

#Power
todayPower = system.tag.queryTagHistory(paths = ['[LIMA]'+ window.getRootContainer().locationPath + '/Power/rMains_KWH']
										, startDate = self.dateStt
										, endDate = system.date.addHours(param3, 2)
										, returnFormat='Wide'
										, aggregationMode = 'LastValue'
										, columnNames = 'rMains_KWH'
										,intervalHours = 1)
todayPower_tStamp = [todayPower.getValueAt(row,0) for row in range(todayPower.getRowCount())]
todayPower_Value = [todayPower.getValueAt(row,1) for row in range(todayPower.getRowCount())]
value1 = [j - i for i, j in zip(todayPower_Value[: -1], todayPower_Value[1 :])]
powerValue = [f(x) for x in value1]
sumValuePower = sumOfList(powerValue, len(powerValue))	
window.getRootContainer().getComponent('Deep Well Summary').getComponent('Comparison Bar Chart').dataSetPower = system.dataset.toDataSet(header1,zip(todayPower_tStamp,powerValue))


#water
todayWater = system.tag.queryTagHistory(paths = ['[LIMA]'+ window.getRootContainer().locationPath + '/Process/rFlowrate']
										, startDate = self.dateStt
										, endDate = system.date.addHours(param3, 2)
										, returnFormat='Wide'
										, aggregationMode = 'LastValue'
										, columnNames = 'rMains_KWH'
										,intervalHours = 1)
todayWater_tStamp = [todayWater.getValueAt(row,0) for row in range(todayWater.getRowCount())]
todayWater_Value = [todayWater.getValueAt(row,1) for row in range(todayWater.getRowCount())]
value2 = [j - i for i, j in zip(todayWater_Value[: -1], todayWater_Value[1 :])]
waterValue = [f(x) for x in value2]
window.getRootContainer().getComponent('Deep Well Summary').getComponent('Comparison Bar Chart').dataSetWater = system.dataset.toDataSet(header2,zip(todayWater_tStamp,waterValue))
sumValueWater = sumOfList(waterValue, len(waterValue))

I want to fix it when my tag reaches its limit then resets it will still accumulate the data after it resets.

@justinedwards.jle

I'm not sure I understand the question, and secondly, this code seems to be doing a lot of work. Where does it live, and what triggers it?

Source Code
def dataDaily(self):
	def sumOfList(list, size):
		if (size == 0):
			return 0
		else:
			return list[size - 1] + sumOfList(list, size - 1)
	f = lambda x: x if x > 0 else 0
	param2 = self.dateStt
	param3 = self.dateEnd
	window = system.gui.getWindow('Dashboard/Deep Well Summary/Deep Well Summary')
	header1 = ['Label', 'Power']
	header2 = ['Label', 'Water']
	header3 = ['Label', 'Efficiency']
	header4 = ['Label', 'Power', 'Water']
	data1 = []
	data2 = []
	data3 = []
	# Power
	todayPower = system.tag.queryTagHistory(paths=['[LIMA]' + window.getRootContainer().locationPath + '/Power/rMains_KWH'],
		startDate=self.dateStt,
		endDate=system.date.addHours(param3, 2),
		returnFormat='Wide',
		aggregationMode='LastValue',
		columnNames='rMains_KWH',
		intervalHours=1)
	todayPower_tStamp = [todayPower.getValueAt(row, 0) for row in range(todayPower.getRowCount())]
	todayPower_Value = [todayPower.getValueAt(row, 1) for row in range(todayPower.getRowCount())]
	value1 = [j - i for i, j in zip(todayPower_Value[:-1], todayPower_Value[1:])]
	powerValue = [f(x) for x in value1]
	sumValuePower = sumOfList(powerValue, len(powerValue))
	window.getRootContainer().getComponent('Deep Well Summary').getComponent('Comparison Bar Chart').dataSetPower = system.dataset.toDataSet(
		header1, zip(todayPower_tStamp, powerValue))
	# Water
	todayWater = system.tag.queryTagHistory(paths=['[LIMA]' + window.getRootContainer().locationPath + '/Process/rFlowrate'],
		startDate=self.dateStt,
		endDate=system.date.addHours(param3, 2),
		returnFormat='Wide',
		aggregationMode='LastValue',
		columnNames='rMains_KWH',
		intervalHours=1)
	todayWater_tStamp = [todayWater.getValueAt(row, 0) for row in range(todayWater.getRowCount())]
	todayWater_Value = [todayWater.getValueAt(row, 1) for row in range(todayWater.getRowCount())]
	value2 = [j - i for i, j in zip(todayWater_Value[:-1], todayWater_Value[1:])]
	waterValue = [f(x) for x in value2]
	window.getRootContainer().getComponent('Deep Well Summary').getComponent('Comparison Bar Chart').dataSetWater = system.dataset.toDataSet(
		header2, zip(todayWater_tStamp, waterValue))
	sumValueWater = sumOfList(waterValue, len(waterValue))

its in the root container property change. The one triggering is when someone selects an aggregation date and apply the date then select location thru a dropdown.
image
here the location dropdown:
image

My question is if my simulated tag reaches its maximum it will reset like this
1

I have Power and Water accumulated data. This accumulated datas is subracted to get the value per hour. Example: 9am data minus 8am data to get the 8am data. but if it resets my table goes like this:
2

My problem is that..
example:
My tag accumulator has a limit of 1.9 million and its resets in a certain time. I want to continue the computation of example: 9amData - 8amData = 8amData.

This is classic odometer behavior. The answer is to use your database's lag() function to compute the delta between the samples, and apply modulo math with the rollover value to get the actual delta. If you know the totalizer is always going forward, the expression would be (delta + rollover) % rollover, in whatever syntax your DB requires.

Once you have that on a per-sample basis, you can sum those adjusted deltas to get the true total over the sampling period.

can you give me an example?