Spaces:
Running
Running
File size: 1,584 Bytes
a58dac7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
// Lightweight helper to determine whether a category should be considered fully Not Applicable.
// It intentionally only treats the category as NA when the category-level field
// `additionalAspects` explicitly marks it as not applicable. Question-level/source
// markers are ignored for category selectability (they are relevant to question details).
export function naReasonForCategoryFromEval(
catEval: any,
benchmarkQuestionIds: string[] = [],
processQuestionIds: string[] = []
): string | undefined {
if (!catEval) return undefined
const isNonNAAnswer = (ans: any) => {
if (ans === undefined || ans === null) return false
if (Array.isArray(ans)) {
return ans.some((a) => {
const s = String(a || "").trim().toLowerCase()
return s !== "n/a" && !/not applicable/i.test(s) && s.length > 0
})
}
const s = String(ans).trim().toLowerCase()
return s !== "n/a" && !/not applicable/i.test(s) && s.length > 0
}
let anyNonNA = false
if (catEval.benchmarkAnswers) {
for (const k of benchmarkQuestionIds) {
if (isNonNAAnswer(catEval.benchmarkAnswers[k])) {
anyNonNA = true
break
}
}
}
if (!anyNonNA && catEval.processAnswers) {
for (const k of processQuestionIds) {
if (isNonNAAnswer(catEval.processAnswers[k])) {
anyNonNA = true
break
}
}
}
if (anyNonNA) return undefined
if (typeof catEval.additionalAspects === "string" && /not applicable/i.test(catEval.additionalAspects)) {
return catEval.additionalAspects
}
return undefined
}
|