コード例 #1
0
def get_shared_rides(trip_id, threshold, max_time):
    with HanaConnection() as connection:
        start_time = time.time()
        # Get data from original trip
        connection.execute(get_start_and_end(trip_id))
        start_group, start_frame, end_group, end_frame = connection.fetchone()

        print('Get data from trip: {} ms'.format(
            (time.time() - start_time) * 1000))

        start_time = time.time()
        shift = max_time // 30
        shifted_start_frames = get_shifted_frames(start_frame, start_group,
                                                  shift)
        shifted_end_frames = get_shifted_frames(end_frame, end_group, shift)

        connection.execute(
            get_frame_shared_rides(trip_id, start_group, start_frame,
                                   end_group, end_frame, shifted_start_frames,
                                   shifted_end_frames, threshold))
        cursor = connection.fetchall()
        trip_data = frame_to_point_trips(cursor)
        geojson = [to_geojson(*trip) for trip in trip_data]
        print('Fetch shared rides: {} ms'.format(
            (time.time() - start_time) * 1000))

        return geojson, connection.execution_time
コード例 #2
0
def get_trip_by_id(trip_id, max_time):
    with HanaConnection() as connection:
        # 900 = 60 Seconds per Minute * 15 Minutes per frames
        max_group = (max_time // 900) + 1
        connection.execute(get_trip_by_id_sql(trip_id, max_group))
        cursor = connection.fetchall()
        points, timestamps = frame_to_point_with_limit(cursor, max_time)
        return to_geojson(trip_id, points,
                          timestamps), connection.execution_time
コード例 #3
0
def get_shared_rides(trip_id, max_distance, max_time):
    with HanaConnection() as connection:
        connection.execute(get_ride_by_id_sql(trip_id))
        trip = convert_trip(connection.fetchone())

        connection.execute(
            get_shared_ride_candidates_sql(trip, max_distance, max_time))
        cursor = connection.fetchall()
        trips = []
        for row in cursor:
            shared_trip = to_geojson(row, trip, max_distance, max_time)
            if shared_trip:
                trips.append(shared_trip)
    return trips, connection.execution_time
コード例 #4
0
def get_shared_rides(trip_id, threshold):
    with HanaConnection() as connection:
        connection.execute(get_start_and_end(trip_id))
        start_group, start_frame, end_group, end_frame, data = connection.fetchone(
        )
        sample = json.load(data)
        start_lon = sample[0][1]
        start_lat = sample[0][2]
        end_lon = sample[-1][1]
        end_lat = sample[-1][2]
        connection.execute(
            get_shared_rides_sql(start_lon, start_lat, start_group,
                                 start_frame, end_lon, end_lat, end_group,
                                 end_frame, threshold))
        cursor = connection.fetchall()
        return [to_geojson(trip) for trip in cursor]
コード例 #5
0
def get_trip_by_id(trip_id, max_time):
    with HanaConnection() as connection:
        connection.execute(get_trip_by_id_sql(trip_id))
        return to_geojson(trip_id, connection.fetchone(),
                          max_time), connection.execution_time
コード例 #6
0
def get_all_trip_ids(time, offset, limit):
    with HanaConnection() as connection:
        connection.execute(get_all_trip_ids_sql(time, offset, limit))
        return trip_ids_to_json(
            connection.fetchall()), connection.execution_time
コード例 #7
0
def get_shared_rides(trip_id, max_distance, max_time):
    with HanaConnection() as connection:
        connection.execute(
            get_shared_rides_sql(trip_id, max_distance, max_time))
        cursor = connection.fetchall()
        return all_trips_to_geojson(cursor), connection.execution_time
コード例 #8
0
def get_all_trajectory_ids():
    with HanaConnection() as connection:
        connection.execute(get_all_trajectory_ids_sql())
        return trajectory_ids_to_json(
            connection.fetchall()), connection.execution_time
コード例 #9
0
def get_trajectory_by_id(trajectory_id):
    with HanaConnection() as connection:
        connection.execute(get_trajectory_by_id_sql(trajectory_id))
        data = connection.fetchall()
        return frame_to_geojson(
            frame_to_point(data)), connection.execution_time
コード例 #10
0
def get_trajectory_by_id(trajectory_id):
    with HanaConnection() as connection:
        connection.execute(get_trajectory_by_id_sql(trajectory_id))
        data = connection.fetchone()
        return to_geojson(data), connection.execution_time