Make dummy probe use tighter pattern for random readings
to make for a more reasonable-looking graph
This commit is contained in:
parent
44d012b3fd
commit
1f8507508a
|
@ -181,6 +181,17 @@ class TempmonClient(Daemon):
|
||||||
return therm_file.readlines()
|
return therm_file.readlines()
|
||||||
|
|
||||||
def random_temp(self, probe):
|
def random_temp(self, probe):
|
||||||
|
last_reading = probe.last_reading()
|
||||||
|
if last_reading:
|
||||||
|
volatility = 2
|
||||||
|
# try to keep somewhat of a tight pattern, so graphs look reasonable
|
||||||
|
last_degrees = float(last_reading.degrees_f)
|
||||||
|
temp = random.uniform(last_degrees - volatility * 3, last_degrees + volatility * 3)
|
||||||
|
if temp > (probe.critical_temp_max + volatility * 2):
|
||||||
|
temp -= volatility
|
||||||
|
elif temp < (probe.critical_temp_min - volatility * 2):
|
||||||
|
temp += volatility
|
||||||
|
else:
|
||||||
temp = random.uniform(probe.critical_temp_min - 5, probe.critical_temp_max + 5)
|
temp = random.uniform(probe.critical_temp_min - 5, probe.critical_temp_max + 5)
|
||||||
return round(temp, 4)
|
return round(temp, 4)
|
||||||
|
|
||||||
|
|
|
@ -297,6 +297,16 @@ class Probe(Base):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.description
|
return self.description
|
||||||
|
|
||||||
|
def last_reading(self):
|
||||||
|
"""
|
||||||
|
Returns the reading which was taken most recently for this probe.
|
||||||
|
"""
|
||||||
|
session = orm.object_session(self)
|
||||||
|
return session.query(Reading)\
|
||||||
|
.filter(Reading.probe == self)\
|
||||||
|
.order_by(Reading.taken.desc())\
|
||||||
|
.first()
|
||||||
|
|
||||||
def start_status(self, status, time):
|
def start_status(self, status, time):
|
||||||
"""
|
"""
|
||||||
Update the "started" timestamp field for the given status. This is
|
Update the "started" timestamp field for the given status. This is
|
||||||
|
@ -413,6 +423,7 @@ class Reading(Base):
|
||||||
""",
|
""",
|
||||||
backref=orm.backref(
|
backref=orm.backref(
|
||||||
'readings',
|
'readings',
|
||||||
|
order_by='Reading.taken',
|
||||||
cascade='all, delete-orphan'))
|
cascade='all, delete-orphan'))
|
||||||
|
|
||||||
taken = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow)
|
taken = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow)
|
||||||
|
|
Loading…
Reference in a new issue