Esempio n. 1
0
def normalize(stations):
    extract = tools.extract_element
    normalized = lambda station: {
        'name':
        extract(station, 'name'),
        'address':
        extract(station, 'name'),
        'lat':
        float(extract(station, 'lat')),
        'lon':
        float(extract(station, 'long')),
        'status':
        'OPEN' if extract(station, 'locked') == 'false' else 'CLOSED',
        'bikes':
        int(extract(station, 'nbbikes')),
        'stands':
        int(extract(station, 'nbemptydocks')),
        'update':
        tools.epoch_to_datetime(int(extract(station, 'latestupdatetime')),
                                divisor=1000).isoformat()
    }
    return [
        normalized(station) for station in stations.find_all('station')
        if extract(station, 'latestupdatetime') is not None
    ]
Esempio n. 2
0
def normalize(stations):
    normalized = lambda station: {
        'name': station['name'],
        'address': station['address'],
        'lat': station['position']['lat'],
        'lon': station['position']['lng'],
        'status': station['status'],
        'bikes': station['available_bikes'],
        'stands': station['available_bike_stands'],
        'update': tools.epoch_to_datetime(station['last_update'],
                                          divisor=1000).isoformat()
    }
    return [normalized(station) for station in stations]
Esempio n. 3
0
def normalize(stations):
    extract = tools.extract_element
    normalized = lambda station: {
        'name': extract(station, 'name'),
        'address': extract(station, 'name'),
        'lat': float(extract(station, 'lat')),
        'lon': float(extract(station, 'long')),
        'status': 'OPEN' if extract(station, 'locked') == 'false' else 'CLOSED',
        'bikes': int(extract(station, 'nbbikes')),
        'stands': int(extract(station, 'nbemptydocks')),
        'update': tools.epoch_to_datetime(int(extract(station,
                                          'latestupdatetime')),
                                          divisor=1000).isoformat()
    }
    return [normalized(station) for station
            in stations.find_all('station')]
Esempio n. 4
0
def generate_path(situation,
                  target,
                  distance,
                  mode,
                  stationFirst=False,
                  nbCandidates=5):
    '''
    Choose the best station around the arrival and then define a trip
    between the departure and the station.
    '''
    city = situation['city']
    people = situation['people']
    time = tools.convert_time(situation['time'])
    # Convert the positions to (lat, lon) if they are textual addresses
    departure = geography.convert_to_point(city, situation['departure'])
    arrival = geography.convert_to_point(city, situation['arrival'])
    # Find the close stations with MongoDB and Hilbert curves
    stations = [
        station
        for station in geo.close_points(city, arrival, number=nbCandidates)
    ]
    # Get the distances to the stations
    candidates = geography.compute_distances_manual(arrival, stations,
                                                    distance)
    # Sort the stations by distance
    candidates.sort(key=lambda station: station['duration'])
    # Find an appropriate solution through the sorted candidates
    trip = False
    for candidate in candidates:
        # Calculate what time it would be when reaching the candidate station
        currentTime = time + candidate['duration']
        currentTime = tools.epoch_to_datetime(time)
        prediction = wrapper.predict('forest', currentTime, target, city,
                                     candidate['_id'])
        # Check if the prediction is satisfying
        if prediction >= people:
            stationPosition = list(reversed(candidate['p']))
            if stationFirst is False:
                trip = reshape(mode, departure, stationPosition)
            else:
                trip = reshape(mode, stationPosition, departure)
            break
    return trip
Esempio n. 5
0
def generate_path(situation, target, distance, mode, stationFirst=False,
                  nbCandidates=5):
    '''
    Choose the best station around the arrival and then define a trip
    between the departure and the station.
    '''
    city = situation['city']
    people = situation['people']
    time = tools.convert_time(situation['time'])
    # Convert the positions to (lat, lon) if they are textual addresses
    departure = geography.convert_to_point(city, situation['departure'])
    arrival = geography.convert_to_point(city, situation['arrival'])
    # Find the close stations with MongoDB and Hilbert curves
    stations = [station for station in
                geo.close_points(city, arrival, number=nbCandidates)]
    # Get the distances to the stations
    candidates = geography.compute_distances_manual(arrival, stations,
                                                    distance)
    # Sort the stations by distance
    candidates.sort(key=lambda station: station['duration'])
    # Find an appropriate solution through the sorted candidates
    trip = False
    for candidate in candidates:
        # Calculate what time it would be when reaching the candidate station
        currentTime = time + candidate['duration']
        currentTime = tools.epoch_to_datetime(time)
        prediction = wrapper.predict('forest', currentTime, target,
                                     city, candidate['_id'])
        # Check if the prediction is satisfying
        if prediction >= people:
            stationPosition = list(reversed(candidate['p']))
            if stationFirst is False:
                trip = reshape(mode, departure, stationPosition)
            else:
                trip = reshape(mode, stationPosition, departure)
            break
    return trip