Пример #1
0
def _parse_child(child_name, child, child_path):
    if 'values' in child:
        return parameters.Parameter(child_name, child, child_path)
    elif 'brackets' in child:
        return parameters.ParameterScale(child_name, child, child_path)
    elif isinstance(child, dict) and all(
        [periods.INSTANT_PATTERN.match(str(key)) for key in child.keys()]):
        return parameters.Parameter(child_name, child, child_path)
    else:
        return parameters.ParameterNode(child_name,
                                        data=child,
                                        file_path=child_path)
Пример #2
0
def load_parameter_file(file_path, name=''):
    """
    Load parameters from a YAML file (or a directory containing YAML files).

    :returns: An instance of :class:`.ParameterNode` or :class:`.ParameterScale` or :class:`.Parameter`.
    """
    if not os.path.exists(file_path):
        raise ValueError("{} does not exist".format(file_path))
    if os.path.isdir(file_path):
        return parameters.ParameterNode(name, directory_path=file_path)
    data = _load_yaml_file(file_path)
    return _parse_child(name, data, file_path)
def node():
    return parameters.ParameterNode(
        "baremes",
        data = {
            "health": {
                "brackets": [
                    {"rate": {"2015-01-01": 0.05}, "threshold": {"2015-01-01": 0}},
                    {"rate": {"2015-01-01": 0.10}, "threshold": {"2015-01-01": 2000}},
                    ]
                },
            "retirement": {
                "brackets": [
                    {"rate": {"2015-01-01": 0.02}, "threshold": {"2015-01-01": 0}},
                    {"rate": {"2015-01-01": 0.04}, "threshold": {"2015-01-01": 3000}},
                    ]
                },
            },
        )(2015)