continue fixing

This commit is contained in:
2026-06-13 10:35:06 +08:00
parent 76c2f17229
commit b19c811048
8 changed files with 240 additions and 43 deletions

View File

@@ -0,0 +1,51 @@
export type VocabularyRiskTestType = 'chinese-to-english' | 'audio-to-english' | 'multiple-choice';
export const DEFAULT_VOCABULARY_FULL_CORRECT_WORD_THRESHOLD = 50;
export const VOCABULARY_FULL_CORRECT_RISK_FLAG = 'large_batch_all_correct';
export const INVALIDATING_VOCABULARY_RISK_FLAGS: string[] = [
'too_fast',
'too_slow',
'missing_input_value_trace',
'input_value_mismatch',
'uniform_answer_intervals',
'repeated_whole_second_intervals',
VOCABULARY_FULL_CORRECT_RISK_FLAG
];
const parsePositiveThreshold = (value: unknown): number | undefined => {
const parsed = Number(value);
return Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
};
export const getVocabularyFullCorrectWordThreshold = (): number => {
return parsePositiveThreshold(process.env.VOCABULARY_FULL_CORRECT_WORD_THRESHOLD) ??
DEFAULT_VOCABULARY_FULL_CORRECT_WORD_THRESHOLD;
};
export const analyzeVocabularyAttemptResultRisk = ({
testType,
totalWords,
correctWords,
threshold = getVocabularyFullCorrectWordThreshold()
}: {
testType: VocabularyRiskTestType | string;
totalWords: number;
correctWords: number;
threshold?: number;
}): string[] => {
const effectiveThreshold = parsePositiveThreshold(threshold) ??
DEFAULT_VOCABULARY_FULL_CORRECT_WORD_THRESHOLD;
const safeTotalWords = Number.isFinite(totalWords) ? totalWords : 0;
const safeCorrectWords = Number.isFinite(correctWords) ? correctWords : 0;
if (
testType !== 'multiple-choice' &&
safeTotalWords > effectiveThreshold &&
safeTotalWords === safeCorrectWords
) {
return [VOCABULARY_FULL_CORRECT_RISK_FLAG];
}
return [];
};