def getfeatures_by_program_event()

in source/controlplaneapi/runtime/app.py [0:0]


def getfeatures_by_program_event(program, event):
    """
    Get all the Features (as defined in plugin output attributes) based on Program and Event

    Returns:

        A list of Feature Names

    Raises:
        404 - NotFoundError
        500 - ChaliceViewError
    """
    features = []
    try:
        program = urllib.parse.unquote(program)
        event = urllib.parse.unquote(event)

        event_table = ddb_resource.Table(EVENT_TABLE_NAME)

        response = event_table.get_item(
            Key={
                "Name": event,
                "Program": program
            },
            ConsistentRead=True
        )
        if "Item" not in response:
            raise NotFoundError(f"Event '{event}' in Program '{program}' not found")

        profile = response['Item']['Profile']

        profile_table = ddb_resource.Table(PROFILE_TABLE_NAME)
        profile_response = profile_table.get_item(
            Key={
                "Name": profile
            },
            ConsistentRead=True
        )

        if "Item" not in profile_response:
            raise NotFoundError(f"Profile '{profile}' not found")

        plugin_table = ddb_resource.Table(PLUGIN_TABLE_NAME)

        if 'Featurers' in profile_response['Item']:
            for feature in profile_response['Item']['Featurers']:
                response = plugin_table.get_item(
                    Key={
                        "Name": feature['Name'],
                        "Version": "v0"
                    },
                    ConsistentRead=True
                )

                # if "Item" not in response:
                #    raise NotFoundError(f"Plugin '{feature['Name']}' not found")
                if "Item" in response:
                    if "OutputAttributes" in response['Item']:
                        for key in response['Item']['OutputAttributes'].keys():
                            features.append(f"{feature['Name']} | {key}")

                dependent_plugin_features = get_features_from_dependent_plugins(feature)
                features.extend(dependent_plugin_features)

        if 'Classifier' in profile_response['Item']:
            # for feature in profile_response['Item']['Classifier']:
            response = plugin_table.get_item(
                Key={
                    "Name": profile_response['Item']['Classifier']['Name'],
                    "Version": "v0"
                },
                ConsistentRead=True
            )
            if "Item" in response:
                if "OutputAttributes" in response['Item']:
                    for key in response['Item']['OutputAttributes'].keys():
                        features.append(f"{profile_response['Item']['Classifier']['Name']} | {key}")

                dependent_plugin_features = get_features_from_dependent_plugins(profile_response['Item']['Classifier'])
                features.extend(dependent_plugin_features)

        if 'Labeler' in profile_response['Item']:
            # for feature in profile_response['Item']['Classifier']:
            response = plugin_table.get_item(
                Key={
                    "Name": profile_response['Item']['Labeler']['Name'],
                    "Version": "v0"
                },
                ConsistentRead=True
            )
            if "Item" in response:
                if "OutputAttributes" in response['Item']:
                    for key in response['Item']['OutputAttributes'].keys():
                        features.append(f"{profile_response['Item']['Labeler']['Name']} | {key}")

                dependent_plugin_features = get_features_from_dependent_plugins(profile_response['Item']['Labeler'])
                features.extend(dependent_plugin_features)


    except Exception as e:
        print(f"Unable to get replays for Program and Event: {str(e)}")
        raise ChaliceViewError(f"Unable to get replays for Program and Event: {str(e)}")

    return replace_decimals(features)