Esempio 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
Esempio 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
def location_by_uid_day(uid, day):
    day = '201312' + day
    cols = ['start_time', 'location']
    db.ping(True)
    cursor = db.cursor()
    prepare_sql = """select start_time, location
                        from location_logs_with_date
                        where uid = %s and log_date = %s order by start_time"""
    cursor.execute(prepare_sql, (uid, day))
    rows = cursor.fetchall()
    results = [dict(list(zip(cols, row))) for row in rows]
    return make_response(dumps(merge_locations_by_date(results)))
Esempio n. 5
0
def location_by_uid_day(uid, day):
    day = '201312' + day
    cols = ['start_time', 'location']
    db.ping(True)
    cursor = db.cursor()
    prepare_sql = """select start_time, location
                        from location_logs_with_date
                        where uid = %s and log_date = %s order by start_time"""
    cursor.execute(prepare_sql, (uid, day))
    rows = cursor.fetchall()
    results = [dict(list(zip(cols, row))) for row in rows]
    return make_response(dumps(merge_locations_by_date(results)))
def entropy_by_uid_day(uid, day):
    day = '201312' + day
    cols = ['start_time', 'location']
    db.ping(True)
    cursor = db.cursor()
    prepare_sql = """select start_time, location
                        from location_logs_with_date
                        where uid = %s and log_date = %s order by start_time"""
    cursor.execute(prepare_sql, (uid, day))
    rows = cursor.fetchall()
    results = merge_locations_by_date([dict(list(zip(cols, row))) for row in rows])
    get_delta_by_day(results)
    moves = get_moves_by_day(results)
    result = []
    for move in moves:
        for location in move:
            result.append({
                'entropy': transient_entropy(location, move),
                'time': location['start_time']
            })
    return make_response(dumps(result))