better test summary for admin page
This commit is contained in:
parent
2193284a14
commit
07ed3b5958
|
@ -304,15 +304,42 @@ const authRouter = (passport: PassportStatic) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTestCompletionSummary(users: T.LingdocsUser[]) {
|
function getTestCompletionSummary(users: T.LingdocsUser[]) {
|
||||||
const tests: { id: string, passes: number }[] = [];
|
const tests: { id: string, passes: number, fails: number }[] = [];
|
||||||
users.forEach(u => (
|
users.forEach(u => {
|
||||||
Array.from(new Set(u.tests.map(x => x.id))).forEach(id => {
|
const usersTests = removeDuplicateTests(u.tests)
|
||||||
const ti = tests.findIndex(x => x.id === id);
|
usersTests.forEach(ut => {
|
||||||
if (ti > -1) tests[ti].passes++;
|
const ti = tests.findIndex(x => x.id === ut.id);
|
||||||
else tests.push({ id, passes: 1 });
|
if (ti === -1) {
|
||||||
})
|
tests.push({
|
||||||
));
|
id: ut.id,
|
||||||
|
...ut.done ? { passes: 1, fails: 0 } : { passes: 0, fails: 1 },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else tests[ti][ut.done ? "passes" : "fails"]++;
|
||||||
|
});
|
||||||
|
});
|
||||||
return tests;
|
return tests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeDuplicateTests(tests: T.TestResult[]): T.TestResult[] {
|
||||||
|
return tests.reduceRight((acc, curr) => {
|
||||||
|
const redundant = acc.filter(x => ((x.id === curr.id) && (x.done === curr.done)));
|
||||||
|
return redundant.length
|
||||||
|
? acc
|
||||||
|
: [...acc, curr];
|
||||||
|
}, [...tests]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// function getTestCompletionSummary(users: T.LingdocsUser[]) {
|
||||||
|
// const tests: { id: string, passes: number }[] = [];
|
||||||
|
// users.forEach(u => (
|
||||||
|
// Array.from(new Set(u.tests.map(x => x.id))).forEach(id => {
|
||||||
|
// const ti = tests.findIndex(x => x.id === id);
|
||||||
|
// if (ti > -1) tests[ti].passes++;
|
||||||
|
// else tests.push({ id, passes: 1 });
|
||||||
|
// })
|
||||||
|
// ));
|
||||||
|
// return tests;
|
||||||
|
// }
|
||||||
|
|
||||||
export default authRouter;
|
export default authRouter;
|
|
@ -101,9 +101,9 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div>
|
<div>
|
||||||
<h5>Tests Completed</h5>
|
<h5>Tests Completed: Pass / Fail</h5>
|
||||||
<% for(var i=0; i < tests.length; i++) { %>
|
<% for(var i=0; i < tests.length; i++) { %>
|
||||||
<div><%= tests[i].id %>: <%= tests[i].passes %></div>
|
<div><%= tests[i].id %>: <%= tests[i].passes %> / <%= tests[i].fails %></div>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue