def transform(self, value, quality, timestamp):
# Get the period selection value
period_value = value
# Get current time
now = system.date.now()
period_start = system.date.addHours(now, -24)
period_end = now
# Call the named query
result = system.db.runNamedQuery("get_top5_machines", {"period_start": period_start,
"period_end": period_end,
"sort_order": "lowest"})
# Return the dataset
return result
returns an error script eval.
In the console,
now = system.date.now() period_start = system.date.addHours(now, -24) period_end = now result = system.db.runNamedQuery( "get_top5_machines", { "period_start": period_start, "period_end": period_end, "sort_order": 'lowest' } ) print(result)
prints a pyDataSet.
RunNamedQuery definitely has perspective session scope. Help?
Copy paste error, thats not whats in the transform
just copying again for myself:
def transform(self, value, quality, timestamp): # Get the period selection value period_value = value # Get current time now = system.date.now() period_start = system.date.addHours(now, -24) period_end = now
# Call the named query
result = system.db.runNamedQuery("get_top5_machines", {"period_start": period_start,
"period_end": period_end,
"sort_order": "lowest"})
# Return the dataset
return result
for multiline, use three backticks. one set on the line above, one on the line below.
def transform(self, value, quality, timestamp):
# Get the period selection value
period_value = value
# Get current time
now = system.date.now()
period_start = system.date.addHours(now, -24)
period_end = now
# Call the named query
result = system.db.runNamedQuery("get_top5_machines", {"period_start": period_start, "period_end": period_end, "sort_order": "lowest"})
# Return the dataset
return result
Perhaps it's a copy paste error to the forum but you do not have any indentation on the code below def transform.
Also couple other things. If it's a simple project then it'll auto assume the project name but if your project is using Inheritance then you need to specify the project name as additional parameter before the path.
And as a suggestion put your parameters separate then list it in the function, it's optional but just a better habit for down the road to organize things, especially if some queries get lengthy lists for parameters.
def transform(self, value, quality, timestamp):
project_name = "YourProjectName"
now = system.date.now()
period_start = system.date.addHours(now, -24)
period_end = now
params = {
"period_start": period_start,
"period_end": period_end,
"sort_order": "lowest"
}
result = system.db.runNamedQuery(project_name, "get_top5_machines", params)
return result