Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
energy
bmon
Commits
448f70c5
Commit
448f70c5
authored
Feb 03, 2015
by
Alan Mitchell
Browse files
Ensured a Dictionary was passed to Transform & Calc Functions
parent
2b033735
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
bmsapp/calcs/calcreadings.py
bmsapp/calcs/calcreadings.py
+3
-2
bmsapp/calcs/transforms.py
bmsapp/calcs/transforms.py
+4
-1
No files found.
bmsapp/calcs/calcreadings.py
View file @
448f70c5
...
...
@@ -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
...
...
bmsapp/calcs/transforms.py
View file @
448f70c5
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment