示例#1
0
def test_prepare_data():
    """Test prepare_data function on sample data."""
    data = {
        "browser_arch": "x86",
        "os_name": "Windows_NT",
        "os_version": "6.1",
        "memory_mb": 4286,
        "is_wow64": False,
        "gfx0_vendor_id": "0xfeee",
        "gfx0_device_id": "0xd1d1",
        "screen_width": 1280,
        "screen_height": 1024,
        "cpu_cores": 2,
        "cpu_vendor": "SomeCpuVendor",
        "cpu_speed": 3261,
        "has_flash": True,
    }

    prepared_data = summarize_json.prepare_data(data, device_map)
    assert (prepared_data["browser_arch"] == "x86"
            ), "The browser architecture must be correct."
    assert prepared_data[
        "cpu_cores"] == 2, "The number of CPU cores must be correct."
    assert (
        prepared_data["cpu_speed"] == 3.3
    ), "The CPU speed must be in GHz and correctly rounded to 1 decimal."
    assert (prepared_data["cpu_vendor"] == "SomeCpuVendor"
            ), "The CPU vendor must be correct."
    assert (prepared_data["cpu_cores_speed"] == "2_3.3"
            ), "The CPU cores and speed must be correctly merged together."
    assert (
        prepared_data["gfx0_vendor_name"] == "Other"
    ), "The GPU vendor name must be correctly converted from the vendor id."
    assert (
        prepared_data["gfx0_model"] == "family-chipset"
    ), "The GPU family and chipset must be correctly derived from vendor and device ids."
    assert (prepared_data["resolution"] == "1280x1024"
            ), "The screen resolution must be correctly concatenated."
    assert prepared_data[
        "memory_gb"] == 4, "The RAM memory must be converted to GB."
    assert (prepared_data["os"] == "Windows_NT-6.1"
            ), "The OS string must contain the OS name and version."
    assert (prepared_data["os_arch"] == "x86"
            ), "The OS architecture must be correctly inferred."
    assert (prepared_data["has_flash"] is
            True), "The flash plugin must be correctly reported."
def test_prepare_data():
    """Test prepare_data function on sample data."""
    data = {
        'browser_arch': 'x86',
        'os_name': 'Windows_NT',
        'os_version': '6.1',
        'memory_mb': 4286,
        'is_wow64': False,
        'gfx0_vendor_id': '0xfeee',
        'gfx0_device_id': '0xd1d1',
        'screen_width': 1280,
        'screen_height': 1024,
        'cpu_cores': 2,
        'cpu_vendor': 'SomeCpuVendor',
        'cpu_speed': 3261,
        'has_flash': True
    }

    prepared_data = summarize_json.prepare_data(data, device_map)
    assert prepared_data["browser_arch"] == "x86", (
        "The browser architecture must be correct.")
    assert prepared_data["cpu_cores"] == 2, (
        "The number of CPU cores must be correct.")
    assert prepared_data["cpu_speed"] == 3.3, (
        "The CPU speed must be in GHz and correctly rounded to 1 decimal.")
    assert prepared_data["cpu_vendor"] == "SomeCpuVendor", (
        "The CPU vendor must be correct.")
    assert prepared_data["cpu_cores_speed"] == "2_3.3", (
        "The CPU cores and speed must be correctly merged together.")
    assert prepared_data["gfx0_vendor_name"] == "Other", (
        "The GPU vendor name must be correctly converted from the vendor id.")
    assert prepared_data["gfx0_model"] == "family-chipset", (
        "The GPU family and chipset must be correctly derived from vendor and device ids."
    )
    assert prepared_data["resolution"] == "1280x1024", (
        "The screen resolution must be correctly concatenated.")
    assert prepared_data["memory_gb"] == 4, (
        "The RAM memory must be converted to GB.")
    assert prepared_data["os"] == "Windows_NT-6.1", (
        "The OS string must contain the OS name and version.")
    assert prepared_data["os_arch"] == "x86", (
        "The OS architecture must be correctly inferred.")
    assert prepared_data["has_flash"] is True, (
        "The flash plugin must be correctly reported.")
示例#3
0
def test_aggregate_data():
    """Test aggregate_data function on sample data."""
    raw_data = [
        {
            "browser_arch": "x86",
            "os_name": "Windows_NT",
            "os_version": "6.1",
            "memory_mb": 4286,
            "is_wow64": False,
            "gfx0_vendor_id": "0xfeee",
            "gfx0_device_id": "0xd1d1",
            "screen_width": 1280,
            "screen_height": 1024,
            "cpu_cores": 2,
            "cpu_vendor": "SomeCpuVendor",
            "cpu_speed": 3261,
            "has_flash": True,
        },
        {
            "browser_arch": "x86",
            "os_name": "Windows_NT",
            "os_version": "6.1",
            "memory_mb": 4286,
            "is_wow64": False,
            "gfx0_vendor_id": "0xfeee",
            "gfx0_device_id": "0xd1d1",
            "screen_width": 1280,
            "screen_height": 1024,
            "cpu_cores": 2,
            "cpu_vendor": "SomeCpuVendor",
            "cpu_speed": 3261,
            "has_flash": True,
        },
        {
            "browser_arch": "x86-64",
            "os_name": "Darwin",
            "os_version": "15.3",
            "memory_mb": 8322,
            "is_wow64": False,
            "gfx0_vendor_id": "0xfeee",
            "gfx0_device_id": "0xd1d2",
            "screen_width": 1320,
            "screen_height": 798,
            "cpu_cores": 4,
            "cpu_vendor": "SomeCpuVendor",
            "cpu_speed": 4211,
            "has_flash": True,
        },
    ]

    spark = SparkSession.builder.appName(
        "hardware_report_dashboard").getOrCreate()

    # Create an rdd with the pepared data, then aggregate.
    data_rdd = spark.sparkContext.parallelize(
        [summarize_json.prepare_data(d, device_map) for d in raw_data])
    agg_data = summarize_json.aggregate_data(data_rdd)

    assert (
        agg_data[("os_arch",
                  "x86")] == 2), "Two 'x86' OS architectures must be reported."
    assert (agg_data[(
        "os_arch",
        "x86-64")] == 1), "One 'x86-64' OS architecture must be reported."
    assert (agg_data[("has_flash", True)] == 3
            ), "All the entries had the flash plugin, so this must be 3."
def test_aggregate_data():
    """Test aggregate_data function on sample data."""
    raw_data = [
        {
            'browser_arch': 'x86',
            'os_name': 'Windows_NT',
            'os_version': '6.1',
            'memory_mb': 4286,
            'is_wow64': False,
            'gfx0_vendor_id': '0xfeee',
            'gfx0_device_id': '0xd1d1',
            'screen_width': 1280,
            'screen_height': 1024,
            'cpu_cores': 2,
            'cpu_vendor': 'SomeCpuVendor',
            'cpu_speed': 3261,
            'has_flash': True
        },
        {
            'browser_arch': 'x86',
            'os_name': 'Windows_NT',
            'os_version': '6.1',
            'memory_mb': 4286,
            'is_wow64': False,
            'gfx0_vendor_id': '0xfeee',
            'gfx0_device_id': '0xd1d1',
            'screen_width': 1280,
            'screen_height': 1024,
            'cpu_cores': 2,
            'cpu_vendor': 'SomeCpuVendor',
            'cpu_speed': 3261,
            'has_flash': True
        },
        {
            'browser_arch': 'x86-64',
            'os_name': 'Darwin',
            'os_version': '15.3',
            'memory_mb': 8322,
            'is_wow64': False,
            'gfx0_vendor_id': '0xfeee',
            'gfx0_device_id': '0xd1d2',
            'screen_width': 1320,
            'screen_height': 798,
            'cpu_cores': 4,
            'cpu_vendor': 'SomeCpuVendor',
            'cpu_speed': 4211,
            'has_flash': True
        },
    ]

    spark = (SparkSession
             .builder
             .appName("hardware_report_dashboard")
             .getOrCreate())

    # Create an rdd with the pepared data, then aggregate.
    data_rdd = spark.sparkContext.parallelize(
               [summarize_json.prepare_data(d, device_map) for d in raw_data])
    agg_data = summarize_json.aggregate_data(data_rdd)

    assert agg_data[('os_arch', 'x86')] == 2, (
               "Two 'x86' OS architectures must be reported.")
    assert agg_data[('os_arch', 'x86-64')] == 1, (
               "One 'x86-64' OS architecture must be reported.")
    assert agg_data[('has_flash', True)] == 3, (
               "All the entries had the flash plugin, so this must be 3.")