Skip to content

Commit

Permalink
feat: add overall slice option to charts (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
cabreraalex authored Sep 5, 2023
1 parent a3149ff commit 04a06b3
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
66 changes: 65 additions & 1 deletion backend/zeno_backend/processing/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,25 @@ def xyc_data(chart: Chart, project: str) -> str:
elements: list[dict[str, Any]] = []
if not (isinstance(chart.parameters, XCParameters)):
return json.dumps({"table": elements})

all_metrics = metrics(project)
selected_metric = next(
(x for x in all_metrics if x.id == chart.parameters.metric),
Metric(id=-1, name="count", type="count", columns=[]),
)

selected_slices = slices(project, chart.parameters.slices)
if -1 in chart.parameters.slices:
selected_slices = selected_slices + [
Slice(
id=-1,
slice_name="All instances",
filter_predicates=FilterPredicateGroup(
predicates=[], join=Join.OMITTED
),
)
]

selected_models = chart.parameters.models
for current_slice in selected_slices:
for model in selected_models:
Expand Down Expand Up @@ -82,6 +95,16 @@ def table_data(chart: Chart, project: str) -> str:
)
)
selected_slices = slices(project, params.slices)
if -1 in params.slices:
selected_slices = selected_slices + [
Slice(
id=-1,
slice_name="All instances",
filter_predicates=FilterPredicateGroup(
predicates=[], join=Join.OMITTED
),
)
]
selected_models = params.models

for current_metric in selected_metrics:
Expand Down Expand Up @@ -129,6 +152,16 @@ def beeswarm_data(chart: Chart, project: str) -> str:
)
)
selected_slices = slices(project, params.slices)
if -1 in params.slices:
selected_slices = selected_slices + [
Slice(
id=-1,
slice_name="All instances",
filter_predicates=FilterPredicateGroup(
predicates=[], join=Join.OMITTED
),
)
]
selected_models = params.models

for current_metric in selected_metrics:
Expand Down Expand Up @@ -175,6 +208,16 @@ def radar_data(chart: Chart, project: str) -> str:
)
)
selected_slices = slices(project, params.slices)
if -1 in params.slices:
selected_slices = selected_slices + [
Slice(
id=-1,
slice_name="All instances",
filter_predicates=FilterPredicateGroup(
predicates=[], join=Join.OMITTED
),
)
]
selected_models = params.models

for current_metric in selected_metrics:
Expand Down Expand Up @@ -221,12 +264,33 @@ def heatmap_data(chart: Chart, project: str) -> str:
)
x_slice = params.x_channel == SlicesOrModels.SLICES
y_slice = params.y_channel == SlicesOrModels.SLICES
selected_x: list[Slice] | list[str] = (
selected_x = (
slices(project, params.x_values) if x_slice else params.x_values # type: ignore
)
if x_slice and -1 in params.x_values:
selected_x = selected_x + [
Slice(
id=-1,
slice_name="All instances",
filter_predicates=FilterPredicateGroup(
predicates=[], join=Join.OMITTED
),
)
]

selected_y = (
slices(project, params.y_values) if y_slice else params.y_values # type: ignore
)
if y_slice and -1 in params.y_values:
selected_y = selected_y + [
Slice(
id=-1,
slice_name="All instances",
filter_predicates=FilterPredicateGroup(
predicates=[], join=Join.OMITTED
),
)
]

for current_x in selected_x:
for current_y in selected_y:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let options: { value: number; label: string }[] = [];
let value = 0;
options.push({ value: -1, label: 'All instances' });
$slices.forEach((s) => {
options.push({ value: s.id, label: s.sliceName });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
let options: { value: number; label: string }[] = [];
let value: number[] = [];
options.push({ value: -1, label: 'All instances' });
// initial options & values
$slices.forEach((s) => {
options.push({ value: s.id, label: s.sliceName });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
<!-- y cell -->
<Cell>
{#if parameters.yChannel === SlicesOrModels.SLICES}
<SliceDetailsContainer sli={$slices.find((sli) => sli.id === row)} />
{#if row === -1}
<p>All instances</p>
{:else}
<SliceDetailsContainer sli={$slices.find((sli) => sli.id === row)} />
{/if}
{:else}
{row}
{/if}
Expand Down

0 comments on commit 04a06b3

Please sign in to comment.