forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiznator.js
More file actions
119 lines (113 loc) · 2.74 KB
/
Copy pathquiznator.js
File metadata and controls
119 lines (113 loc) · 2.74 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import axios from "axios"
import { accessToken } from "./moocfi"
import { flatten, getCommonElements } from "../util/arrays"
const BASE_URL = "https://quiznator.mooc.fi"
export async function fetchManyQuizDetails(quizIds) {
const res = await axios.post(
`${BASE_URL}/api/v1/quizzes/stripped`,
{ quizIds },
{ headers: { Authorization: `Bearer ${accessToken()}` } },
)
return res.data
}
export async function fetchQuizProgress() {
let res = []
const partToTag = [
{
part: "osa01",
tag: "ohjelmoinnin-mooc-2019-1",
},
{
part: "osa02",
tag: "ohjelmoinnin-mooc-2019-2",
},
{
part: "osa03",
tag: "ohjelmoinnin-mooc-2019-3",
},
{
part: "osa04",
tag: "ohjelmoinnin-mooc-2019-4",
},
{
part: "osa05",
tag: "ohjelmoinnin-mooc-2019-5",
},
{
part: "osa06",
tag: "ohjelmoinnin-mooc-2019-6",
},
{
part: "osa07",
tag: "ohjelmoinnin-mooc-2019-7",
},
{
part: "osa08",
tag: "ohjelmoinnin-mooc-2019-8",
},
{
part: "osa09",
tag: "ohjelmoinnin-mooc-2019-9",
},
{
part: "osa10",
tag: "ohjelmoinnin-mooc-2019-10",
},
{
part: "osa11",
tag: "ohjelmoinnin-mooc-2019-11",
},
{
part: "osa12",
tag: "ohjelmoinnin-mooc-2019-12",
},
{
part: "osa13",
tag: "ohjelmoinnin-mooc-2019-13",
},
{
part: "osa14",
tag: "ohjelmoinnin-mooc-2019-14",
},
]
const quizIdInformation = await fetchQuizIds()
const allQuizIds = flatten(quizIdInformation.map(o => o.quizIds))
const progress = await fetchProgressByQuizIds(allQuizIds)
const allAnswered = (progress.answered || []).map(o => o._id)
partToTag.forEach(({ part, tag }) => {
const relevant = quizIdInformation
.filter(o => {
return o.tags.indexOf(tag) !== -1
})
.map(o => o.quizIds)
const quizIds = flatten(relevant)
const answered = getCommonElements(quizIds, allAnswered)
const maxPoints = quizIds.length
const nPoints = answered.length
const progress = Math.floor((nPoints / maxPoints) * 100) / 100
res = res.concat({
group: part,
max_points: maxPoints,
n_points: nPoints,
progress,
})
})
return res
}
export async function fetchQuizIds() {
const res = await axios.post(
`${BASE_URL}/api/v1/tags/quizids`,
{ tags: ["ohjelmoinnin-mooc-2019"] },
{ headers: { Authorization: `Bearer ${accessToken()}` } },
)
return res.data
}
async function fetchProgressByQuizIds(quizIds) {
const res = await axios.post(
`${BASE_URL}/api/v1/answerers/progress`,
{ quizIds },
{ headers: { Authorization: `Bearer ${accessToken()}` } },
)
const data = res.data
return data
}