Exemplo n.º 1
0
    def test_minutes_difference(self):
        dt1 = datetime(2012, 10, 12, tzinfo=tzutc())
        dt2 = datetime(2012, 10, 12, 1, tzinfo=tzutc())
        self.assertEqual(utilities.minutes_difference(dt2, dt1), 60)

        dt3 = datetime(2012, 10, 13, 0, tzinfo=tzutc())
        self.assertEqual(utilities.minutes_difference(dt3, dt1), 24 * 60)

        dt4 = datetime(2012, 10, 13, 0, 1, tzinfo=tzutc())
        self.assertEqual(utilities.minutes_difference(dt4, dt1), 24 * 60 + 1)
Exemplo n.º 2
0
    def test_minutes_difference(self):
        dt1 = datetime(2012, 10, 12, tzinfo=tzutc())
        dt2 = datetime(2012, 10, 12, 1, tzinfo=tzutc())
        self.assertEqual(utilities.minutes_difference(dt2, dt1), 60)

        dt3 = datetime(2012, 10, 13, 0, tzinfo=tzutc())
        self.assertEqual(utilities.minutes_difference(dt3, dt1), 24*60)

        dt4 = datetime(2012, 10, 13, 0, 1, tzinfo=tzutc())
        self.assertEqual(utilities.minutes_difference(dt4, dt1), 24*60+1)
def convert_df_predictions_from_datetimes_to_minutes(df_predictions,
    midnight_time):
    """
    For each day we 
    """

    for i in df_predictions.index:
        df_predictions["actual_runway_arrival"][i] = tu.minutes_difference(
            df_predictions["actual_runway_arrival"][i], midnight_time)
        df_predictions["actual_gate_arrival"][i] = tu.minutes_difference(
            df_predictions["actual_gate_arrival"][i], midnight_time)

    return df_predictions
def write_flight_history_test_day_and_solution_test_flights_only(
        input_path, test_output_path, solution_path, cutoff_time):
    diverted_or_redirected_flight_ids = get_diverted_or_redirected_flights(
        input_path)

    codes_file = os.path.join(os.environ["DataPath"], "GEFlight", "Reference",
                              "usairporticaocodes.txt")
    us_icao_codes = get_us_airport_icao_codes(codes_file)
    midnight_time = datetime.datetime(cutoff_time.year,
                                      cutoff_time.month,
                                      cutoff_time.day,
                                      tzinfo=tz.tzutc())

    df = get_df_flight_history_from_train_format(input_path)

    original_length = len(df)

    df = df.select(lambda i: flight_history_row_in_test_set(
        df.irow(i), cutoff_time, us_icao_codes,
        diverted_or_redirected_flight_ids))

    df_test = df[[
        "flight_history_id", "departure_airport_code", "arrival_airport_code",
        "published_departure", "published_arrival", "scheduled_gate_departure",
        "scheduled_gate_arrival", "scheduled_runway_departure",
        "scheduled_runway_arrival"
    ]]

    df_test.to_csv(test_output_path, index=False)

    df_solution = df[[
        "flight_history_id", "actual_runway_arrival", "actual_gate_arrival"
    ]]

    for i in df_solution.index:
        df_solution["actual_runway_arrival"][i] = utilities.minutes_difference(
            df_solution["actual_runway_arrival"][i], midnight_time)
        df_solution["actual_gate_arrival"][i] = utilities.minutes_difference(
            df_solution["actual_gate_arrival"][i], midnight_time)

    df_solution.to_csv(solution_path, index=False)

    print("%s, %s: %d rows kept out of %d original lines" %
          (utilities.get_day_str(cutoff_time), "test_flights.csv",
           len(df_test), original_length))

    return df_test, df_solution
Exemplo n.º 5
0
def write_flight_history_test_day_and_solution_test_flights_only(input_path, test_output_path, solution_path, cutoff_time):
    diverted_or_redirected_flight_ids = get_diverted_or_redirected_flights(input_path)

    codes_file = os.path.join(os.environ["DataPath"], "GEFlight", "Reference", "usairporticaocodes.txt")
    us_icao_codes = get_us_airport_icao_codes(codes_file)
    midnight_time = datetime.datetime(cutoff_time.year, cutoff_time.month, cutoff_time.day, tzinfo=tz.tzutc())

    df = get_df_flight_history_from_train_format(input_path)
    
    original_length = len(df)

    df = df.select(lambda i: flight_history_row_in_test_set(df.irow(i), cutoff_time, us_icao_codes, diverted_or_redirected_flight_ids))

    df_test = df[["flight_history_id"
                , "departure_airport_code"
                , "arrival_airport_code"
                , "published_departure"
                , "published_arrival"
                , "scheduled_gate_departure"
                , "scheduled_gate_arrival"
                , "scheduled_runway_departure"
                , "scheduled_runway_arrival"]]        

    df_test.to_csv(test_output_path, index=False)
    
    df_solution = df[["flight_history_id"
                    , "actual_runway_arrival"
                    , "actual_gate_arrival"]]

    for i in df_solution.index:
        df_solution["actual_runway_arrival"][i] = utilities.minutes_difference(df_solution["actual_runway_arrival"][i], midnight_time)
        df_solution["actual_gate_arrival"][i] = utilities.minutes_difference(df_solution["actual_gate_arrival"][i], midnight_time)

    df_solution.to_csv(solution_path, index=False)

    print("%s, %s: %d rows kept out of %d original lines" % (utilities.get_day_str(cutoff_time), "test_flights.csv", len(df_test), original_length))

    return df_test, df_solution