def METHOD_NAME(result: Mapping[str, Any]) -> Mapping[str, Any]:
    """
    Flatten metric result dictionary and normalize metric keys.
    :param result:
        the result dictionary.
    :return:
        the flattened metric results with normalized metric names.
    """
    # normalize keys
    # TODO: this can only normalize rank-based metrics!
    # TODO: find a better way to handle this
    flat_result = flatten_dictionary(result)
    result = {}
    for key, value in flat_result.items():
        try:
            key = MetricKey.normalize(key)
        except ValueError as error:
            logger.warning(f"Trying to fix malformed key: {error}")
            key = MetricKey.normalize(
                key.replace("nondeterministic", "").replace("unknown", "").strip(".").replace("..", ".")
            )
        result[key] = value
    return result