def validate_opchars(scenario_id, subscenarios, subproblem, stage, conn, op_type):
    """

    :param subscenarios:
    :param subproblem:
    :param stage:
    :param conn:
    :param op_type:
    :return:
    """

    # TODO: deal with fuel and variable O&M column, which are nor optional nor
    #  required for any?

    # Get the opchar inputs for this operational type
    df = get_optype_inputs_from_db(scenario_id, subscenarios, conn, op_type)

    # Get the required, optional, and other columns with their types
    (
        required_columns_types,
        optional_columns_types,
        other_columns_types,
    ) = get_optype_param_requirements(op_type=op_type)
    req_cols = required_columns_types.keys()
    na_cols = other_columns_types.keys()

    # Check that required inputs are present
    write_validation_to_database(
        conn=conn,
        scenario_id=scenario_id,
        subproblem_id=subproblem,
        stage_id=stage,
        gridpath_module=__name__,
        db_table="inputs_project_operational_chars",
        severity="High",
        errors=validate_req_cols(df, req_cols, True, op_type),
    )

    # Check that other (not required or optional) inputs are not present
    write_validation_to_database(
        conn=conn,
        scenario_id=scenario_id,
        subproblem_id=subproblem,
        stage_id=stage,
        gridpath_module=__name__,
        db_table="inputs_project_operational_chars",
        severity="Low",
        errors=validate_req_cols(df, na_cols, False, op_type),
    )

    # TODO: do data-type and numeric non-negativity checking here rather than
    #  in project.init?

    # Return the opchar df (sometimes used for further validations)
    return df
Beispiel #2
0
    def test_validate_req_cols(self):
        """

        :return:
        """

        df_columns = ["project", "min_stable_level_fraction", "unit_size_mw",
                      "startup_cost_per_mw", "shutdown_cost_per_mw"]
        test_cases = {
            # Make sure correct inputs don't throw error
            1: {"df": pd.DataFrame(
                    columns=df_columns,
                    data=[["nuclear", 0.5, 100, None, None]]),
                "columns": ["min_stable_level_fraction", "unit_size_mw"],
                "required": True,
                "category": "Always_on",
                "result": []
                },
            # Make sure missing required inputs are flagged
            2: {"df": pd.DataFrame(
                    columns=df_columns,
                    data=[["nuclear", None, 100, None, None]]),
                "columns": ["min_stable_level_fraction", "unit_size_mw"],
                "required": True,
                "category": "Always_on",
                "result": ["project(s) 'nuclear'; Always_on should have "
                           "inputs for 'min_stable_level_fraction'"]
                },
            # Make sure incompatible inputs are flagged
            3: {"df": pd.DataFrame(
                    columns=df_columns,
                    data=[["nuclear", 0.5, 100, 1000, None]]),
                "columns": ["startup_cost_per_mw", "shutdown_cost_per_mw"],
                "required": False,
                "category": "Always_on",
                "result": ["project(s) 'nuclear'; Always_on should not have inputs for 'startup_cost_per_mw'"]
                }
        }

        for test_case in test_cases.keys():
            expected_list = test_cases[test_case]["result"]
            actual_list = module_to_test.validate_req_cols(
                df=test_cases[test_case]["df"],
                columns=test_cases[test_case]["columns"],
                required=test_cases[test_case]["required"],
                category=test_cases[test_case]["category"]
            )
            self.assertListEqual(expected_list, actual_list)