-
Notifications
You must be signed in to change notification settings - Fork 0
/
overview.mjs
37 lines (28 loc) · 1.11 KB
/
overview.mjs
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
import DefaultObj from '../utils/DefaultObj.mjs';
import serveVirtualFile from '../utils/serveVirtualFile.mjs';
import pointPercentage from '../utils/percentage.mjs';
import { getStates } from './states.mjs';
import { getCategories } from './categories.mjs';
async function overview() {
const categories = await getCategories();
const states = await getStates(false);
const bars = new DefaultObj(() => ({ states: [] }));
for (const { slug, color, description, maxPoints } of categories) {
bars[slug].color = color;
bars[slug].description = description;
for (const state of states) {
const { achievedPoints } = state.performance.find(
({ categorySlug }) => categorySlug === slug,
);
const percentage = pointPercentage(achievedPoints, maxPoints);
bars[slug].states.push({
state: { slug: state.slug, name: state.name, short: state.short },
percentage,
});
}
bars[slug].states.sort((a, b) => b.percentage - a.percentage);
}
const clean = { ...bars, toJSON: undefined };
return clean;
}
export default serveVirtualFile('overview', overview);