def get_causal_page()

in src/responsibleai/rai_analyse/_score_card/common_components.py [0:0]


def get_causal_page(data):
    left_elem = [
        div(
            p(
                "ausal analysis answers real-world what-if questions "
                "about how changing specific treatments would impact outcomes."
            )
        )
    ]

    left_container = div(left_elem, _class="left")

    main_elems = []

    def get_causal_dot_plot(center, em, ep):
        png_base64 = get_dot_plot(center, em, ep)
        return div(
            img(_src="data:image/png;base64,{}".format(png_base64)), _class="image_div"
        )

    def get_table_row(data):
        table_row_elems = []
        for v in data:
            table_row_elems.append(td(v, _class="cell"))
        return tr(table_row_elems, _class="row")

    def get_table(data):
        horizontal_headings = [
            "Index",
            "Current<br>Value",
            "Recommended<br>Treatment",
            "Effect<br>Estimate",
        ]
        headings_td = [td(x, _class="header_cell") for x in horizontal_headings]
        headings = thead(tr(headings_td, _class="row"), _class="table-head")

        rows_elems = []
        for elem in data:
            rows_elems.append(get_table_row(elem))

        body = tbody(rows_elems, _class="table-body")

        return table(headings, body, _class="table")

    for f in data["global_effect"].values():
        main_elems.append(
            div(
                h3(f["feature"]),
                p(
                    'On average, increasing "{}" by 1 unit increases the outcome by {}'.format(
                        f["feature"], round(f["point"], 3)
                    )
                ),
                get_causal_dot_plot(
                    f["point"], f["ci_upper"] - f["point"], f["point"] - f["ci_lower"]
                ),
                _class="nobreak_div",
            )
        )

        main_elems.append(
            h3(
                'Top data points responding the most to treatment on "{}":'.format(
                    f["feature"]
                )
            )
        )
        main_elems.append(
            p(
                "Datapoints with the largest estimated causal responses to treatment feature: "
                '"{}"'.format(f["feature"])
            )
        )

        def causal_policies_map_to_table(policy):
            ct = policy["Current treatment"]
            et = policy["Effect of treatment"]

            ct = round(ct, 2) if isinstance(ct, (int, float)) else ct
            et = round(et, 2) if isinstance(et, (int, float)) else et

            return [
                policy["index"],
                ct,
                policy["Treatment"],
                et,
            ]

        main_elems.append(
            get_table(
                list(
                    map(
                        causal_policies_map_to_table,
                        data["top_local_policies"][f["feature"]],
                    )
                )
            )
        )

    main_container = div(main_elems, _class="main")

    return div(
        div(
            get_page_divider("Causal Inference"),
            left_container,
            main_container,
            _class="nobreak_div",
        ),
        _class="container nobreak_div",
    )