-
Notifications
You must be signed in to change notification settings - Fork 315
/
Copy pathpod.dummy-response-generator.yaml
69 lines (60 loc) · 2.03 KB
/
pod.dummy-response-generator.yaml
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
apiVersion: v1
kind: Pod
metadata:
name: dummy-response-generator
labels:
app: dummy-response-generator
spec:
restartPolicy: OnFailure
containers:
- name: mongo
image: mongo:5
command:
- sh
- -c
- |
mongosh mongodb+srv://quiz-pods.kiada.svc.cluster.local/kiada?tls=false --quiet --file /dev/stdin <<EOF
const dateFrom = new Date("2020-01-01Z");
const dateTo = new Date("2023-01-01Z");
const maxTimeBetweenResponsesMillis = 3600 * 1000; // 1 hour
print("Generating dummy quiz responses");
print("===============================");
print();
var cursor = db.questions.find();
var questions = cursor.toArray();
cursor.close();
print("Found " + questions.length + " questions.");
print();
print("Date range:");
print(" From: " + dateFrom);
print(" To: " + dateTo);
print();
print("Generated responses:")
var count=0;
var responses = [];
var date = dateFrom;
do {
date.setTime(date.getTime() + Math.floor(Math.random() * maxTimeBetweenResponsesMillis));
var question = questions[Math.floor(Math.random() * questions.length)];
var answerIndex = Math.floor(Math.random() * question.answers.length);
var response = {
timestamp: date,
questionId: question.id,
answerIndex: answerIndex,
correctAnswerIndex: question.correctAnswerIndex,
correct: answerIndex == question.correctAnswerIndex
};
print(JSON.stringify(response));
responses.push(response);
count++;
if (count % 1000 == 0) { // insert responses in batches of 1000
db.responses.insertMany(responses);
responses = [];
}
} while (date.getTime() < dateTo)
db.responses.insertMany(responses); // insert any remaining responses
print();
print("Generated a total of " + count + " responses.");
print();
print("Done.");
EOF