Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/rtichoke/_decision_curve_viz_spec_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _decision_curve_v2_spec_from_performance_data(
*,
min_p_threshold: float = 0.0,
max_p_threshold: float = 1.0,
operating_point_dimension: str | None = "probability_threshold",
) -> dict[str, object]:
"""Build canonical static Decision Curve v2 from production quantities."""
missing = _REQUIRED_COLUMNS.difference(performance_data.columns)
Expand Down Expand Up @@ -163,7 +164,7 @@ def _decision_curve_v2_spec_from_performance_data(
}
)

return {
spec = {
"schemaVersion": "2.0",
"type": "decision_curve",
"evaluations": evaluations,
Expand All @@ -178,6 +179,13 @@ def _decision_curve_v2_spec_from_performance_data(
"yAxis": {"label": "Net benefit"},
"references": references,
}
if operating_point_dimension is not None:
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
raise ValueError(
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
)
spec["operatingPoint"] = {"dimension": operating_point_dimension}
return spec


def _decision_curve_times_v2_spec_from_performance_data(
Expand All @@ -186,6 +194,7 @@ def _decision_curve_times_v2_spec_from_performance_data(
*,
min_p_threshold: float = 0.0,
max_p_threshold: float = 1.0,
operating_point_dimension: str | None = "probability_threshold",
) -> dict[str, object]:
"""Build canonical time-dependent Decision Curve v2 from production quantities."""
missing = _REQUIRED_TIMES_COLUMNS.difference(performance_data.columns)
Expand Down Expand Up @@ -372,7 +381,7 @@ def _decision_curve_times_v2_spec_from_performance_data(
}
)

return {
spec = {
"schemaVersion": "2.0",
"type": "decision_curve",
"evaluations": evaluations,
Expand All @@ -387,3 +396,10 @@ def _decision_curve_times_v2_spec_from_performance_data(
"yAxis": {"label": "Net benefit"},
"references": references,
}
if operating_point_dimension is not None:
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
raise ValueError(
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
)
spec["operatingPoint"] = {"dimension": operating_point_dimension}
return spec
20 changes: 18 additions & 2 deletions src/rtichoke/_interventions_avoided_viz_spec_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _interventions_avoided_v2_spec_from_performance_data(
*,
min_p_threshold: float = 0.0,
max_p_threshold: float = 1.0,
operating_point_dimension: str | None = "probability_threshold",
) -> dict[str, object]:
"""Build canonical static Interventions Avoided from production quantities."""
missing = _REQUIRED_COLUMNS.difference(performance_data.columns)
Expand Down Expand Up @@ -168,7 +169,7 @@ def _interventions_avoided_v2_spec_from_performance_data(
}
)

return {
spec = {
"schemaVersion": "2.0",
"type": "interventions_avoided",
"evaluations": evaluations,
Expand All @@ -183,6 +184,13 @@ def _interventions_avoided_v2_spec_from_performance_data(
"yAxis": {"label": "Interventions Avoided (per 100)"},
"references": references,
}
if operating_point_dimension is not None:
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
raise ValueError(
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
)
spec["operatingPoint"] = {"dimension": operating_point_dimension}
return spec


def _interventions_avoided_times_v2_spec_from_performance_data(
Expand All @@ -191,6 +199,7 @@ def _interventions_avoided_times_v2_spec_from_performance_data(
*,
min_p_threshold: float = 0.0,
max_p_threshold: float = 1.0,
operating_point_dimension: str | None = "probability_threshold",
) -> dict[str, object]:
"""Build canonical time-dependent Interventions Avoided v2.

Expand Down Expand Up @@ -363,7 +372,7 @@ def _interventions_avoided_times_v2_spec_from_performance_data(
}
)

return {
spec = {
"schemaVersion": "2.0",
"type": "interventions_avoided",
"evaluations": evaluations,
Expand All @@ -378,3 +387,10 @@ def _interventions_avoided_times_v2_spec_from_performance_data(
"yAxis": {"label": "Interventions Avoided (per 100)"},
"references": references,
}
if operating_point_dimension is not None:
if operating_point_dimension not in {"probability_threshold", "ppcr"}:
raise ValueError(
f"Invalid operating_point_dimension: {operating_point_dimension!r}."
)
spec["operatingPoint"] = {"dimension": operating_point_dimension}
return spec
Loading
Loading