Skip to content

CadetCareerProblem – Export Data Methods

export_data(datasets=None, printing=None)

Exports the desired problem instance datasets back to csvs.

Parameters: datasets (list of str): List of datasets to export. By default, the method exports the "Value Parameters" and "Solutions" datasets, as these are the ones that are likely to change the most. Other possible datasets are "AFSCs", "Cadets", "Preferences", and "Goal Programming". printing (bool): Whether to print status updates or not. If not specified, the value of self.printing will be used.

Returns: None

This method exports the specified datasets using the export_<dataset_name>_data functions from the afccp.data.processing module. The exported csvs are saved in the paths specified in the self.export_paths dictionary.

If the self.import_paths and self.export_paths attributes are not set, this method will call the afccp_dp.initialize_file_information function to create the necessary directories and set the paths.

If the "Goal Programming" dataset is included in the datasets parameter and the gp_df attribute is not None, the method exports the gp_df dataframe to a csv using the file path specified in the export_paths dictionary.

Source code in afccp/main.py
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
def export_data(self, datasets=None, printing=None):
    """
    Exports the desired problem instance datasets back to csvs.

    Parameters:
    datasets (list of str): List of datasets to export. By default, the method exports the "Value Parameters" and
        "Solutions" datasets, as these are the ones that are likely to change the most. Other possible datasets are
        "AFSCs", "Cadets", "Preferences", and "Goal Programming".
    printing (bool): Whether to print status updates or not. If not specified, the value of `self.printing` will
        be used.

    Returns:
    None

    This method exports the specified datasets using the `export_<dataset_name>_data` functions from the
    `afccp.data.processing` module. The exported csvs are saved in the paths specified in the
    `self.export_paths` dictionary.

    If the `self.import_paths` and `self.export_paths` attributes are not set, this method will call the
    `afccp_dp.initialize_file_information` function to create the necessary directories and set the paths.

    If the "Goal Programming" dataset is included in the `datasets` parameter and the `gp_df` attribute is not None,
    the method exports the `gp_df` dataframe to a csv using the file path specified in the `export_paths` dictionary.
    """

    # Parameter initialization
    if datasets is None:
        datasets = ["Cadets", "AFSCs", "Preferences", "Goal Programming", "Value Parameters",
                    "Solutions", "Additional", "Base Solutions", "Course Solutions"]
    if printing is None:
        printing = self.printing

    # Print statement
    if printing:
        print("Exporting datasets", datasets)

    # Shorten module name
    afccp_dp = afccp.data.processing

    # Check to make sure we have file data information
    for attribute in [self.import_paths, self.export_paths]:

        # If we don't have this information, that means this is a new instance to export
        if attribute is None:
            self.import_paths, self.export_paths = afccp_dp.initialize_file_information(self.data_name,
                                                                                        self.data_version)
            break

    # Export various data using the different functions
    dataset_function_dict = {"AFSCs": afccp_dp.export_afscs_data,
                             "Cadets": afccp_dp.export_cadets_data,
                             "Preferences": afccp_dp.export_afsc_cadet_matrices_data,
                             "Value Parameters": afccp_dp.export_value_parameters_data,
                             "Solutions": afccp_dp.export_solutions_data,
                             "Additional": afccp_dp.export_additional_data}
    for dataset in dataset_function_dict:
        if dataset in datasets:
            dataset_function_dict[dataset](self)

    # Goal Programming dataframe is an easy export (dataframe is already constructed)
    if "Goal Programming" in datasets and self.gp_df is not None:
        self.gp_df.to_csv(self.export_paths["Goal Programming"], index=False)

export_solution_results(printing=None)

This function exports the metrics for one solution back to excel for review

Source code in afccp/main.py
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
def export_solution_results(self, printing=None):
    """
    This function exports the metrics for one solution back to excel for review
    """
    if printing is None:
        printing = self.printing

    # Make sure we have a solution
    self._error_checking('Solution')

    # Create solution folder if necessary
    self._manage_solution_folder()

    # Filepath to export to
    filename = self.data_name + " " + self.solution_name + " (" + self.vp_name + ").xlsx"
    filepath = self.export_paths['Analysis & Results'] + self.solution_name + '/' + filename

    # Print statement
    if printing:
        print("Exporting solution", self.solution_name, "results to " + filepath + "...")

    # Export results
    afccp.data.processing.export_solution_results(self, filepath)

    if printing:
        print("Done.")