Data Source Scripting dataset

header = ['Temperature','Time Difference','Time']

filteredDataset = []
rawDataset = data['button history'].getCoreResults()

for row in range(rawDataset.rowCount):
	TimeDiff = rawDataset.getValueAt(row,'recording diff')
	if (TimeDiff >= 0 or (TimeDiff < 0 and TimeDiff > -maxHours) ):
		specificTime = rawDataset.getValueAt(row,'t_stamp')
		temp = rawDataset.getValueAt(row,'temperature')
filteredDataset = system.dataset.toDataSet(header,filteredDataset)
data['Scripted Data'] = filteredDataset

I’m not sure if the above segment of code is giving me the correct desired result. I’m trying to only get the data points that have a time difference greater than zero, or if the data points have a negative time difference, then the time difference should at least be greater than the max hours. However, I’m not sure if im appending these values to the filteredDataset properly. Am I correct in my assumption that the if statement will only consider the values that have a timestamp or temperature that fall into the specified time difference range?

If you assume maxHours is always positive, your if statement reduces to:

if TimeDiff > -maxHours:

I don’t know that if that makes sense for what you are trying to do.

Sorry, I should have been more clear in my initial statement, but I have a start button and a stop button set up. The time difference is the difference between the times when the buttons are pressed. If the stop button is pressed after the start button, then TimeDiff will be positive. However, if the start button is pressed after the stop button, TimeDiff will be negative, indicating that a new process or cycle has started(if we assume a normal process to be starting with the press of a start button and ending with the press of the end button).

Additionally, I wanted to add an additional constraint, maxHours, representing the maximum amount of time between two processes. If the TimeDiff exceeds that number, then those data points should be filtered out. I’m just wondering if my lines after the if statement are in fact only getting the data points corresponding to that if statement or if my logic is correct overall.

I still can’t evaluate what you are doing. How is TimeDiff related to a specific sample’s timestamp? (Rhetorical question–you’ll have your answer when you understand that.)
Personally, I would construct a list of start,end tuples, and compare the timestamps of the raw data to those tuples. Accepting any data that falls within one of the start/end pairs, and rejecting those that don’t.