-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-grade.js
57 lines (46 loc) · 1.2 KB
/
generate-grade.js
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
// script file to generate grade files for testing
function getTemplate() {
const midTermMax = randomInt(40, 50);
const finalMax = randomInt(40, 50);
const template = `~ Meta
> Homework
weight = 0.2
data = 20/20, ${random(12, 20)}/20, ${random(18, 20)}/20, ${random(10, 20)}/20
> Quizzes
weight = 0.1
data = 20/20, ${random(12, 20)}/20, ${random(18, 20)}/20, ${random(10, 20)}/20
> Midterm
weight = 0.3
data = ${random(20, midTermMax)}/${randomInt(40, midTermMax)}
> Final Exam
weight = 0.4
data = ${random(30, finalMax)}/${finalMax}
`;
return template;
}
function random(min, max) {
return (Math.random() * (max - min + 1) + min).toFixed(2);
}
function randomInt(min, max) {
return Math.floor(random(min, max));
}
function main() {
if (!process.argv[2]) {
console.error('No level provided');
process.exit(1);
}
const fs = require('fs');
const courses = ['ma', 'gov', 'cs', 'lang'];
for (const course of courses) {
fs.writeFile(
course + process.argv[2] + '.grade',
getTemplate(),
(err) => {
if (err) {
throw err;
}
}
);
}
}
main();