|
8 | 8 | from mlip_testing.analysis.utils.utils import calc_ranks, calc_scores |
9 | 9 |
|
10 | 10 |
|
11 | | -def register_table_callbacks(table_id) -> None: |
| 11 | +def register_summary_table_callbacks() -> None: |
| 12 | + """Register callbacks to update summary table.""" |
| 13 | + |
| 14 | + @callback( |
| 15 | + Output("summary-table", "data"), |
| 16 | + Input("all-tabs", "value"), |
| 17 | + Input("summary-table-weight-store", "data"), |
| 18 | + State("summary-table-scores-store", "data"), |
| 19 | + State("summary-table", "data"), |
| 20 | + prevent_initial_call=False, |
| 21 | + ) |
| 22 | + def update_summary_table( |
| 23 | + tabs_value: str, |
| 24 | + stored_weights: dict[str, float], |
| 25 | + stored_scores: dict[str, list[float]], |
| 26 | + summary_data: list[dict], |
| 27 | + ) -> list[dict]: |
| 28 | + """ |
| 29 | + Update summary table when scores change. |
| 30 | +
|
| 31 | + Parameters |
| 32 | + ---------- |
| 33 | + tabs_value |
| 34 | + Value of selected tab. Parameter unused, but required to register Input. |
| 35 | + stored_weights |
| 36 | + Stored summary weights dictionary. |
| 37 | + stored_scores |
| 38 | + Stored scores for table scores. |
| 39 | + summary_data |
| 40 | + Data from summary table to be updated. |
| 41 | +
|
| 42 | + Returns |
| 43 | + ------- |
| 44 | + list[dict] |
| 45 | + Updated summary table data. |
| 46 | + """ |
| 47 | + # Update table from stored scores |
| 48 | + if stored_scores: |
| 49 | + for key, values in stored_scores.items(): |
| 50 | + for row, value in zip(summary_data, values, strict=True): |
| 51 | + row[key] = value |
| 52 | + |
| 53 | + # Update table contents |
| 54 | + summary_data = calc_scores(summary_data, stored_weights) |
| 55 | + return calc_ranks(summary_data) |
| 56 | + |
| 57 | + |
| 58 | +def register_tab_table_callbacks(table_id) -> None: |
12 | 59 | """ |
13 | 60 | Register callback to update table scores/rankings when stored values change. |
14 | 61 |
|
@@ -77,49 +124,6 @@ def update_scores_store( |
77 | 124 | # Update scores store |
78 | 125 | return {table_id.removesuffix("-table"): [row["Score"] for row in table_data]} |
79 | 126 |
|
80 | | - @callback( |
81 | | - Output("summary-table", "data"), |
82 | | - Input("all-tabs", "value"), |
83 | | - Input("summary-table-weight-store", "data"), |
84 | | - State("summary-table-scores-store", "data"), |
85 | | - State("summary-table", "data"), |
86 | | - prevent_initial_call=False, |
87 | | - ) |
88 | | - def update_summary_table( |
89 | | - tabs_value: str, |
90 | | - stored_weights: dict[str, float], |
91 | | - stored_scores: dict[str, list[float]], |
92 | | - summary_data: list[dict], |
93 | | - ) -> list[dict]: |
94 | | - """ |
95 | | - Update summary table when scores change. |
96 | | -
|
97 | | - Parameters |
98 | | - ---------- |
99 | | - tabs_value |
100 | | - Value of selected tab. Parameter unused, but required to register Input. |
101 | | - stored_weights |
102 | | - Stored summary weights dictionary. |
103 | | - stored_scores |
104 | | - Stored scores for table scores. |
105 | | - summary_data |
106 | | - Data from summary table to be updated. |
107 | | -
|
108 | | - Returns |
109 | | - ------- |
110 | | - list[dict] |
111 | | - Updated summary table data. |
112 | | - """ |
113 | | - # Update table from stored scores |
114 | | - if stored_scores: |
115 | | - for key, values in stored_scores.items(): |
116 | | - for row, value in zip(summary_data, values, strict=True): |
117 | | - row[key] = value |
118 | | - |
119 | | - # Update table contents |
120 | | - summary_data = calc_scores(summary_data, stored_weights) |
121 | | - return calc_ranks(summary_data) |
122 | | - |
123 | 127 |
|
124 | 128 | def register_weight_callbacks(input_id: str, table_id: str, column: str) -> None: |
125 | 129 | """ |
|
0 commit comments