Data Source Scripting

I’m trying to run a script that will filter out the motor speed that doesn’t specifically have the timestamp of 9 am on every day and show two columns of the date at 9 am and the motor speed at that time for multiple days. This is my code so far.

	header = ['Mtr Spd','Date']
	filteredDataset = []
	rawDataset = data['motor speed_1'].getCoreResults()
	
	for row in range(rawDataset.rowCount):
		if (system.date.getHour24(data['Date'])) == 9:
			specificVal = rawDataset.getvalueAt(row,'mtr spd')
			specificTime = rawDataset.getvalueAt(row,'t_stamp')
			filteredDataset.append([specificTime, specificVal])
					
	filteredDataset = system.dataset.toDataSet(header,filteredDataset)
	
	data['updated Data'] = filteredDataset

The issue right now is that on line 7, the function system.date.getHour doesn’t work because data[‘t_stamp’] is not a correct date entry. However, I’m not sure what else I can use to keep track of the time. StartDate/endDate work but they don’t do what I specifically want. I’m also not sure if the query, motor speed_1, that I’m trying to extract data from has enough data to draw from since I only have a few results showing up for that query in the window.

Please don’t use screenshots of code. Paste the code itself into your post, with a line of just ``` above it, and another triple-backtick below it.

Anyways, you need to extract the t_stamp from your raw dataset and check the hour on it, not on anything from data. Something like this:

for row in range(rawDataset.rowCount):
    specificTime = rawDataset.getValueAt(row, 't_stamp')
    if specificTime and specificTime.hour == 9:
        .......

getting this error for specifictime.hour:
WARN: Traceback (most recent call last):
File “function:updateData”, line 9, in updateData
AttributeError: ‘java.sql.Timestamp’ object has no attribute ‘hour’

Sorry. Use .hours. See the Javadoc for java.util.Date, which java.sql.Timestamp extends.