Ejemplo n.º 1
0
def generate_random_data(start_date, end_date, imei, name, lat, lon):
    try:
        start_time = datetime(*[int(i) for i in start_date.split("-")])
        end_time = datetime(*[int(i) for i in end_date.split("-")])
        #assert (imei=="" or imei== None), "IMEI cannot be blank"
        #assert (name=="" or name== None), "Name cannot be blank"
        #assert (lat=="" or lat== None), "Lat cannot be blank"
        #assert (lon=="" or lon== None), "Long cannot be blank"
        for ts in datespan(start_time, end_time, delta=timedelta(minutes=5)):
            aqf = AQFeed()
            aqf.imei=imei
            aqf.name=name            
            aqf.humidity = random.random(1,100) + random.random()
            aqf.temperature = random.random(15,45) + random.random()
            aqf.pm10 = random.random(1,500) + random.random()
            aqf.pm25 = random.random(1,1000) + random.random()
            aqf.count_large = random.triangular(1,500) + random.random()
            aqf.count_small = random.triangular(1,900) + random.random()
            aqf.lat = lat
            aqf.lon = lon
            aqf.created_on=ts
            aqf.save()                    
            
    except: 
        print "Usage::"
        print  "generate_random_data(start_date, end_date, imei, name, lat, lon)" 
        print "Format of dates must be as :: YYYY-MM-DD-HH-MM "
        return 
Ejemplo n.º 2
0
def initfeed(xfeed):
    x = xfeed['with'][0]
    aqd = AQDevice.objects.get(imei=x['content']['imei'])
    lat = aqd.geom['coordinates'][1]
    lon = aqd.geom['coordinates'][0]
    lastUpdateTime = dateutil.parser.parse("2015-08-03T02:24:00.000Z")
    for x in xfeed['with']:    
        d = dateutil.parser.parse(x['created'])
        if d < lastUpdateTime:
            continue        
        aqf = AQFeed()
        aqf.imei=x['content']['imei']
        aqf.name=""
        aqf.humidity = x['content']['h']
        aqf.temperature = x['content']['t']
        aqf.pm10 = x['content']['pm10']
        aqf.pm25 = x['content']['pm25']
        aqf.count_large = x['content']['cl']
        aqf.count_small = x['content']['cs']
        aqf.lat = lat
        aqf.lon = lon
        aqf.created_on=x['created']
        aqf.save()