def finalize_data()

in mozetl/hardware_report/summarize_json.py [0:0]


def finalize_data(data, sample_count, broken_ratio, inactive_ratio, report_date):
    """Finalize the aggregated data.

    Translate raw sample numbers to percentages and add the date for the reported
    week along with the percentage of discarded samples due to broken data.

    Rename the keys to more human friendly names.

    Args:
        data: Data in aggregated form.
        sample_count: The number of samples the aggregates where generated from.
        broken_ratio: The percentage of samples discarded due to broken data.
        inactive_ratio: The percentage of samples discarded due to the client not sending data.
        report_date: The starting day for the reported week.

    Returns:
        An object containing the reported hardware statistics.

    """
    denom = float(sample_count)

    aggregated_percentages = {
        "date": report_date.date().isoformat(),
        "broken": broken_ratio,
        "inactive": inactive_ratio,
    }

    keys_translation = {
        "browser_arch": "browserArch_",
        "cpu_cores": "cpuCores_",
        "cpu_cores_speed": "cpuCoresSpeed_",
        "cpu_vendor": "cpuVendor_",
        "cpu_speed": "cpuSpeed_",
        "gfx0_vendor_name": "gpuVendor_",
        "gfx0_model": "gpuModel_",
        "resolution": "resolution_",
        "memory_gb": "ram_",
        "os": "osName_",
        "os_arch": "osArch_",
        "has_flash": "hasFlash_",
    }

    # Compute the percentages from the raw numbers.
    for k, v in data.items():
        # The old key is a tuple (key, value). We translate the key part and concatenate the
        # value as a string.
        new_key = keys_translation[k[0]] + text_type(k[1])
        aggregated_percentages[new_key] = v / denom

    return aggregated_percentages