Commit 448f70c5 authored by Alan Mitchell's avatar Alan Mitchell
Browse files

Ensured a Dictionary was passed to Transform & Calc Functions

parent 2b033735
......@@ -124,8 +124,7 @@ class CalculateReadings:
'calcFuncName' is a string giving the name of a method of this class. The method
is used to calculate new readings for the sensor database. 'calcParams' is one string
that is formatted like the keyword parameters of a function call; for example:
heat_capacity=1.08, flow=60
that is YAML formatted to provide keyword parameters to the function.
There are two categories of functions that can be named by 'calcFuncName':
* Functions that expect at least one of the parameters to be the ID of an
......@@ -165,6 +164,8 @@ class CalculateReadings:
# Get the function parameters as a dictionary
params = yaml.load(calcParams)
if params is None:
params = {} # substitute empty dictionary for no parameters
# Start a List to hold the sensor IDs that need to be synchronized. Also start
# a separate dictionary that will map the parameter names to these IDs, since the
......
......@@ -25,11 +25,14 @@ class Transformer:
'''
Returns transformed sensor reading information, using a transformation
function identified by the string trans_func, and additional parameters to that function
given by the string 'trans_params'. That string is in keyword format, like "abc=23.3, xyz=True".
given by the string 'trans_params'. That string is in YAML format and must
convert to a Python dictionary.
All three elements of the reading--ts, id, and val--can be transformed by the function.
'''
params = yaml.load(trans_params)
if params is None:
params = {} # substitute an empty dictionary for empty parameter string
if hasattr(self, trans_func.strip()):
the_func = getattr(self, trans_func.strip())
return the_func(ts, id, val, **params)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment