Python functions

The modeling project must provide a Python function for each of the following tasks:

Once you've skimmed the criteria below, you can develop your functions against the computestudiokit automated testing suite.

Model Parameters

Accepts Meta Parameters, if they are being utilized. Returns data in the form specified in the inputs page.

import matchups

def get_inputs(meta_params_dict):
    meta_params = MetaParams()
    params = MatchupsParams()
    spec = params.specification(
    return meta_params.specification(meta_data=True), {"matchup": spec}

Here's what you get after filling in this function: alt text

Validate user adjustments

Accepts parsed user adjustments, separated by each major section. Returns warnings/errors (if any).

Compute Studio will provide parsed user adjustments of the form:

    "matchup": {
        "start_date": [{"value": "2012-08-01"}],
        "end_date": [{"value": "2012-09-01"}],
        "pitcher": [{"value": "Not a Real Pitcher"}],

The function should return:


        "matchup": {
            "errors": {
                "pitcher": ['Pitcher "Not a Real Pitcher" not allowed']
            "warnings": {}
import matchups

def validate_inputs(meta_param_dict, adjustment, errors_warnings):
    # matchups doesn't look at meta_param_dict for validating inputs.
    params = MatchupsParams()
    params.adjust(adjustment["matchup"], raise_errors=False)
    return errors_warnings

Here's what you get after filling in this function: alt text

Run simulation

Accepts Meta Parameters values and model parameters. Returns outputs as specified in the outputs page

Compute Studio submits the model's meta parameters and the parsed and formatted user adjustments:

    "meta_params": {},
    "model_params": {
        "some_major_section": {},
        "another_major_section": {}
import matchups

def get_matchup(meta_param_dict, adjustment):
    result = matchups.get_matchup(meta_param_dict, adjustment)
    return result

Here's what you get after filling in this function:

alt text