Exemplo n.º 1
0
 def __init__(self, lon, lat, t):
     self.lon = lon
     self.lat = lat
     x, y = geo.project((self.lon, self.lat))
     self.x = (x - MIN_X) / (MAX_X - MIN_X)
     self.y = (y - MIN_Y) / (MAX_Y - MIN_Y)        
     dt = timeutil.t_to_dt(t, tz="America/New_York")
     self.period = ((dt.hour * 60) + (dt.minute)) // PERIOD_SIZE
Exemplo n.º 2
0
 def __init__(self, lon, lat, t):
     self.lon = lon
     self.lat = lat
     x, y = geo.project((self.lon, self.lat))
     self.x = (x - MIN_X) / (MAX_X - MIN_X)
     self.y = (y - MIN_Y) / (MAX_Y - MIN_Y)
     self.t = t
     self.geohash = geo.geohash_encode((self.lon, self.lat),
                                       precision=LOCATION_SIZE)
     self.cluster = None
     self.location = None
     dt = timeutil.t_to_dt(self.t,
                           tz="America/New_York")  # not sure why, honestly.
     self.period = ((dt.hour * 60) + (dt.minute)) // PERIOD_SIZE
     self.address = None
     self.display_time = None
Exemplo n.º 3
0
    def get(self, page):
        if page == "stations":
            stations = model.fetch_stations()
            s = {}
            for station_id, station in stations.items():
                s[station_id] = geo.project((station['lon'], station['lat']))
            max_x = s[max(s, key=lambda d: s[d][0])][0]
            min_x = s[min(s, key=lambda d: s[d][0])][0]
            max_y = s[max(s, key=lambda d: s[d][1])][1]
            min_y = s[min(s, key=lambda d: s[d][1])][1]
            for station_id, value in s.items():
                x, y = value
                s[station_id] = util.scale(x, min_x, max_x), util.scale(y, min_y, max_y)
            return self.json(s)
            

        return self.render("home.html")
Exemplo n.º 4
0
    if len(sequence) < MIN_STEPS:
        continue
    walks.append(walk)


LON = 0
LAT = 1
X = 2
Y = 3

all_points = []
for walk in walks:
    points = model.fetch_geo(walk['id'])
    points = np.array([(point['lng'], point['lat'], None, None) for point in points])
    for point in points:
        point[X], point[Y] = geo.project((point[LON], point[LAT]))
    walk['points'] = points
    all_points.extend(points)
all_points = np.array(all_points)

max_x = np.max(all_points[:,X])
min_x = np.min(all_points[:,X])
max_y = np.max(all_points[:,Y])
min_y = np.min(all_points[:,Y])

width = float(abs(max_x - min_x))
height = float(abs(max_y - min_y))
ratio = width / height

print(ratio)
    
Exemplo n.º 5
0
    }
})

log.info("POINTS %s" % results.count())
users = len(results.distinct('user_id'))
log.info("USERS %s" % users)

points = np.array([(result['location']['coordinates'][0],
                    result['location']['coordinates'][1], result['user_id'])
                   for result in results])

min_lon, max_lon = (np.min(points[:, 0]), np.max(points[:, 0]))
min_lat, max_lat = (np.min(points[:, 1]), np.max(points[:, 1]))
log.debug("%f %f %f %f" % (min_lon, max_lon, min_lat, max_lat))

min_x, max_y = geo.project((min_lon, max_lat))
max_x, min_y = geo.project((max_lon, min_lat))

ratio = (max_x - min_x) / (max_y - min_y)

ctx = drawing.Context(1000,
                      int(1000 / ratio),
                      relative=True,
                      flip=True,
                      hsv=True)
log.info("Drawing %d %d..." % (ctx.width, ctx.height))

for point in points:

    x, y = geo.project((point[0], point[1]))
Exemplo n.º 6
0
#!/usr/bin/env python3

import random, datetime, json, math, requests, json
import numpy as np
from housepy import geo, config, log, util, timeutil
from sklearn.cluster import Birch
from mongo import db
import drawer


PERIOD_SIZE = config['period_size']
PERIODS = int(1440 / PERIOD_SIZE)
LON_1, LAT_1 = config['bounds']['NW']
LON_2, LAT_2 = config['bounds']['SE']
MIN_X, MAX_Y = geo.project((LON_1, LAT_1))
MAX_X, MIN_Y = geo.project((LON_2, LAT_2))


# generator for retrieving user points from mongo
def get_user_points(user_ids):
    location = {'$geoWithin': {'$geometry': {'type': "Polygon", 'coordinates': [[ [LON_1, LAT_1], [LON_2, LAT_1], [LON_2, LAT_2], [LON_1, LAT_2], [LON_1, LAT_1] ]]}}}
    for u, user_id in enumerate(user_ids):
        log.info("USER %s..." % user_id)
        cursor = db.entries.find({'user_id': user_id, 'location': location, 't': {'$gt': timeutil.timestamp(timeutil.string_to_dt(config['start_date'], tz="America/New_York")), '$lt': timeutil.timestamp(timeutil.string_to_dt(config['stop_date'], tz="America/New_York"))}}).sort('t')
        points = [Point(point['location']['coordinates'][0], point['location']['coordinates'][1], point['t']) for point in cursor]
        log.info("--> %d points" % len(points))
        yield user_id, points
    yield (None, None)


class Point():