def make_result_dict(
    lad20cd,
    n_sensors,
    theta,
    oa_x,
    oa_y,
    oa11cd,
    sensors,
    total_coverage,
    oa_coverage,
    placement_history,
    coverage_history,
    oa_weight=None,
    pop_age_groups=None,
    population_weight=None,
    workplace_weight=None,
):
    """Package up optimisation parameters and results as a dictionary, which
    is used by the API and some other functions.

    Arguments:
        n_sensors {int} -- number of sensors
        theta {float} -- coverage decay parameter
        oa_x {list} -- x position of each OA
        oa_y {list} -- y position of each OA
        oa11cd {list} -- id of each OA
        sensors {list} -- 1 if OA has sensor, 0 otherwise
        total_coverage {float} -- total coverage metric for this network
        oa_coverage {list} -- coverage of each OA for this network

    Keyword Arguments:
        oa_weight {list} -- weight for each OA
        pop_age_groups {dict} -- population age groups (see calc_oa_weights)
        population_weight {float} -- Weighting for residential population
        workplace_weight {float} -- Weighting for workplace population

    Returns:
        dict -- Optimisation results and parameters. Keys: n_sensors, theta,
        pop_age_groups, population_weight, workplace_weight, sensors,
        total_coverage, oa_coverage
    """
    n_poi = len(oa_x)
    sensor_locations = [
        {"x": oa_x[i], "y": oa_y[i], "oa11cd": oa11cd[i]}
        for i in range(n_poi)
        if sensors[i] == 1
    ]

    oa_coverage = [
        {"oa11cd": oa11cd[i], "coverage": oa_coverage[i]} for i in range(n_poi)
    ]

    if oa_weight is not None:
        oa_weight = [
            {"oa11cd": oa11cd[i], "weight": oa_weight[i]} for i in range(n_poi)
        ]

    result = {
        "lad20cd": lad20cd,
        "n_sensors": n_sensors,
        "theta": theta,
        "sensors": sensor_locations,
        "total_coverage": total_coverage,
        "oa_coverage": oa_coverage,
        "oa_weight": oa_weight,
        "placement_history": placement_history,
        "coverage_history": coverage_history,
        "pop_age_groups": pop_age_groups,
        "population_weight": population_weight,
        "workplace_weight": workplace_weight,
    }

    return result