Пример #1
0
def get_bounds(sectionList):
    # Lat and lng are going to be in the range of -180 to 180.
    # So let's pick large positive and negative numbers to initialize them
    min_lat = 999999
    min_lon = 999999
    max_lat = -9999999
    max_lon = -9999999
    for sectionJSON in sectionList:
        section = rt.Section.section_from_json(sectionJSON)
        logging.debug("Testing start point %s " %
                      section.section_start_location)
        if section.section_start_location.lat < min_lat:
            min_lat = section.section_start_location.lat
        if section.section_start_location.lon < min_lon:
            min_lon = section.section_start_location.lon

        logging.debug("Testing end point %s " % section.section_end_location)
        if section.section_end_location.lat > max_lat:
            max_lat = section.section_end_location.lat
        if section.section_end_location.lon > max_lon:
            max_lon = section.section_end_location.lon
    return (rt.Coordinate(min_lat, min_lon), rt.Coordinate(max_lat, max_lon))
Пример #2
0
def get_one_random_point_in_radius(crd, radius):
    # From https://gis.stackexchange.com/questions/25877/how-to-generate-random-locations-nearby-my-location
    radius_in_degrees = kilometers_to_degrees(radius)
    x_0 = crd.get_lon()
    y_0 = crd.get_lat()
    u = random.random()
    v = random.random()
    w = radius_in_degrees * math.sqrt(u)
    t = 2 * math.pi * v
    x = w * math.cos(t)
    y = w * math.sin(t)
    x = old_div(float(x), float(math.cos(y_0))) # To account for Earth curvature stuff
    to_return = to.Coordinate(y + y_0, x + x_0)
    return to_return
Пример #3
0
def google_maps_to_our_trip(google_maps_json,
                            _id,
                            user_id,
                            trip_id,
                            mode,
                            org_start_time,
                            itinerary=0):
    sections = []
    time = org_start_time
    for leg in google_maps_json['routes'][itinerary]['legs']:
        td = coerce_gmaps_time(leg['duration']['text'])
        coords = []
        for step in leg['steps']:
            coords.append(
                ewt.Coordinate(step['end_location']['lat'],
                               step['end_location']['lng']))
        distance = leg['distance']
        start_location = ewt.Coordinate(leg['start_location']['lat'],
                                        leg['start_location']['lng'])
        end_location = ewt.Coordinate(leg['end_location']['lat'],
                                      leg['end_location']['lng'])
        end_time = time + td
        section = ewt.Section(0, user_id, trip_id, distance, "move", time,
                              end_time, start_location, end_location, mode,
                              mode)
        section.points = coords
        sections.append(section)
        time = end_time
        start_trip = sections[0].section_start_location
        end_trip = sections[-1].section_end_location
    #TODO: actually calculate cost
    cost = 0
    parent_id = trip_id
    mode_list = [str(mode)]
    return ewt.Alternative_Trip(_id, user_id, trip_id, sections,
                                org_start_time, end_time, start_trip, end_trip,
                                parent_id, cost, mode_list)
Пример #4
0
import emission.core.wrapper.trip_old as to
import emission.net.ext_service.gmaps.googlemaps as gmaps
import emission.net.ext_service.gmaps.common as gmcommon
import emission.core.get_database as edb

import datetime
import random
import math
import urllib.request, urllib.error, urllib.parse
import json
import heapq
import time
import requests
import random

CENTER_OF_CAMPUS = to.Coordinate(37.871790, -122.260005)
RANDOM_RADIUS = .3  # 300 meters around center of campus; for randomization
N_TOP_TRIPS = 3 # Number of top trips we return for the user to look at

key_file = open("conf/net/ext_service/googlemaps.json")
GOOGLE_MAPS_KEY = json.load(key_file)["api_key"]


class UserBase(object):

    """ 
    Stores all the users and stores the population of areas  
    Also keeps state on other useful things that we need to know, like caches
    """

    def __init__(self):