You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
564 B
17 lines
564 B
export function getAssessmentLocalProgress(
|
|
draft: unknown,
|
|
serverCompleted: boolean,
|
|
): number {
|
|
if (serverCompleted) return 100;
|
|
if (!draft || typeof draft !== "object") return 0;
|
|
|
|
const value = draft as { answers?: unknown; totalQuestions?: unknown };
|
|
const answers = value.answers;
|
|
const total = Number(value.totalQuestions);
|
|
if (!answers || typeof answers !== "object" || !Number.isFinite(total) || total <= 0) {
|
|
return 0;
|
|
}
|
|
|
|
const answered = Object.keys(answers).length;
|
|
return Math.min(99, Math.round((answered / total) * 100));
|
|
}
|