def get_fake_points(origin, destination): all_points.append(origin) params = { 'origin': "%s,%s" % (origin[LAT], origin[LON]), 'destination': "%s,%s" % (destination[LAT], destination[LON]), 'mode': "driving", # 'avoid': "highways", 'sensor': "false" } params = net.urlencode(params) url = "http://maps.googleapis.com/maps/api/directions/json?" + params response = net.read(url) directions = json.loads(response) try: steps = directions['routes'][0]['legs'][0]['steps'] except Exception as e: print(response) exit() points = [] for i, step in enumerate(steps): instruction = step['html_instructions'] instructions.append(instruction) if i != 0: point = [step['start_location']['lng'], step['start_location']['lat'], None, None, None] points.append(point) if i != len(steps) - 1: point = [step['end_location']['lng'], step['end_location']['lat'], None, None, None] points.append(point) for point in points: point[X] = util.scale(point[LON], min_lon, max_lon) point[Y] = util.scale(point[LAT], min_lat, max_lat) all_points.append(point) all_points.append(destination) return points
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")
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) points = list(points) for walk in walks: for point in walk['points']: point[X] = util.scale(point[X], min_x, max_x) point[Y] = util.scale(point[Y], min_y, max_y) ctx = drawing.Context(1000, int(1000.0/ratio), relative=True, flip=True, hsv=True, margin=20, background=(252/256, 245/256, 216/256)) for w, walk in enumerate(walks): c = float(w) / len(walks) points = [(point[X], point[Y]) for point in walk['points']] # ctx.line(points, thickness=3.0, stroke=(0.55, 1.0, c)) # ctx.line(points, thickness=3.0, stroke=(0.55, 0.0, c)) # ctx.line(points, thickness=5.0, stroke=(0.55, 1.0, 0.7, 0.4)) ctx.line(points, thickness=5.0, stroke=(0.55, 0.0, 0.0, 0.4)) ctx.output("charts/geo_%s.png" % int(time.time()))
points = json.loads(open("thief_points.json").read()) points = np.array([(float(point['lon']), float(point['lat']), time.mktime(util.parse_date(point['time']).timetuple()), None, None) for point in points]) median_lon = np.median(points[:,0]) median_lat = np.median(points[:,1]) points = np.array([point for point in points if abs(point[0] - median_lon) < ZOOM and abs(point[1] - median_lat) < ZOOM]) max_lon = np.max(points[:,0]) min_lon = np.min(points[:,0]) max_lat = np.max(points[:,1]) min_lat = np.min(points[:,1]) points = list(points) for point in points: point[X] = util.scale(point[LON], min_lon, max_lon) point[Y] = util.scale(point[LAT], min_lat, max_lat) all_points = [] # should also print out the directions instructions = [] def get_fake_points(origin, destination): all_points.append(origin) params = { 'origin': "%s,%s" % (origin[LAT], origin[LON]), 'destination': "%s,%s" % (destination[LAT], destination[LON]), 'mode': "driving", # 'avoid': "highways", 'sensor': "false" }