Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance search bar of comparison table #1839

Merged
merged 8 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
12 changes: 11 additions & 1 deletion report-viewer/src/components/ComparisonTableFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="space-y-2">
<div class="flex flex-row flex-wrap items-center gap-x-8 gap-y-2">
<h2>{{ header }}</h2>
<ToolTipComponent direction="bottom" class="min-w-[50%] flex-grow">
<ToolTipComponent direction="left" class="min-w-[50%] flex-grow">
<template #default>
<SearchBarComponent placeholder="Filter/Unhide Comparisons" v-model="searchStringValue" />
</template>
Expand All @@ -11,6 +11,16 @@
Type in the name of a submission to only show comparisons that contain this submission.
</p>
<p class="whitespace-pre text-sm">Fully written out names get unhidden.</p>
<p class="whitespace-pre text-sm">
You can also filter by index by just writing a number or select a specific one by
writing <i>index:number</i>
</p>
<p class="whitespace-pre text-sm">
You can filter for specific similarity percantages by writing a &lt;/&gt;/&lt;=/&gt;=
followed by the percentage. <br />
You can filter for a specific metric, by prefacing the percentage with the three letter
metric name (e.g. <i>avg:>80</i>)
</p>
Kr0nox marked this conversation as resolved.
Show resolved Hide resolved
</template>
</ToolTipComponent>

Expand Down
74 changes: 73 additions & 1 deletion report-viewer/src/components/ComparisonsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,83 @@ function getFilteredComparisons(comparisons: ComparisonListElement[]) {
return comparisons
}

const indexSearches = searches
.filter((s) => /index:[0-9]+/.test(s))
.map((s) => s.substring(6))
.map((s) => parseInt(s))

const metricSearches = searches.filter((s) => /((avg|max):)?([<>])=?[0-9]+%?/.test(s))

return comparisons.filter((c) => {
// name search
const id1 = c.firstSubmissionId.toLowerCase()
const id2 = c.secondSubmissionId.toLowerCase()
return searches.some((s) => id1.includes(s) || id2.includes(s))
if (searches.some((s) => id1.includes(s) || id2.includes(s))) {
return true
}

// index search
if (indexSearches.includes(c.sortingPlace + 1)) {
return true
}
if (searches.some((s) => (c.sortingPlace + 1).toString().includes(s))) {
return true
}

// metric search
const searchPerMetric: Record<MetricType, string[]> = {
[MetricType.AVERAGE]: [],
[MetricType.MAXIMUM]: []
}
metricSearches.forEach((s) => {
const regexResult = /^(?:(avg|max):)?((?:[<>])=?[0-9]+%?$)/.exec(s)
if (regexResult) {
const metricName = regexResult[1]
let metric = MetricType.AVERAGE
for (const m of [MetricType.AVERAGE, MetricType.MAXIMUM]) {
if (metricToolTips[m].shortName.toLowerCase() == metricName) {
metric = m
break
}
}
searchPerMetric[metric].push(regexResult[2])
} else {
searchPerMetric[MetricType.AVERAGE].push(s)
searchPerMetric[MetricType.MAXIMUM].push(s)
}
})
for (const metric of [MetricType.AVERAGE, MetricType.MAXIMUM]) {
for (const search of searchPerMetric[metric]) {
const regexResult = /((?:[<>])=?)([0-9]+)%?/.exec(search)!
const operator = regexResult[1]
const value = parseInt(regexResult[2])
if (evaluateMetricComparison(c.similarities[metric] * 100, operator, value)) {
return true
}
}
}

return false
})

function evaluateMetricComparison(
comparisonMetric: number,
operator: string,
checkValue: number
) {
switch (operator) {
case '>':
return comparisonMetric > checkValue
case '<':
return comparisonMetric < checkValue
case '>=':
return comparisonMetric >= checkValue
case '<=':
return comparisonMetric <= checkValue
default:
return false
}
}
}

function getSortedComparisons(comparisons: ComparisonListElement[]) {
Expand Down
4 changes: 1 addition & 3 deletions report-viewer/tests/e2e/Comparison.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ test('Test comparison table and comparsion view', async ({ page }) => {

await uploadFile('progpedia-report.zip', page)

const comparisonContainer = page.getByText(
'Top Comparisons: Type in the name of a submission to only show comparisons that contain this submission. Fully written out names get unhidden.Hide AllSort By'
)
const comparisonContainer = page.getByText('Hide AllSort By')

// check for elements in average similarity table
await page.getByPlaceholder('Filter/Unhide Comparisons').fill('Purple')
Expand Down