示例#1
0
def _process_message(data):
    """ Process a data message and save it """

    
    reading_date = parser.parse(data['time'])
    try:
        # Check if the reading for this time already exists (ignore if so)
        Reading.objects.get(time = reading_date)
        return False
    except:
        pass
    
    # Save the reading into the DB
    reading = Reading()
    reading.time = reading_date
    reading.temperature = Decimal(str(data['temperature']))
    reading.meter_id = data['sensor_id']
    reading.meter_type = int(data['meter_type'])
    reading.ch1_wattage = Decimal(str(data['ch1']))
    if data.has_key('ch2'):
        reading.ch2_wattage = Decimal(str(data['ch2']))
    if data.has_key('ch3'):
        reading.ch3_wattage = Decimal(str(data['ch3']))
    
    reading.save()