Ejemplo n.º 1
0
def process_share(geo_data, share_type):
    """Add share aggregate data to redis."""
    log.debug('Processing as SHARE')
    redis.incr(rkeys.SHARE_TOTAL)
    redis.hincrby(rkeys.SHARE_ISSUES, share_type)
    country = geo_data.get('country', geo_data.get('registered_country'))
    if country:
        country = country['iso_code']
        redis.hincrby(rkeys.SHARE_COUNTRIES, country)
        redis.hincrby(rkeys.SHARE_COUNTRY_ISSUES.format(country), share_type)

    continent = geo_data.get('continent')
    if continent:
        continent = continent['code']
        redis.hincrby(rkeys.SHARE_CONTINENTS, continent)
        redis.hincrby(rkeys.SHARE_CONTINENT_ISSUES.format(continent), share_type)
Ejemplo n.º 2
0
def process_map(geo_data, timestamp):
    """Add download aggregate data to redis."""
    redis.incr(rkeys.MAP_TOTAL)
    try:
        # rounding to aid in geo aggregation
        location = {
            'lat': round_map_coord(geo_data['location']['latitude']),
            'lon': round_map_coord(geo_data['location']['longitude']),
        }
    except (KeyError, TypeError):
        # this appears to mostly happen with anonymous proxies
        log.info('Geo data contained no location.')
        log.debug(geo_data)
        return

    geo_key = '{lat}:{lon}'.format(**location)
    log.debug('Got location: ' + geo_key)
    time_key = rkeys.MAP_GEO.format(timestamp)
    log.debug('Got timestamp: %s' % timestamp)
    redis.hincrby(time_key, geo_key, 1)

    # store the timestamp used in a sorted set for use in milhouse
    redis.zadd(rkeys.MAP_TIMESTAMPS, timestamp, timestamp)