from typing import Dict
from typing import Any


def convert_crowdsourced_old_to_new(old: Dict[str, Any]) -> Dict[str, Any]:
    """Convert scraped data from the original format (which had "answers-cleaned" field) to a clearer format."""
    raw = old["answerstrings"]
    clusters = {
        cluster["clusterid"]: {"count": cluster["count"], "answers": cluster["answers"]}
        for cluster in old["answers-cleaned"]
    }
    num_answers = sum([cluster["count"] for cluster in clusters.values()])
    assert num_answers == old["metadata"]["totalcount"]
    new = {
        "metadata": {
            "id": old["metadata"]["id"],
            "source": old["metadata"]["source"],
        },
        "question": {
            "original": old["question"]["question"],
            "normalized": old["question"]["normalized-question"],
        },
        "answers": {
            "raw": raw,
            "clusters": clusters,
        },
        "num": {"answers": num_answers, "clusters": len(clusters)},
    }
    return new