Skip to content

Commit 079f496

Browse files
committed
chore: format numeric values
1 parent 2a84182 commit 079f496

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/components/LoCha/LoChaReason.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ const props = defineProps<{
66
reason: Reason
77
}>()
88
9-
const nonEmptyEntries = computed(() => Object.entries(props.reason).filter(([_key, values]) => !!values))
9+
const nonEmptyEntries = computed(() => Object.entries(props.reason).filter(([_key, values]) => !!values) as Array<[keyof Reason, Reason[keyof Reason]]>)
1010
11-
function isObject(entry?: any): boolean {
12-
return entry && typeof entry === 'object' && !Array.isArray(entry)
11+
function isObject(entry?: Reason[keyof Reason]): boolean {
12+
return !!entry && typeof entry === 'object' && !Array.isArray(entry)
13+
}
14+
15+
function formatNumericValue(key: string, val: number | string): number | string {
16+
switch (key) {
17+
case 'score':
18+
return `${Math.round(((1 - (val as number)) * 100))}%`
19+
case 'max_distance':
20+
case 'min_distance':
21+
return `${Math.round(val as number)}m`
22+
default:
23+
return val
24+
}
1325
}
1426
</script>
1527

@@ -20,7 +32,7 @@ function isObject(entry?: any): boolean {
2032
<hr>
2133
<p v-if="!isObject(values)">{{ values }}</p>
2234
<p v-for="[key2, value] in Object.entries(values)" v-else :key="key2">
23-
<b>{{ key2 }}</b>: {{ value }}
35+
<b>{{ key2 }}</b>: {{ formatNumericValue(key2, value) }}
2436
</p>
2537
</span>
2638
</div>

0 commit comments

Comments
 (0)