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
f2d68bf0
Commit
f2d68bf0
authored
Oct 29, 2016
by
Alan Mitchell
Browse files
Substituted current time for None in Reading DB.
parent
aaa1e02a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
6 deletions
+18
-6
bmsapp/periodic_scripts/okofen.py
bmsapp/periodic_scripts/okofen.py
+3
-3
bmsapp/readingdb/bmsdata.py
bmsapp/readingdb/bmsdata.py
+14
-3
bmsapp/scripts/run_periodic_scripts.py
bmsapp/scripts/run_periodic_scripts.py
+1
-0
No files found.
bmsapp/periodic_scripts/okofen.py
View file @
f2d68bf0
...
...
@@ -4,6 +4,6 @@ Script to collect sensor readings from an OkoFEN pellet boiler.
import
random
,
time
def
run
(
**
kwargs
):
time
.
sleep
(
random
.
random
()
*
2.0
)
print
kwargs
return
{
'Random Number'
:
random
.
random
()}
results
=
{
'readings'
:
[(
None
,
'anc_birch_wind'
,
10.0
*
random
.
random
())
,
(
None
,
'anc_birch_temp'
,
40
+
20
*
random
.
random
())]}
return
results
bmsapp/readingdb/bmsdata.py
View file @
f2d68bf0
...
...
@@ -73,8 +73,9 @@ class BMSdata:
def
insert_reading
(
self
,
ts
,
id
,
val
):
"""Inserts a record or records into the database. 'ts', 'id', and
'val' can either be lists or single values. If val is None, it is
not stored in the database and it is recorded as an exception.
'val' can either be lists or single values. If 'ts' is None, it is
replaced with the current time.
If val is None, the record is not stored in the database and it is recorded as an exception.
"""
try
:
recs
=
zip
(
ts
,
id
,
val
)
...
...
@@ -85,7 +86,17 @@ class BMSdata:
rejected_count
=
0
success_count
=
0
for
one_ts
,
one_id
,
one_val
in
recs
:
one_id
=
str
(
one_id
)
# make sure sensor ID is a string
# make sure sensor ID is a string
one_id
=
str
(
one_id
)
if
one_ts
is
None
:
# substitute current time
one_ts
=
time
.
time
()
# convert time to integer
one_ts
=
int
(
one_ts
)
try
:
# Check to see if sensor table exists. If not, create it.
if
one_id
not
in
self
.
sensor_ids
:
...
...
bmsapp/scripts/run_periodic_scripts.py
View file @
f2d68bf0
...
...
@@ -125,6 +125,7 @@ class RunScript(threading.Thread):
# get a connection to the reading database and insert
reading_db
=
bmsdata
.
BMSdata
()
insert_msg
=
reading_db
.
insert_reading
(
ts
,
ids
,
vals
)
reading_db
.
close
()
# store this message so it can be seen in the Django Admin
# interface
results
[
'reading_insert_message'
]
=
insert_msg
...
...
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