Пример #1
0
def test_reduce_to_missing_ranges():
    l1 = [1, 2, 10, 40, 41, 50]
    answer1 = [support.Range(3, 9, 1), support.Range(11, 39, 1), support.Range(42, 49, 1)]
    result1 = support.reduce_to_missing_ranges(l1, lambda x: x, 1, 1, 50)
    run_tests.compare_answer(result1, answer1, "missing_support.Ranges 1")

    #Difficult one because one value is outside of the (start value, end value) support.Range while the resolution allows it
    l2 = [9, 11]
    answer2 = [support.Range(1, 6, 3), support.Range(10, 10, 3)]
    result2 = support.reduce_to_missing_ranges(l2, lambda x: x, 3, 1, 10)
    run_tests.compare_answer(result2, answer2, "missing_ranges 2")
Пример #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
Пример #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
def check_integrity_bandwidth_prediction_data(bpfetched, date, end_time):
    end_time_unix = support.to_unix_timestamp_from_date_and_time(date, end_time)
    start_time_unix = end_time_unix - config.BP_USE_DATA_FROM_LAST_SECONDS

    list_time_throughput_bps = map(db_layout.BPFetched.to_tuple_without_link_id, bpfetched)

    missing_ranges = support.reduce_to_missing_ranges( list_time_throughput_bps
                                                     , lambda (time, throughput): time
                                                     , 1
                                                     , start_time_unix
                                                     , end_time_unix
                                                     )

    return missing_ranges
def check_user_mobility_data_single_user_integrity(grouped_by_date_grid_by_minute_of_day_mp_fetched, current_date):
    missing_ranges_date_time_date_time = []

    current_unix_days = support.date_to_unix_days_timestamp(current_date)
    history_unix_days = current_unix_days - config.MP_USE_DATA_FROM_LAST_DAYS
    current_unix_week = int(current_unix_days / common_config.DAYS_IN_A_WEEK)
    history_unix_week = int(history_unix_days / common_config.DAYS_IN_A_WEEK)

    # Find missing weeks
    all_weeks = map(
        lambda x: support.date_to_unix_weeks_timestamp(x), grouped_by_date_grid_by_minute_of_day_mp_fetched.keys()
    )

    missing_ranges_unix_weeks = support.reduce_to_missing_ranges(
        all_weeks, lambda i: i, 1, history_unix_week, current_unix_week
    )

    missing_ranges_date = map(
        lambda x: support.Range(
            support.unix_weeks_timestamp_to_date_range(x.min_range).min_range,
            support.unix_weeks_timestamp_to_date_range(x.max_range).max_range,
            support.Range.RESOLUTION_DATETIME_DAY,
        ),
        missing_ranges_unix_weeks,
    )

    # Add the missing days
    begin_of_day_time = datetime.time(0, 0, 0)
    end_of_day_time = datetime.time(23, 59, 59)
    for missing_range_date in missing_ranges_date:
        start_date_time = datetime.datetime.combine(missing_range_date.min_range, begin_of_day_time)
        end_date_time = datetime.datetime.combine(missing_range_date.max_range, end_of_day_time)

        missing_ranges_date_time_date_time.append(
            support.Range(start_date_time, end_date_time, support.Range.RESOLUTION_DATETIME_MINUTE)
        )

    # Calculate the missing time ranges in each day that already exists
    for date, grid_by_minute_of_day_mp_fetched in grouped_by_date_grid_by_minute_of_day_mp_fetched.items():
        missing_ranges_in_minutes = support.reduce_to_missing_ranges_already_grid(
            grid_by_minute_of_day_mp_fetched, 1, 0, common_config.MINUTES_IN_A_DAY - 1
        )

        missing_ranges_in_time = map(
            lambda missing_range: support.Range(
                support.calc_time_from_minute_of_day(missing_range.min_range),
                support.calc_time_from_minute_of_day(missing_range.max_range),
                support.Range.RESOLUTION_DATETIME_SECOND,
            ),
            missing_ranges_in_minutes,
        )

        # Add the missing times for a certain day
        for missing_range_in_time in missing_ranges_in_time:
            start_date_time = datetime.datetime.combine(date, missing_range_in_time.min_range)
            end_date_time = datetime.datetime.combine(date, missing_range_in_time.max_range)

            missing_ranges_date_time_date_time.append(
                support.Range(start_date_time, end_date_time, support.Range.RESOLUTION_DATETIME_MINUTE)
            )

    return missing_ranges_date_time_date_time
Пример #6
0
def check_user_mobility_data_single_user_integrity(
        grouped_by_date_grid_by_minute_of_day_mp_fetched, current_date):
    missing_ranges_date_time_date_time = []

    current_unix_days = support.date_to_unix_days_timestamp(current_date)
    history_unix_days = current_unix_days - config.MP_USE_DATA_FROM_LAST_DAYS
    current_unix_week = int(current_unix_days / common_config.DAYS_IN_A_WEEK)
    history_unix_week = int(history_unix_days / common_config.DAYS_IN_A_WEEK)

    #Find missing weeks
    all_weeks = map(lambda x: support.date_to_unix_weeks_timestamp(x),
                    grouped_by_date_grid_by_minute_of_day_mp_fetched.keys())

    missing_ranges_unix_weeks = support.reduce_to_missing_ranges(
        all_weeks, lambda i: i, 1, history_unix_week, current_unix_week)

    missing_ranges_date = map(
        lambda x: support.Range(
            support.unix_weeks_timestamp_to_date_range(x.min_range).min_range,
            support.unix_weeks_timestamp_to_date_range(x.max_range).max_range,
            support.Range.RESOLUTION_DATETIME_DAY), missing_ranges_unix_weeks)

    #Add the missing days
    begin_of_day_time = datetime.time(0, 0, 0)
    end_of_day_time = datetime.time(23, 59, 59)
    for missing_range_date in missing_ranges_date:
        start_date_time = datetime.datetime.combine(
            missing_range_date.min_range, begin_of_day_time)
        end_date_time = datetime.datetime.combine(missing_range_date.max_range,
                                                  end_of_day_time)

        missing_ranges_date_time_date_time.append(
            support.Range(start_date_time, end_date_time,
                          support.Range.RESOLUTION_DATETIME_MINUTE))

    #Calculate the missing time ranges in each day that already exists
    for date, grid_by_minute_of_day_mp_fetched in grouped_by_date_grid_by_minute_of_day_mp_fetched.items(
    ):
        missing_ranges_in_minutes = support.reduce_to_missing_ranges_already_grid(
            grid_by_minute_of_day_mp_fetched, 1, 0,
            common_config.MINUTES_IN_A_DAY - 1)

        missing_ranges_in_time = map(
            lambda missing_range: support.Range(
                support.calc_time_from_minute_of_day(missing_range.min_range),
                support.calc_time_from_minute_of_day(missing_range.max_range),
                support.Range.RESOLUTION_DATETIME_SECOND),
            missing_ranges_in_minutes)

        #Add the missing times for a certain day
        for missing_range_in_time in missing_ranges_in_time:
            start_date_time = datetime.datetime.combine(
                date, missing_range_in_time.min_range)
            end_date_time = datetime.datetime.combine(
                date, missing_range_in_time.max_range)

            missing_ranges_date_time_date_time.append(
                support.Range(start_date_time, end_date_time,
                              support.Range.RESOLUTION_DATETIME_MINUTE))

    return missing_ranges_date_time_date_time