Ejemplo n.º 1
0
 def follow_instructions():
     global has_escalated
     has_escalated = False     
     while True:      
         global instruction_thread_in_waiting
         instruction_thread_in_waiting = False
         try:
             instructions = database.db_adapter.get_all_instructions()                
             if len(instructions) > 1:
                 pretty_date = misc_utils.get_storeable_datetime_timestamp(time.time())
                 instructions_string = ',\n'.join(map(str, instructions))
                 message = "More than one instruction for time " + pretty_date + ":\n" + instructions_string                    
                 if not has_escalated:                        
                     emailer.escalate("Instruction error", message)
                     global has_escalated
                     has_escalated = True    
                 print message                
             elif len(instructions) == 1:
                 global current_instruction_id
                 instruction = instructions[0]
                 if (current_instruction_id != instruction.instruction_id):
                     current_instruction_id = instruction.instruction_id
                     global instruction_target_temperature_C                        
                     instruction_target_temperature_C = instruction.target_temperature_C
                     print 'Applying instruction #' + instruction.instruction_id + ', setting target temperature to: ' + str(instruction_target_temperature_C) + "C"
             elif len(instructions) == 0:
                 global current_instruction_id
                 current_instruction_id = None
         except Exception as e:
             print 'Error while looking at instructions:\n' + str(e)
         instruction_thread_in_waiting = True
         time.sleep(configuration.instruction_interval_seconds())                    
 def test_set_settings(self):
     new_temp_store = 60;
     new_instruction_interval = 120;
     new_temp_check = 10;
     new_temp_margin = 0.25;
     request_body = '{ "store_temperature_interval_seconds" : ' + str(new_temp_store) + ',  "instruction_interval_seconds" : ' + str(new_instruction_interval) + ',  "monitor_temperature_interval_seconds" : ' + str(new_temp_check) + ', "temperature_tolerance_C":' + str(new_temp_margin) + '}'        
     response = self._call_POST_with_credentials_and_body('http://localhost:8080/chestfreezer/api/options', request_body, 'application/json')[0]
     assert(response.status == 204)  
     assert configuration.store_temperature_interval_seconds() == new_temp_store      
     assert configuration.instruction_interval_seconds() == new_instruction_interval
     assert configuration.control_temperature_interval_seconds() == new_temp_check
     assert configuration.temperature_tolerance() == new_temp_margin
Ejemplo n.º 3
0
def get_settings_as_json():
    """ returns the application options as a json object """
    store_temperature_interval_seconds = configuration.store_temperature_interval_seconds()     
    l1 = '  "store_temperature_interval_seconds" : ' + str(int(store_temperature_interval_seconds)) + ',';
    instruction_interval_seconds = configuration.instruction_interval_seconds()
    l2 = '  "instruction_interval_seconds" : ' + str(int(instruction_interval_seconds)) + ',';
    control_temperature_interval_seconds = configuration.control_temperature_interval_seconds()
    l3 = '  "monitor_temperature_interval_seconds" : ' + str(int(control_temperature_interval_seconds)) + ',';
    temperature_tolerance = configuration.temperature_tolerance()
    l4 = '  "temperature_tolerance_C" : ' + str(temperature_tolerance) + ',';        
    database_size = db_adapter.get_database_size()
    l5 = '  "database_size_MB" : ' + str(round(database_size,1)) + ',';
    database_free_size = db_adapter.get_database_free_size()
    l6 = '  "database_free_size_MB" : ' + str(round(database_free_size,1)) + '';
    return '{\n  ' + l1 + '\n  ' + l2 + '\n  ' + l3 + '\n  ' + l4 + '\n  ' + l5 + '\n  ' + l6 + '\n}'