Skip to content

Commit

Permalink
Merge pull request #11 from danyoungday/filter-count
Browse files Browse the repository at this point in the history
Added policy counter and reset button, fixed a bug with baseline outcome display
  • Loading branch information
danyoungday authored Sep 11, 2024
2 parents 521a8f2 + fb57f8e commit fe18a41
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
34 changes: 31 additions & 3 deletions app/components/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,21 @@ def create_filter_div(self):
dcc.Store(id="metrics-store")
],
),
className="w-100 mb-5"
className="w-100"
),
html.Div(
className="d-flex flex-row mb-2",
children=[
dbc.Button(
"0 Policies Selected",
id="cand-counter",
disabled=True,
outline=True,
className="me-1",
style={"width": "200px"} # TODO: We hard-code the width here because of text size
),
dbc.Button("Reset Filters", id="reset-button")
]
),
html.Div(
dbc.Accordion(
Expand All @@ -169,12 +183,14 @@ def register_callbacks(self, app):
"""
@app.callback(
[Output(f"{metric_id}-slider", param) for metric_id in self.metric_ids for param in self.updated_params],
Input("metrics-store", "data")
Input("metrics-store", "data"),
Input("reset-button", "n_clicks")
)
def update_filter_sliders(metrics_jsonl: list[dict[str, list]]) -> list:
def update_filter_sliders(metrics_jsonl: list[dict[str, list]], _) -> list:
"""
Update the filter slider min/max/value/marks based on the incoming metrics data. The output of this function
is a list of the updated parameters for each slider concatenated.
This also happens whenever we click the reset button.
"""
metrics_df = pd.DataFrame(metrics_jsonl)
total_output = []
Expand Down Expand Up @@ -205,3 +221,15 @@ def filter_parcoords_figure(metrics_json: dict[str, list], *metric_ranges) -> go
Filters parallel coordinates figure based on the metric ranges from the sliders.
"""
return self.plot_parallel_coordinates_line(metrics_json, metric_ranges)

@app.callback(
Output("cand-counter", "children"),
State("metrics-store", "data"),
[Input(f"{metric_id}-slider", "value") for metric_id in self.metric_ids]
)
def count_selected_cands(metrics_json: dict[str, list], *metric_ranges) -> str:
"""
Counts the number of selected candidates based on the metric ranges from the sliders.
"""
metrics_df = filter_metrics_json(metrics_json, metric_ranges)
return f"{len(metrics_df) - 1} Policies Selected"
4 changes: 2 additions & 2 deletions app/components/outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def update_outcomes_plots(metrics_json, outcome1, outcome2, outcomes_jsonl, *met
Updates outcome plot when specific outcome is selected or context scatter point is clicked.
"""
metrics_df = filter_metrics_json(metrics_json, metric_ranges)
cand_idxs = list(metrics_df.index)
cand_idxs = list(metrics_df.index)[:-1] # So we don't include the baseline

fig1 = self.plot_outcome_over_time(outcome1, outcomes_jsonl, cand_idxs)
fig2 = self.plot_outcome_over_time(outcome2, outcomes_jsonl, cand_idxs)
Expand All @@ -223,5 +223,5 @@ def update_cand_link_select(metrics_json: dict[str, list],
Updates the available candidates in the link dropdown based on metric ranges.
"""
metrics_df = filter_metrics_json(metrics_json, metric_ranges)
cand_idxs = list(metrics_df.index)
cand_idxs = list(metrics_df.index)[:-1] # So we don't include the baseline
return cand_idxs

0 comments on commit fe18a41

Please sign in to comment.