Exemple #1
0
def metersFromHome(config, user, lng, lat):
    locs = readGoogleMapsLocations(config['userMap'][str(user)])['places']
    for name, pt in locs:
        if name == 'home':
            break
    else:
        raise ValueError("unknown 'home' location for %s" % user)
    _, _, m = geod.inv(lng, lat, pt[1], pt[0])
    return m
Exemple #2
0
def metersFromHome(config, user, lng, lat):
    locs = readGoogleMapsLocations(config['userMap'][str(user)])['places']
    for name, pt in locs:
        if name == 'home':
            break
    else:
        raise ValueError("unknown 'home' location for %s" % user)
    _, _, m = geod.inv(lng, lat, pt[1], pt[0])
    return m
Exemple #3
0
def mapImage(mongo, width=320, height=320, history=10):
    surf, ctx = makeSurf(width, height)
    mongo.ensure_index([('timestamp', -1)])
    rows = list(mongo.find().sort('timestamp', -1).limit(history))
    points = []
    for row in rows:
        points.append((row['longitude'], row['latitude']))

    locs = readGoogleMapsLocations()

    coord = Coord(surf, points, locs)

    prevRow = None
    path = []
    color = None
    for age, row in enumerate(rows):
        pos = coord.screenFromWorld(row['longitude'], row['latitude'])
        if color is None:
            color = randColor(row['user'])        
        dot(ctx, pos, 3, 0, color, (0,0,0))
        if (prevRow and (
            (abs(row['timestamp'] - prevRow['timestamp']) > 10*60*1000) or
            (row['user'] != prevRow['user'])
            )):
            drawPath(ctx, surf, color, age, path)
            path = []
            color = None
        path.append(pos)

        prevRow = row

    if color:
        drawPath(ctx, surf, color, age, path)

    drawLocations(coord, ctx, locs)

    people = []
    seen = set()
    for row in rows:
        if row['user'] in seen:
            continue
        drawPerson(coord, ctx, row['user'], row['longitude'], row['latitude'], people)
        seen.add(row['user'])

    return toPng(surf)
Exemple #4
0
def mapImage(mongo, width=320, height=320, history=10):
    surf, ctx = makeSurf(width, height)
    mongo.ensure_index([('timestamp', -1)])
    rows = list(mongo.find().sort('timestamp', -1).limit(history))
    points = []
    for row in rows:
        points.append((row['longitude'], row['latitude']))

    locs = readGoogleMapsLocations()

    coord = Coord(surf, points, locs)

    prevRow = None
    path = []
    color = None
    for age, row in enumerate(rows):
        pos = coord.screenFromWorld(row['longitude'], row['latitude'])
        if color is None:
            color = randColor(row['user'])
        dot(ctx, pos, 3, 0, color, (0, 0, 0))
        if (prevRow and
            ((abs(row['timestamp'] - prevRow['timestamp']) > 10 * 60 * 1000) or
             (row['user'] != prevRow['user']))):
            drawPath(ctx, surf, color, age, path)
            path = []
            color = None
        path.append(pos)

        prevRow = row

    if color:
        drawPath(ctx, surf, color, age, path)

    drawLocations(coord, ctx, locs)

    people = []
    seen = set()
    for row in rows:
        if row['user'] in seen:
            continue
        drawPerson(coord, ctx, row['user'], row['longitude'], row['latitude'],
                   people)
        seen.add(row['user'])

    return toPng(surf)
Exemple #5
0
def closestTarget(config, lng, lat, user):
    """name and meters to the closest known target"""

    mapId = config['userMap'][user]
    locations = readGoogleMapsLocations(mapId)['places']

    closest = (None, 0)
    for name, target in locations:
        try:
            _, _, dist = geod.inv(lng, lat, target[1], target[0])
        except ValueError:
            eps = .0001  # not sure how close Geod breaks
            if (abs(lng - target[1]) < eps and abs(lat - target[0]) < eps):
                return name, 0
            else:
                raise
        if closest[0] is None or dist < closest[1]:
            closest = name, dist

    return closest
Exemple #6
0
def closestTarget(config, lng, lat, user):
    """name and meters to the closest known target"""

    mapId = config['userMap'][user]
    locations = readGoogleMapsLocations(mapId)['places']

    closest = (None, 0)
    for name, target in locations:
        try:
            _, _, dist = geod.inv(lng, lat, target[1], target[0])
        except ValueError:
            eps = .0001 # not sure how close Geod breaks
            if (abs(lng - target[1]) < eps and
                abs(lat - target[0]) < eps):
                return name, 0
            else:
                raise
        if closest[0] is None or dist < closest[1]:
            closest = name, dist

    return closest
Exemple #7
0
def placesMap():
    ret = readGoogleMapsLocations(request.query['m'],
                                  bool(request.query.get('forceReload', '')))
    return ret
Exemple #8
0
def placesMap():
    ret = readGoogleMapsLocations(request.query['m'],
                                  bool(request.query.get('forceReload', '')))
    return ret