This commit is contained in:
lingdocs 2022-08-29 19:53:01 +04:00
parent a3219230bc
commit 21072755c1
1 changed files with 17 additions and 10 deletions

View File

@ -103,16 +103,23 @@ function getPercentageComplete(
tests: undefined | AT.TestResult[], tests: undefined | AT.TestResult[],
): "not logged in" | number { ): "not logged in" | number {
if (!tests) return "not logged in"; if (!tests) return "not logged in";
const chapterTestIds = chapter.items.map(gr => gr.id); console.log({ tests, chapter });
const userCompletedIds = tests.map(t => t.id); try {
const required = chapterTestIds.length; const chapterTestIds = chapter.items.map(gr => gr.id);
const completed = chapterTestIds const userCompletedIds = tests.map(t => t.id);
.filter(userCompletedIds.includes) const required = chapterTestIds.length;
.length; const completed = chapterTestIds
.filter(userCompletedIds.includes)
.length;
return Math.round( return Math.round(
(completed / (required + 1)) * 100 (completed / (required + 1)) * 100
); );
} catch (e) {
console.error("error getting per");
console.error(e);
return 0;
}
} }
export default GamesBrowser; export default GamesBrowser;