Ejemplo n.º 1
0
def test_calc_minute_of_day():
    time1 = datetime.time(hour=0, minute=1, second=1)
    time2 = datetime.time(hour=1, minute=0, second=1)
    time3 = datetime.time(hour=0, minute=0, second=0)
    time4 = datetime.time(hour=23, minute=59, second=59)

    value1 = support.calc_minute_of_day(time1)
    value2 = support.calc_minute_of_day(time2)
    value3 = support.calc_minute_of_day(time3)
    value4 = support.calc_minute_of_day(time4)

    run_tests.compare_answer(value1, 1, "minute of day = 1")
    run_tests.compare_answer(value2, 60, "minute of day = 2")
    run_tests.compare_answer(value3, 0, "minute of day = 3")
    run_tests.compare_answer(value4, 1439, "minute of day = 4")
Ejemplo n.º 2
0
def find_the_gaps_user_info_to_mp_fetched(dbcc, user_id, start_date,
                                          start_time, end_date, end_time,
                                          user_info_list):
    start_unix_minutes = support.date_time_to_unix_minutes_timestamp(
        datetime.datetime.combine(start_date, start_time))
    end_unix_minutes = support.date_time_to_unix_minutes_timestamp(
        datetime.datetime.combine(end_date, end_time))

    missing_ranges_unix_minutes = support.reduce_to_missing_ranges(
        user_info_list, lambda x: support.date_time_to_unix_minutes_timestamp(
            datetime.datetime.combine(x.date, x.time)), 1, start_unix_minutes,
        end_unix_minutes)

    mp_fetched = []

    for missing_range_unix_minutes in missing_ranges_unix_minutes:
        progression = missing_range_unix_minutes.get_progression()

        for missing_unix_minute in progression:
            date_time = support.unix_minutes_timestamp_to_date_time(
                missing_unix_minute)
            time = date_time.time()
            date = date_time.date()
            minute_of_day = support.calc_minute_of_day(time)
            day = support.calc_day(date)
            cell_id = 0

            new_mp_fetched = db_layout.MPFetched.new(dbcc, user_id,
                                                     minute_of_day, date, day,
                                                     cell_id)

            mp_fetched.append(new_mp_fetched)

    return mp_fetched
Ejemplo n.º 3
0
def find_the_gaps_user_info_to_mp_fetched(dbcc, user_id, start_date, start_time, end_date, end_time, user_info_list):
    start_unix_minutes = support.date_time_to_unix_minutes_timestamp(datetime.datetime.combine(start_date, start_time))
    end_unix_minutes = support.date_time_to_unix_minutes_timestamp(datetime.datetime.combine(end_date, end_time))

    missing_ranges_unix_minutes = support.reduce_to_missing_ranges(
        user_info_list,
        lambda x: support.date_time_to_unix_minutes_timestamp(datetime.datetime.combine(x.date, x.time)),
        1,
        start_unix_minutes,
        end_unix_minutes,
    )

    mp_fetched = []

    for missing_range_unix_minutes in missing_ranges_unix_minutes:
        progression = missing_range_unix_minutes.get_progression()

        for missing_unix_minute in progression:
            date_time = support.unix_minutes_timestamp_to_date_time(missing_unix_minute)
            time = date_time.time()
            date = date_time.date()
            minute_of_day = support.calc_minute_of_day(time)
            day = support.calc_day(date)
            cell_id = 0

            new_mp_fetched = db_layout.MPFetched.new(dbcc, user_id, minute_of_day, date, day, cell_id)

            mp_fetched.append(new_mp_fetched)

    return mp_fetched
Ejemplo n.º 4
0
def clear_user_information_maas_message(dbcc, msg):
    user_id = msg.user_id
    db_user_mobility_information_list = []

    #Save it in mean database and convert to db layout object
    for movement in msg.user_information:
        db_user_mobility_information = db_layout.UserMobilityInformation.new(
            dbcc, user_id, movement.time, movement.date, movement.cell_id)
        db_user_mobility_information_list.append(db_user_mobility_information)

    db_layout.UserMobilityInformation.save_many(
        dbcc, db_user_mobility_information_list)

    mp_fetched_list = []
    #Clear the data and save it in the fetched database
    for db_user_mobility_information in db_user_mobility_information_list:
        minute_of_day = support.calc_minute_of_day(
            db_user_mobility_information.time)
        day = support.calc_day(db_user_mobility_information.date)

        mp_fetched = db_layout.MPFetched.new(
            dbcc, user_id, minute_of_day, db_user_mobility_information.date,
            day, db_user_mobility_information.cell_id)
        mp_fetched_list.append(mp_fetched)

    #Fill in gaps
    end_date_time = datetime.datetime.combine(
        msg.start_date,
        msg.start_time) + datetime.timedelta(seconds=msg.time_span)

    gaps_mp_fetched = find_the_gaps_user_info_to_mp_fetched(
        dbcc, msg.user_id,
        msg.start_date, msg.start_time, end_date_time.date(),
        end_date_time.time(), db_user_mobility_information_list)

    mp_fetched_list.extend(gaps_mp_fetched)
    db_layout.MPFetched.save_many(dbcc, mp_fetched_list)

    err.log_error(
        err.INFO, "Cleared " + str(len(msg.user_information)) +
        " rows user information data")
    err.log_error(
        err.INFO, "Filled in " + str(len(gaps_mp_fetched)) +
        " holes with mp fetched data")

    return sr.SuppliedUserInfo.from_maas_user_info_message_to_supplied_info(
        msg)
