Пример #1
0
def projectmap():
    data = stream.data()

    date_rate_offset = datetime.now() + timedelta(hours=-5)

    for record in data:
        user = record['user']

        if user[:4] == 'test':
            continue

        new_time = datetime.strptime(record['timestamp'],
                                     spark_date_format) + timedelta(hours=-4)

        if not devices.has_key(user):
            devices[user] = {
                'rate': 0,
                'total_records': 0,
                'last_hour': 0,
                'lon': 0,
                'lat': 0
            }

        #rolling hour record rate
        if new_time > date_rate_offset:
            devices[user]['rate'] = devices[user]['rate'] + 1

        #total number of data records
        devices[user]['total_records'] = devices[user]['total_records'] + 1

        # get most recent process date
        if not max_date.has_key(user):
            max_date[user] = new_time.strftime(date_format)
            devices[user]['lon'] = record['longitude']
            devices[user]['lat'] = record['latitude']

        if datetime.strptime(max_date[user], date_format) < new_time:
            max_date[user] = new_time.strftime(date_format)
            devices[user]['lon'] = record['longitude']
            devices[user]['lat'] = record['latitude']

    #get the elapsed minues since the max_date
    for device in max_date.iterkeys():
        elapsed[device] = calculate_elapsed(max_date[device])

    return template("project",
                    max_date=max_date,
                    elapsed=elapsed,
                    devices=devices)
Пример #2
0
def projectmap():
    data = stream.data()
    
    date_rate_offset= datetime.now() + timedelta(hours=-5)

    for record in data:
        user = record['user']

        if user[:4] == 'test': 
              continue

        new_time = datetime.strptime(record['timestamp'],spark_date_format) + timedelta(hours=-4)

        if not devices.has_key(user):
            devices[user] = {'rate':0, 'total_records':0, 'last_hour':0, 'lon':0, 'lat':0}


        #rolling hour record rate
        if new_time > date_rate_offset:
              devices[user]['rate'] = devices[user]['rate'] + 1

        #total number of data records
        devices[user]['total_records'] = devices[user]['total_records'] + 1

        # get most recent process date
        if not max_date.has_key(user):
            max_date[user] = new_time.strftime(date_format)
            devices[user]['lon'] = record['longitude']
            devices[user]['lat'] = record['latitude']

        if datetime.strptime(max_date[user], date_format) < new_time :
            max_date[user] = new_time.strftime(date_format)
            devices[user]['lon'] = record['longitude']
            devices[user]['lat'] = record['latitude']

    #get the elapsed minues since the max_date
    for device in max_date.iterkeys():
        elapsed[device] = calculate_elapsed(max_date[device])

    return template("project", max_date=max_date, elapsed=elapsed, devices=devices)
Пример #3
0
import stream

data = stream.data()