Ejemplo n.º 1
0
 def test_get_temperature_readings(self):        
     data_for_testing.insert_dummy_temperatures(10)
     startSeconds = str(int(time.time()) - 30)  # less than one minute ago        
     endSeconds = str(int(time.time()))
     result = db_adapter.get_temperature_readings(startSeconds, endSeconds)
     assert(len(result) == 3)
     startSeconds = str(int(time.time()) - 70)  # should go over one minute
     result = db_adapter.get_temperature_readings(startSeconds, endSeconds)
     assert(len(result) == 6)        
     result = db_adapter.get_temperature_readings(0, 0)
     assert(len(result) == 0)
Ejemplo n.º 2
0
def get_temperatures():              
    start_timestamp, end_timestamp = _get_timestamp_query_parameters()
    try:        
        start_timestamp = float(start_timestamp)
        end_timestamp = float(end_timestamp)
        seconds = end_timestamp - start_timestamp
        print 'Asked for temperature readings from ' + misc_utils.timestamp_to_datetime(start_timestamp).strftime("%c") + ' to ' + misc_utils.timestamp_to_datetime(end_timestamp).strftime("%c") + ' (' + str(int(seconds)) + ' seconds past)...',
        all_readings = db_adapter.get_temperature_readings(int(start_timestamp), int(end_timestamp))
        print 'got ' + str(len(all_readings)) + ' result(s).'
        response.content_type = 'application/json;'                
        return json_parser.get_temperature_reading_array_as_json(all_readings)    
    except (TypeError, ValueError) as e:
        abort(400, "Malformed timestamp parameter(s): " + str(e))