-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathseed.js
186 lines (177 loc) · 4.86 KB
/
seed.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
var db = require('./models');
var quizzes_list = [
{
title: "Computer Science Quiz",
quiz_category: "Science: Computers",
type: "multiple",
difficulty: "hard",
},
{
title: "Heroes and Villians",
quiz_category: "Marvel",
type: "multiple",
difficulty: "hard",
}
];
var questions_list = [
{
category: "Science: Computers",
type: "multiple",
difficulty: "hard",
question: "The Harvard architecture for micro-controllers added which additional bus?",
correct_answer: "Instruction",
incorrect_answers: [
"Address",
"Data",
"Control"
]
},
{
category: "Science: Computers",
type: "multiple",
difficulty: "hard",
question: "What was the name of the security vulnerability found in Bash in 2014?",
correct_answer: "Shellshock",
incorrect_answers: [
"Heartbleed",
"Bashbug",
"Stagefright"
]
},
{
category: "Science: Computers",
type: "multiple",
difficulty: "hard",
question: "Which of these names was an actual codename for a cancelled Microsoft project?",
correct_answer: "Neptune",
incorrect_answers: [
"Enceladus",
"Pollux",
"Saturn"
]
},
//MARVEL
{
category: "Marvel",
type: "multiple",
difficulty: "hard",
question: "Which trait do you most value and admire?",
correct_answer: "Creativity",
incorrect_answers: [
"Athleticism",
"Trickery",
"Vengence"
]
},
{
category: "Marvel",
type: "multiple",
difficulty: "hard",
question: "Complete this sentence: With great power comes great ...",
correct_answer: "Responsibility",
incorrect_answers: [
"Benefits",
"Toys",
"Groopies"
]
},
{
category: "Marvel",
type: "multiple",
difficulty: "hard",
question: "Fill in the sentence: A man will fight when ... A God will fight when ...",
correct_answer: "Hope be dim, hope be gone",
incorrect_answers: [
"rewards are grandious, rewards are none",
"his life is on the line, all life is on the line",
"when the suns out, no matter the weather!"
]
}
// {
// "category": "Science: Computers",
// "type": "multiple",
// "difficulty": "easy",
// "question": "This mobile OS held the largest market share in 2012.",
// "correct_answer": "iOS",
// "incorrect_answers": [
// "Android",
// "BlackBerry",
// "Symbian"
// ]
// },
// {
// "category": "Science: Computers",
// "type": "multiple",
// "difficulty": "easy",
// "question": "How many values can a single byte represent?",
// "correct_answer": "256",
// "incorrect_answers": [
// "8",
// "1",
// "1024"
// ]
// },
// {
// "category": "Science: Computers",
// "type": "multiple",
// "difficulty": "easy",
// "question": "Which computer hardware device provides an interface for all other connected devices to communicate?",
// "correct_answer": "Motherboard",
// "incorrect_answers": [
// "Central Processing Unit",
// "Hard Disk Drive",
// "Random Access Memory"
// ]
// }
];
// db.Question.remove({}, function(err, questions){
// console.log('removed all questions');
//
// db.Question.create(questions_list, (function(err, allQuestions) {
// if (err) {
// console.log(err);
// } else {
// console.log(allQuestions);
// process.exit(0)
// };
// }));
// });
db.Question.remove({}, function(err, questions) {
console.log("removed all questions");
db.Question.create(questions_list, function(err, questions){
if (err) {
console.log(err);
return;
}
console.log('recreated all questions');
console.log("created", questions.length, "questions");
db.Quiz.remove({}, function(err, quiz){
console.log('removed all quizzes');
quizzes_list.forEach(function (quizData) {
var quiz = new db.Quiz({
title: quizData.title,
type: quizData.type,
difficulty: quizData.difficulty,
});
//use find instead of findOne to find all questions?
db.Question.find({ category: quizData.quiz_category }, function(err, quizQuestions) {
console.log("THIS IS OUR QUIZ CATEGORY", quizData.quiz_category);
console.log("THIS IS OUR FOUND CATEGORY", quizQuestions);
console.log('found question in category: ' + quizQuestions[0].category + ' for quiz ' + quiz.title);
quiz.questions = quizQuestions;
console.log("THESE ARE OUR quiz questions", quiz.questions);
if (err) {
console.log(err);
return;
}
quiz.save(function(err, savedQuiz) {
if (err) {
return console.log(err);
}
console.log('saved ' + savedQuiz.title + ' with questions ' + quizQuestions);
});
});
});
});
});
});