Ejemplo n.º 1
0
def get_speed_by_day_at_change_point(all_rows, day):
    cols = ['start_time', 'location']
    speeds = []
    results = merge_locations_by_date([dict(list(zip(cols, row))) for row in all_rows])

    points = set()
    for location in results:
        points.add(location['start_time'])
        points.add(location['end_time'])
    points = [str2date(x) for x in sorted(points)]

    if len(all_rows) == 0:
        return speeds

    delta_t = 60
    for i in range(len(points)):
        start_time = points[i] - datetime.timedelta(minutes=delta_t / 2)
        end_time = points[i] + datetime.timedelta(minutes=delta_t / 2)
        rows = [x for x in all_rows if date2str(start_time) <= x[0] <= date2str(end_time)]
        if len(rows) == 0:
            speeds.append({
                'time': date2str(points[i]),
                'speed': 0
            })
            continue
        rows = merge_locations_by_date([dict(list(zip(cols, row))) for row in rows])
        get_delta_by_day(rows)
        speed = entropy(rows, delta_t, [start_time, end_time])
        speeds.append({
            'time': date2str(points[i]),
            'speed': speed
        })
    return speeds
def get_speed_by_day(all_rows, day):
    timestamps = pd.date_range(start=day + '001500',
                               end=day + '235959',
                               freq='30Min')
    cols = ['start_time', 'location']
    speeds = []

    if len(all_rows) == 0:
        return speeds

    delta_t = 60
    for i in range(len(timestamps)):
        start_time = timestamps[i].to_datetime() - datetime.timedelta(minutes=delta_t / 2)
        end_time = timestamps[i].to_datetime() + datetime.timedelta(minutes=delta_t / 2)
        rows = [x for x in all_rows if date2str(start_time) <= x[0] <= date2str(end_time)]
        if len(rows) == 0:
            speeds.append({
                'time': date2str(timestamps[i]),
                'speed': 0
            })
            continue
        rows = merge_locations_by_date([dict(list(zip(cols, row))) for row in rows])
        get_delta_by_day(rows)
        speed = entropy(rows, delta_t, [start_time, end_time])
        speeds.append({
            'time': date2str(timestamps[i]),
            'speed': speed
        })
    return speeds
Ejemplo n.º 3
0
def get_speed_by_day(all_rows, day):
    timestamps = pd.date_range(start=day + '001500',
                               end=day + '235959',
                               freq='30Min')
    cols = ['start_time', 'location']
    speeds = []

    if len(all_rows) == 0:
        return speeds

    delta_t = 60
    for i in range(len(timestamps)):
        start_time = timestamps[i].to_datetime() - datetime.timedelta(minutes=delta_t / 2)
        end_time = timestamps[i].to_datetime() + datetime.timedelta(minutes=delta_t / 2)
        rows = [x for x in all_rows if date2str(start_time) <= x[0] <= date2str(end_time)]
        if len(rows) == 0:
            speeds.append({
                'time': date2str(timestamps[i]),
                'speed': 0
            })
            continue
        rows = merge_locations_by_date([dict(list(zip(cols, row))) for row in rows])
        get_delta_by_day(rows)
        speed = entropy(rows, delta_t, [start_time, end_time])
        speeds.append({
            'time': date2str(timestamps[i]),
            'speed': speed
        })
    return speeds