From 4ba8819f3c6b9a575aa3451e87d9624faaf970c9 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 8 May 2024 11:47:02 +0100 Subject: [PATCH] Fix JAT scores when there are no movements. #23 --- .../route_check/jat_check/EditJunction.svelte | 4 +++- src/routes/route_check/results.ts | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/routes/route_check/jat_check/EditJunction.svelte b/src/routes/route_check/jat_check/EditJunction.svelte index 9ebc60dcd5..9bc3c743a3 100644 --- a/src/routes/route_check/jat_check/EditJunction.svelte +++ b/src/routes/route_check/jat_check/EditJunction.svelte @@ -162,7 +162,9 @@ {/each} -

Total JAT score: {totalScore($state.jat[junctionIdx][stage])}%

+ {#if $state.jat[junctionIdx][stage].movements.length > 0} +

Total JAT score: {totalScore($state.jat[junctionIdx][stage])}%

+ {/if} {:else} (editing = null)}>Save Delete diff --git a/src/routes/route_check/results.ts b/src/routes/route_check/results.ts index fc22d4f29e..dd070e2963 100644 --- a/src/routes/route_check/results.ts +++ b/src/routes/route_check/results.ts @@ -347,10 +347,19 @@ function getJatResults(state: State): JunctionResult[] { scoreBoth += scoreLookup[m.score]; totalPossibleBoth += 2; } - // TODO Handle 'not completed's - result.walkingWheeling[stage] = `${(scoreWW / totalPossibleWW) * 100}%`; - result.cycling[stage] = `${(scoreCycling / totalPossibleCycling) * 100}%`; - result.total[stage] = `${(scoreBoth / totalPossibleBoth) * 100}%`; + + result.walkingWheeling[stage] = + totalPossibleWW > 0 + ? `${(scoreWW / totalPossibleWW) * 100}%` + : "Not Completed"; + result.cycling[stage] = + totalPossibleCycling > 0 + ? `${(scoreCycling / totalPossibleCycling) * 100}%` + : "Not Comleted"; + result.total[stage] = + totalPossibleBoth > 0 + ? `${(scoreBoth / totalPossibleBoth) * 100}%` + : "Not Completed"; } out.push(result); }