Skip to content

Commit 46c1ec6

Browse files
authored
Merge pull request #403 from uriahf/activate-operating-point-controls-4708834464914728002
Activate browser operating-point controls
2 parents a8583a4 + c3e9208 commit 46c1ec6

11 files changed

Lines changed: 326 additions & 65 deletions

‎src/rtichoke/_decision_curve_viz_spec_v2.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def _decision_curve_v2_spec_from_performance_data(
3434
*,
3535
min_p_threshold: float = 0.0,
3636
max_p_threshold: float = 1.0,
37+
operating_point_dimension: str | None = "probability_threshold",
3738
) -> dict[str, object]:
3839
"""Build canonical static Decision Curve v2 from production quantities."""
3940
missing = _REQUIRED_COLUMNS.difference(performance_data.columns)
@@ -163,7 +164,7 @@ def _decision_curve_v2_spec_from_performance_data(
163164
}
164165
)
165166

166-
return {
167+
spec = {
167168
"schemaVersion": "2.0",
168169
"type": "decision_curve",
169170
"evaluations": evaluations,
@@ -178,6 +179,13 @@ def _decision_curve_v2_spec_from_performance_data(
178179
"yAxis": {"label": "Net benefit"},
179180
"references": references,
180181
}
182+
if operating_point_dimension is not None:
183+
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
184+
raise ValueError(
185+
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
186+
)
187+
spec["operatingPoint"] = {"dimension": operating_point_dimension}
188+
return spec
181189

182190

183191
def _decision_curve_times_v2_spec_from_performance_data(
@@ -186,6 +194,7 @@ def _decision_curve_times_v2_spec_from_performance_data(
186194
*,
187195
min_p_threshold: float = 0.0,
188196
max_p_threshold: float = 1.0,
197+
operating_point_dimension: str | None = "probability_threshold",
189198
) -> dict[str, object]:
190199
"""Build canonical time-dependent Decision Curve v2 from production quantities."""
191200
missing = _REQUIRED_TIMES_COLUMNS.difference(performance_data.columns)
@@ -372,7 +381,7 @@ def _decision_curve_times_v2_spec_from_performance_data(
372381
}
373382
)
374383

375-
return {
384+
spec = {
376385
"schemaVersion": "2.0",
377386
"type": "decision_curve",
378387
"evaluations": evaluations,
@@ -387,3 +396,10 @@ def _decision_curve_times_v2_spec_from_performance_data(
387396
"yAxis": {"label": "Net benefit"},
388397
"references": references,
389398
}
399+
if operating_point_dimension is not None:
400+
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
401+
raise ValueError(
402+
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
403+
)
404+
spec["operatingPoint"] = {"dimension": operating_point_dimension}
405+
return spec

‎src/rtichoke/_interventions_avoided_viz_spec_v2.py‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def _interventions_avoided_v2_spec_from_performance_data(
3434
*,
3535
min_p_threshold: float = 0.0,
3636
max_p_threshold: float = 1.0,
37+
operating_point_dimension: str | None = "probability_threshold",
3738
) -> dict[str, object]:
3839
"""Build canonical static Interventions Avoided from production quantities."""
3940
missing = _REQUIRED_COLUMNS.difference(performance_data.columns)
@@ -168,7 +169,7 @@ def _interventions_avoided_v2_spec_from_performance_data(
168169
}
169170
)
170171

171-
return {
172+
spec = {
172173
"schemaVersion": "2.0",
173174
"type": "interventions_avoided",
174175
"evaluations": evaluations,
@@ -183,6 +184,13 @@ def _interventions_avoided_v2_spec_from_performance_data(
183184
"yAxis": {"label": "Interventions Avoided (per 100)"},
184185
"references": references,
185186
}
187+
if operating_point_dimension is not None:
188+
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
189+
raise ValueError(
190+
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
191+
)
192+
spec["operatingPoint"] = {"dimension": operating_point_dimension}
193+
return spec
186194

187195

188196
def _interventions_avoided_times_v2_spec_from_performance_data(
@@ -191,6 +199,7 @@ def _interventions_avoided_times_v2_spec_from_performance_data(
191199
*,
192200
min_p_threshold: float = 0.0,
193201
max_p_threshold: float = 1.0,
202+
operating_point_dimension: str | None = "probability_threshold",
194203
) -> dict[str, object]:
195204
"""Build canonical time-dependent Interventions Avoided v2.
196205
@@ -363,7 +372,7 @@ def _interventions_avoided_times_v2_spec_from_performance_data(
363372
}
364373
)
365374

366-
return {
375+
spec = {
367376
"schemaVersion": "2.0",
368377
"type": "interventions_avoided",
369378
"evaluations": evaluations,
@@ -378,3 +387,10 @@ def _interventions_avoided_times_v2_spec_from_performance_data(
378387
"yAxis": {"label": "Interventions Avoided (per 100)"},
379388
"references": references,
380389
}
390+
if operating_point_dimension is not None:
391+
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
392+
raise ValueError(
393+
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
394+
)
395+
spec["operatingPoint"] = {"dimension": operating_point_dimension}
396+
return spec

0 commit comments

Comments
 (0)