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
b886ca20
Commit
b886ca20
authored
Oct 29, 2016
by
Alan Mitchell
Browse files
Fixed bugs in periodic script feature.
parent
2cea3533
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
5 deletions
+13
-5
bmsapp/models.py
bmsapp/models.py
+3
-0
bmsapp/periodic_scripts/okofen.py
bmsapp/periodic_scripts/okofen.py
+2
-2
bmsapp/scripts/run_periodic_scripts.py
bmsapp/scripts/run_periodic_scripts.py
+8
-3
No files found.
bmsapp/models.py
View file @
b886ca20
...
...
@@ -631,6 +631,9 @@ class PeriodicScript(models.Model):
# Results of the script saved and passed to the next invocation of the script.
script_results
=
models
.
TextField
(
'Script results in YAML form'
,
blank
=
True
)
def
__unicode__
(
self
):
return
'%s -- %s'
%
(
self
.
script_file_name
,
self
.
script_parameters
.
replace
(
'
\n
'
,
', '
))
def
choice_text
(
val
,
choices
):
"""Returns the display text associated with the choice value 'val'
...
...
bmsapp/periodic_scripts/okofen.py
View file @
b886ca20
...
...
@@ -2,5 +2,5 @@
Script to collect sensor readings from an OkoFEN pellet boiler.
'''
def
run
():
pass
def
run
(
**
kwargs
):
return
{
'parameters'
:
str
(
kwargs
)}
bmsapp/scripts/run_periodic_scripts.py
View file @
b886ca20
...
...
@@ -90,7 +90,12 @@ class RunScript(threading.Thread):
# last run of the script. Both of the those sets of parameters are in YAML
# form.
params
=
yaml
.
load
(
self
.
script
.
script_parameters
)
params
.
update
(
yaml
.
load
(
self
.
script
.
script_results
))
last_script_results
=
yaml
.
load
(
self
.
script
.
script_results
)
if
type
(
last_script_results
)
!=
dict
:
# There may not have been any script results, or the YAML translation
# did not produce a dictionary.
last_script_results
=
{}
params
.
update
(
last_script_results
)
# import the periodic script module, but first strip off any extension that
# the user may have appended
...
...
@@ -99,7 +104,7 @@ class RunScript(threading.Thread):
# The script is coded in the 'run' function, so run it with the input parameters
# and record the execution time.
start
=
time
.
time
()
script_results
=
script_mod
.
run
(
params
)
script_results
=
script_mod
.
run
(
**
params
)
exec_time
=
time
.
time
()
-
start
results
[
'script_execution_time'
]
=
round
(
exec_time
,
2
)
...
...
@@ -133,6 +138,6 @@ class RunScript(threading.Thread):
# Store the results back into the model script object so they are
# viewable in the Admin interface and are available for the next call.
self
.
script
.
script_results
=
yaml
.
dump
(
results
)
self
.
script
.
script_results
.
save
()
self
.
script
.
save
()
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