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
					
				
					 2 changed files with 23 additions and 1 deletions
				
			
		|  | @ -181,7 +181,18 @@ class TempmonClient(Daemon): | |||
|             return therm_file.readlines() | ||||
| 
 | ||||
|     def random_temp(self, probe): | ||||
|         temp = random.uniform(probe.critical_temp_min - 5, probe.critical_temp_max + 5) | ||||
|         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) | ||||
|         return round(temp, 4) | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -297,6 +297,16 @@ class Probe(Base): | |||
|     def __str__(self): | ||||
|         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): | ||||
|         """ | ||||
|         Update the "started" timestamp field for the given status.  This is | ||||
|  | @ -413,6 +423,7 @@ class Reading(Base): | |||
|         """, | ||||
|         backref=orm.backref( | ||||
|             'readings', | ||||
|             order_by='Reading.taken', | ||||
|             cascade='all, delete-orphan')) | ||||
| 
 | ||||
|     taken = sa.Column(sa.DateTime(), nullable=False, default=datetime.datetime.utcnow) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar