Ejemplo n.º 1
0
def test_summary_values_data_frame():
    """Test for the correct layout and size of the summary values data frame."""
    summary_values = _summary_values(pd.DataFrame(__TEST_DATA))

    assert list(
        summary_values.columns == ["summary_key", "batch", "date", "key1", "key2"]
    )
    assert len(summary_values) == len(__TEST_DATA["simulation"])
    assert set(summary_values["batch"]) == set(__TEST_DATA["batch"])
    assert set(summary_values["date"]) == {
        pd.Timestamp(date) for date in __TEST_DATA["date"]
    }
Ejemplo n.º 2
0
def test_well_plot(app, dash_duo, mocker, caplog):
    test_data = {
        "realization":
        range(12),
        "simulation":
        range(12),
        "batch": [0] * 6 + [1] * 6,
        "date": [
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
        ],
        "WOPR:OP1":
        range(1, 13),
        "WOPRT:OP1":
        range(10, 130, 10),
    }

    mocker.patch(
        "everviz.plugins.summary_plot.wells_plot.get_data",
        return_value=_summary_values(pd.DataFrame(test_data)),
    )

    plugin = WellsPlot(app, "values")
    app.layout = plugin.layout
    dash_duo.start_server(app)

    # Tests warning label not there
    dash_duo.wait_for_contains_text(f"#{plugin.label_id}", "")

    dash_duo.clear_input("#{}".format(plugin.dropdown_key))
    dash_duo.select_dcc_dropdown("#{}".format(plugin.dropdown_key), "WOPR:OP1")
    result = dash_duo.find_element("#{}".format(
        plugin.dropdown_key)).text.split()[0]
    dash_duo.find_element("#{} label:nth-child({})".format(
        plugin.radio_statistics, 2)).click()

    # Tests warning label is there
    dash_duo.wait_for_contains_text(f"#{plugin.label_id}",
                                    "Statistics are calculated")

    for record in caplog.records:
        assert record.levelname != "ERROR"
Ejemplo n.º 3
0
def test_summary_statistics_content():
    """Test for the correct content of the summary statistics data frame."""
    summary_values = _summary_values(pd.DataFrame(__TEST_DATA))
    summary_statistics = calculate_statistics(summary_values, ["key1", "key2"])

    mean = []
    p10 = []
    p90 = []
    min_value = []
    max_value = []
    min_realization = []
    max_realization = []
    for key in ["key1", "key2"]:
        zipped = list(
            zip(
                __TEST_DATA["batch"],
                __TEST_DATA["date"],
                __TEST_DATA[key],
                __TEST_DATA["realization"],
            ))
        for batch in [0, 1]:
            for date in [
                    datetime(2000, 1, 1),
                    datetime(2000, 2, 1),
                    datetime(2000, 3, 1),
            ]:
                values = [
                    v for b, d, v, _ in zipped if batch == b and date == d
                ]
                realizations = [
                    r for b, d, _, r in zipped if batch == b and date == d
                ]
                mean.append(np.mean(values))
                p10.append(np.quantile(values, q=0.1))
                p90.append(np.quantile(values, q=0.9))
                min_value.append(np.min(values))
                max_value.append(np.max(values))
                min_realization.append(realizations[np.argmin(values)])
                max_realization.append(realizations[np.argmax(values)])

    assert summary_statistics["mean"].to_list() == mean
    assert summary_statistics["P10"].to_list() == p10
    assert summary_statistics["P90"].to_list() == p90
    assert summary_statistics["min_value"].to_list() == min_value
    assert summary_statistics["max_value"].to_list() == max_value
    assert summary_statistics["min_realization"].to_list() == min_realization
    assert summary_statistics["max_realization"].to_list() == max_realization
Ejemplo n.º 4
0
def test_summary_statistics_data_frame():
    """Test for the correct layout and size of the summary statistics data frame"""
    summary_values = _summary_values(pd.DataFrame(__TEST_DATA))
    summary_statistics = calculate_statistics(summary_values)

    assert list(summary_statistics.columns) == [
        "summary_key",
        "batch",
        "date",
        "mean",
        "P10",
        "P90",
    ]
    assert len(summary_statistics) == 2 * 3 * 2  # #batches * #dates * #keys
    assert set(summary_statistics["summary_key"]) == set(["key1", "key2"])
    assert set(summary_statistics["batch"]) == set(__TEST_DATA["batch"])
    assert set(summary_statistics["date"]) == {
        pd.Timestamp(date) for date in __TEST_DATA["date"]
    }
Ejemplo n.º 5
0
def test_summary_statistics_content():
    """Test for the correct content of the summary statistics data frame."""
    summary_values = _summary_values(pd.DataFrame(__TEST_DATA))
    summary_statistics = calculate_statistics(summary_values)

    mean = []
    p10 = []
    p90 = []
    for key in ["key1", "key2"]:
        zipped = list(zip(__TEST_DATA["batch"], __TEST_DATA["date"], __TEST_DATA[key]))
        for batch in [0, 1]:
            for date in [
                datetime(2000, 1, 1),
                datetime(2000, 2, 1),
                datetime(2000, 3, 1),
            ]:
                values = [v for b, d, v in zipped if batch == b and date == d]
                mean.append(np.mean(values))
                p10.append(np.quantile(values, q=0.1))
                p90.append(np.quantile(values, q=0.9))

    assert summary_statistics["mean"].to_list() == mean
    assert summary_statistics["P10"].to_list() == p10
    assert summary_statistics["P90"].to_list() == p90
def test_summary_plot_callback(app, dash_duo, mocker, caplog):
    test_data = {
        "realization":
        range(12),
        "simulation":
        range(12),
        "batch": [0] * 6 + [1] * 6,
        "date": [
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
            datetime(2000, 1, 1),
            datetime(2000, 2, 1),
            datetime(2000, 3, 1),
        ],
        "key1":
        range(1, 13),
        "key2":
        range(10, 130, 10),
    }

    mocker.patch(
        "everviz.plugins.summary_plot.summary_plot.get_data",
        return_value=_summary_values(pd.DataFrame(test_data)),
    )

    plugin = SummaryPlot(app, "values")
    app.layout = plugin.layout
    dash_duo.start_server(app)

    # Test statistics plot.
    dash_duo.find_element("#{} label:nth-child({})".format(plugin.radio_id,
                                                           1)).click()
    dash_duo.select_dcc_dropdown("#{}".format(plugin.key_dropdown_id), "key1")

    # Test data plot.
    dash_duo.find_element("#{} label:nth-child({})".format(plugin.radio_id,
                                                           2)).click()

    # Test filtering realizations.
    dash_duo.find_element("#{} label:nth-child({})".format(
        plugin.realization_filter_check_id, 1)).click()
    dash_duo.find_element("#{}".format(
        plugin.realization_filter_input_id)).send_keys("1, 3")

    # Clear the axes dropdowns, which should not cause an error.
    #
    # NOTE: if you try to do this before the previous click action on a radio
    # button, you get an error, because the the dropdown stays open and overlaps
    # with the radio buttons.
    dash_duo.clear_input("#{}".format(plugin.xaxis_dropdown_id))
    dash_duo.clear_input("#{}".format(plugin.key_dropdown_id))

    for record in caplog.records:
        assert record.levelname != "ERROR"
Ejemplo n.º 7
0
 def mock_get_data(data_type):
     if data_type == "values":
         result = _summary_values(pd.DataFrame(test_data))
     else:
         result = _summary_statistics(pd.DataFrame(test_data))
     return result