From b51f028def354695331194a8dec830ae28c5cb66 Mon Sep 17 00:00:00 2001 From: Gerald Iakobinyi-Pich Date: Tue, 21 May 2024 10:04:20 +0300 Subject: [PATCH] feat(app): add support for raw scores from non-binary scorers as well --- app/context/scorerContext.tsx | 41 +++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/app/context/scorerContext.tsx b/app/context/scorerContext.tsx index c602304b6f..db9f2e99bf 100644 --- a/app/context/scorerContext.tsx +++ b/app/context/scorerContext.tsx @@ -122,22 +122,35 @@ export const ScorerContextProvider = ({ children }: { children: any }) => { } setScoreState(response.data.status); if (response.data.status === "DONE") { - if (!response.data.evidence) { - console.error("Invalid scorer configured. Please configure a 'binary weighted' scorer"); - } - const numRawScore = Number.parseFloat(response.data.evidence.rawScore); - const numThreshold = Number.parseFloat(response.data.evidence.threshold); - const numScore = Number.parseFloat(response.data.score); + // We need to handle the 2 types the scorers that the backend allows: binary as well as not-binary + if (response.data.evidence) { + // This is a binary scorer (binary scorers have the evidence data) + const numRawScore = Number.parseFloat(response.data.evidence.rawScore); + const numThreshold = Number.parseFloat(response.data.evidence.threshold); + const numScore = Number.parseFloat(response.data.score); + + setRawScore(numRawScore); + setThreshold(numThreshold); + setScore(numScore); + setStampScores(response.data.stamp_scores); + + if (numRawScore > numThreshold) { + setScoreDescription("Passing Score"); + } else { + setScoreDescription("Low Score"); + } + } else { + // This is not a binary scorer + const numRawScore = Number.parseFloat(response.data.score); + const numThreshold = 0; + const numScore = Number.parseFloat(response.data.score); - setRawScore(numRawScore); - setThreshold(numThreshold); - setScore(numScore); - setStampScores(response.data.stamp_scores); + setRawScore(numRawScore); + setThreshold(numThreshold); + setScore(numScore); + setStampScores(response.data.stamp_scores); - if (numRawScore > numThreshold) { - setScoreDescription("Passing Score"); - } else { - setScoreDescription("Low Score"); + setScoreDescription(""); } }