Commit f2d68bf0 authored by Alan Mitchell's avatar Alan Mitchell
Browse files

Substituted current time for None in Reading DB.

parent aaa1e02a
......@@ -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
......@@ -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:
......
......@@ -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
......
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