def get_valid_client_record()

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


def get_valid_client_record(r, data_index):
    """Check if the referenced record is sane or contains partial/broken data.

    Args:
        r: The client entry in the longitudinal dataset.
        dat_index: The index of the sample within the client record.

    Returns:
        An object containing the client hardware data or REASON_BROKEN_DATA if the
        data is invalid.

    """
    gfx_adapters = r["system_gfx"][data_index]["adapters"]
    monitors = r["system_gfx"][data_index]["monitors"]

    # We should make sure to have GFX adapter. If we don't, discard this
    # record.
    if not gfx_adapters or not gfx_adapters[0]:
        return REASON_BROKEN_DATA

    # Due to bug 1175005, Firefox on Linux isn't sending the screen resolution data.
    # Don't discard the rest of the ping for that: just set the resolution to 0 if
    # unavailable. See bug 1324014 for context.
    screen_width = 0
    screen_height = 0
    if monitors and monitors[0]:
        screen_width = monitors[0]["screen_width"]
        screen_height = monitors[0]["screen_height"]

    # Non Windows OS do not have that property.
    is_wow64 = r["system"][data_index]["is_wow64"] is True

    # At this point, we should have filtered out all the weirdness. Fetch
    # the data we need.
    data = {
        "browser_arch": r["build"][data_index]["architecture"],
        "os_name": r["system_os"][data_index]["name"],
        "os_version": r["system_os"][data_index]["version"],
        "memory_mb": r["system"][data_index]["memory_mb"],
        "is_wow64": is_wow64,
        "gfx0_vendor_id": gfx_adapters[0]["vendor_id"],
        "gfx0_device_id": gfx_adapters[0]["device_id"],
        "screen_width": screen_width,
        "screen_height": screen_height,
        "cpu_cores": r["system_cpu"][data_index]["cores"],
        "cpu_vendor": r["system_cpu"][data_index]["vendor"],
        "cpu_speed": r["system_cpu"][data_index]["speed_mhz"],
        "has_flash": False,
    }

    # The plugins data can still be null or empty, account for that.
    plugins = r["active_plugins"][data_index] if r["active_plugins"] else None
    if plugins:
        data["has_flash"] = any(
            [True for p in plugins if p["name"] == "Shockwave Flash"]
        )

    return REASON_BROKEN_DATA if None in list(data.values()) else data