diff --git a/backend/zeno_backend/database/select.py b/backend/zeno_backend/database/select.py index 6ea1c8c3..0c3c1a92 100644 --- a/backend/zeno_backend/database/select.py +++ b/backend/zeno_backend/database/select.py @@ -1155,18 +1155,20 @@ def table_data_paginated( sql.SQL("DESC" if req.sort[1] else "ASC"), ) - db.cur.execute( - sql.SQL("SELECT * {} FROM {} {} {} LIMIT %s OFFSET %s;").format( + final_statement = sql.SQL(" ").join( + [ + sql.SQL("SELECT *"), diff_sql, - sql.Identifier(f"{project}"), + sql.SQL("FROM {}").format(sql.Identifier(project)), filter, order_sql, - ), - [ - req.limit, - req.offset, - ], + sql.SQL("LIMIT {} OFFSET {};").format( + sql.Literal(req.limit), sql.Literal(req.offset) + ), + ] ) + db.cur.execute(final_statement) + if db.cur.description is not None: columns = [desc[0] for desc in db.cur.description] filter_results = db.cur.fetchall() diff --git a/frontend/src/lib/components/instance-views/ComparisonView.svelte b/frontend/src/lib/components/instance-views/ComparisonView.svelte index 63160dea..4f36d682 100644 --- a/frontend/src/lib/components/instance-views/ComparisonView.svelte +++ b/frontend/src/lib/components/instance-views/ComparisonView.svelte @@ -6,7 +6,6 @@ compareSort, comparisonColumn, comparisonModel, - metric, model, project, rowsPerPage, @@ -16,11 +15,10 @@ tagIds } from '$lib/stores'; import { Join, MetadataType, ZenoColumnType, type GroupMetric } from '$lib/zenoapi'; - import { Label } from '@smui/button'; + import { Icon, Label } from '@smui/button'; import { Pagination } from '@smui/data-table'; import IconButton from '@smui/icon-button'; import Select, { Option } from '@smui/select'; - import ComparisonViewTableHeader from './ComparisonViewTableHeader.svelte'; import { viewMap } from './views/viewMap'; export let viewOptions: Record | undefined; @@ -48,6 +46,7 @@ $: if (currentPage > lastPage) { currentPage = lastPage; } + $: modelAResult.then((r) => { if (r !== undefined && r.length > 0) { lastPage = Math.max(Math.ceil(r[0].size / $rowsPerPage) - 1, 0); @@ -64,10 +63,10 @@ // when state changes update current table view $: { currentPage; + $model; $comparisonModel; $comparisonColumn; $rowsPerPage; - $model; $compareSort; $selectionIds; $selectionPredicates; @@ -118,32 +117,40 @@ } function updateTable() { - if (isNaN(start) || isNaN(end) || end <= start) return; - if ($model !== undefined && $comparisonModel !== undefined) { - let predicates = $selectionPredicates; - if (predicates !== undefined && instanceOfFilterPredicate(predicates)) { - predicates = { - join: Join._, - predicates: [predicates] - }; - } - const secureTagIds = $tagIds === undefined ? [] : $tagIds; - const secureSelectionIds = $selectionIds === undefined ? [] : $selectionIds; - const dataIds = [...new Set([...secureTagIds, ...secureSelectionIds])]; - tablePromise = getFilteredTable( - $project.uuid, - $columns, - [$model, $comparisonModel], - $comparisonColumn, - start, - end - start, - $compareSort, - dataIds, - predicates - ); - if (instanceContainer) { - instanceContainer.scrollTop = 0; - } + if ( + isNaN(start) || + isNaN(end) || + end <= start || + $model === undefined || + $comparisonModel === undefined + ) + return; + + let predicates = $selectionPredicates; + if (predicates !== undefined && instanceOfFilterPredicate(predicates)) { + predicates = { + join: Join._, + predicates: [predicates] + }; + } + + const secureTagIds = $tagIds === undefined ? [] : $tagIds; + const secureSelectionIds = $selectionIds === undefined ? [] : $selectionIds; + const dataIds = [...new Set([...secureTagIds, ...secureSelectionIds])]; + tablePromise = getFilteredTable( + $project.uuid, + $columns, + [$model, $comparisonModel], + $comparisonColumn, + start, + end - start, + $compareSort, + dataIds, + predicates + ); + + if (instanceContainer) { + instanceContainer.scrollTop = 0; } } @@ -166,48 +173,53 @@ - -
A: {$model}
-
- - {$metric ? $metric.name + ':' : ''} - - - {#await modelAResult then res} - {#if res !== undefined && res.length > 0} - {#if res[0].metric !== undefined && res[0].metric !== null} - {res[0].metric.toFixed(2)} - {/if} + updateSort($model)}> +
+

A: {$model}

+ {#if sortModel === $model} + + {#if $compareSort[0] && $compareSort[1]} + arrow_drop_up + {:else if $compareSort[0]} + arrow_drop_down {/if} - {/await} - + + {/if}
- -
B: {$comparisonModel}
-
- - {$metric ? $metric.name + ':' : ''} - - - {#await modelBResult then res} - {#if res !== undefined && res.length > 0} - {#if res[0].metric !== undefined && res[0].metric !== null} - {res[0].metric.toFixed(2)} - {/if} + updateSort($comparisonModel)} + > +
+

B: {$comparisonModel}

+ {#if sortModel === $comparisonModel} + + {#if $compareSort[0] && $compareSort[1]} + arrow_drop_up + {:else if $compareSort[0]} + arrow_drop_down {/if} - {/await} - + + {/if}
- updateSort($model)} class="cursor-pointer p-3 min-w-[150px]"> - - - updateSort($comparisonModel)} class="cursor-pointer p-3 min-w-[150px]"> - - - updateSort('')} class="cursor-pointer p-3 min-w-[150px]"> - + updateSort('')}> +
+
+ Difference in + {$comparisonColumn?.name} +
+ {#if sortModel === ''} + + {#if $compareSort[0] && $compareSort[1]} + arrow_drop_up + {:else if $compareSort[0]} + arrow_drop_down + {/if} + + {/if} +
{#await tablePromise then table} @@ -216,6 +228,10 @@ {#if viewMap[$project.view] !== undefined} +

+ {$comparisonColumn?.name}: + {modelValueAndDiff($model, tableContent)} +

+

+ {$comparisonColumn?.name}: + {modelValueAndDiff($comparisonModel, tableContent)} +

{/if} {#if $model !== undefined && $comparisonModel !== undefined} - {modelValueAndDiff($model, tableContent)} - {modelValueAndDiff($comparisonModel, tableContent)} {$comparisonColumn?.dataType === MetadataType.CONTINUOUS ? Number(tableContent['diff']).toFixed(2) diff --git a/frontend/src/lib/components/metadata/MetadataHeader.svelte b/frontend/src/lib/components/metadata/MetadataHeader.svelte index 96f22214..b7601d39 100644 --- a/frontend/src/lib/components/metadata/MetadataHeader.svelte +++ b/frontend/src/lib/components/metadata/MetadataHeader.svelte @@ -63,29 +63,30 @@
{/if}
-{#if $page.url.href.includes('compare') && $metric !== undefined && $metrics.length > 0} -
- Metric + +{#if $page.url.href.includes('compare') && comparisonColumnOptions.length > 0} +
+

Comparison Feature

{/if} -{#if $page.url.href.includes('compare') && comparisonColumnOptions.length > 0} -
-

Comparison Feature

+{#if $page.url.href.includes('compare') && $metric !== undefined && $metrics.length > 0} +
+ Metric