def mobility_prediction(pykov_chain, current_cell_id, current_date, current_time, predicted_date, predicted_time):
    initial_minute_of_day = support.calc_minute_of_day(current_time)
    initial_day = support.calc_day(current_date)

    initial_key = UserEntry(initial_day, initial_minute_of_day, current_cell_id).to_pykov_key()
    initial_pykov_vector = pykov.Vector({initial_key: 1})

    difference_in_seconds = (
        datetime.datetime.combine(predicted_date, predicted_time)
        - datetime.datetime.combine(current_date, current_time)
    ).total_seconds()
    difference_in_minutes = int(difference_in_seconds / 60)

    distribution_dict = pykov_chain.pow(initial_pykov_vector, difference_in_minutes)
    print "eeeeeee", distribution_dict

    return distribution_dict
Ejemplo n.º 6
0
def clear_user_information_maas_message(dbcc, msg):
    user_id = msg.user_id
    db_user_mobility_information_list = []

    # Save it in mean database and convert to db layout object
    for movement in msg.user_information:
        db_user_mobility_information = db_layout.UserMobilityInformation.new(
            dbcc, user_id, movement.time, movement.date, movement.cell_id
        )
        db_user_mobility_information_list.append(db_user_mobility_information)

    db_layout.UserMobilityInformation.save_many(dbcc, db_user_mobility_information_list)

    mp_fetched_list = []
    # Clear the data and save it in the fetched database
    for db_user_mobility_information in db_user_mobility_information_list:
        minute_of_day = support.calc_minute_of_day(db_user_mobility_information.time)
        day = support.calc_day(db_user_mobility_information.date)

        mp_fetched = db_layout.MPFetched.new(
            dbcc, user_id, minute_of_day, db_user_mobility_information.date, day, db_user_mobility_information.cell_id
        )
        mp_fetched_list.append(mp_fetched)

    # Fill in gaps
    end_date_time = datetime.datetime.combine(msg.start_date, msg.start_time) + datetime.timedelta(
        seconds=msg.time_span
    )

    gaps_mp_fetched = find_the_gaps_user_info_to_mp_fetched(
        dbcc,
        msg.user_id,
        msg.start_date,
        msg.start_time,
        end_date_time.date(),
        end_date_time.time(),
        db_user_mobility_information_list,
    )

    mp_fetched_list.extend(gaps_mp_fetched)
    db_layout.MPFetched.save_many(dbcc, mp_fetched_list)

    err.log_error(err.INFO, "Cleared " + str(len(msg.user_information)) + " rows user information data")
    err.log_error(err.INFO, "Filled in " + str(len(gaps_mp_fetched)) + " holes with mp fetched data")

    return sr.SuppliedUserInfo.from_maas_user_info_message_to_supplied_info(msg)
Ejemplo n.º 7
0
def mobility_prediction(pykov_chain, current_cell_id, current_date,
                        current_time, predicted_date, predicted_time):
    initial_minute_of_day = support.calc_minute_of_day(current_time)
    initial_day = support.calc_day(current_date)

    initial_key = UserEntry(initial_day, initial_minute_of_day,
                            current_cell_id).to_pykov_key()
    initial_pykov_vector = pykov.Vector({initial_key: 1})

    difference_in_seconds = (
        datetime.datetime.combine(predicted_date, predicted_time) -
        datetime.datetime.combine(current_date, current_time)).total_seconds()
    difference_in_minutes = int(difference_in_seconds / 60)

    distribution_dict = pykov_chain.pow(initial_pykov_vector,
                                        difference_in_minutes)
    print 'eeeeeee', distribution_dict

    return distribution_dict