-
Notifications
You must be signed in to change notification settings - Fork 0
/
G-K.js
313 lines (290 loc) · 10.3 KB
/
G-K.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
process.env.DEBUG = "dialogflow:debug"
const Model = require("./schema.js").model
const Model1 = require("./schema.js").model1
exports.gk = async (agent) => {
var ourContext = agent.getContext("abc")
var score = 0;
var increment = 1;
var i = 0;
var i1; var i2; var i3; var i4; var i5; var i6; //differnt variables to store in context
var i7; var i8; var i9;
var score1; var score2; var score3; var score4; var score5;
var score6; var score7; var score8; var score9; var score10;
const opt = agent.parameters['option'];
const ask = agent.parameters['ask'];
if (!opt && !ask) {
console.log("ques 1 triggered")
console.log("context are : ", ourContext)
await Model1.find({}).then(data => {
agent.add(`${data[0].Question[i]}`)
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (opt && !ourContext.parameters.opt1) {
i1 = i + increment
console.log("ques 2 triggered")
console.log("context are : ", ourContext)
if (opt === "3" && !ourContext) {
score1 = score + increment
}
else {
score1 = score
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}, Here is your next question.${data[0].Question[i1]}`)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt1": opt, i1,
score1
}
});
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt1 && !ourContext.parameters.opt2) {
i2 = ourContext.parameters.i1 + increment
console.log("value of i is :", i)
console.log("ques 3 triggered")
console.log("context are : ", ourContext)
if (opt === "2" && !ourContext.parameters.opt2) {
score2 = ourContext.parameters.score1 + increment
}
else {
score2 = ourContext.parameters.score1
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt} . Here is your next question.${data[0].Question[i2]} `)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt2": opt, i2,
score2
}
})
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt2 && !ourContext.parameters.opt3) {
i3 = ourContext.parameters.i2 + increment
console.log("value of i is :", i)
console.log("ques 4 triggered")
console.log("context are : ", ourContext)
if (opt === "2" && !ourContext.parameters.opt3) {
score3 = ourContext.parameters.score2 + increment
}
else {
score3 = ourContext.parameters.score2
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}. Here is your next question.${data[0].Question[i3]} `)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt3": opt, i3,
score3
}
})
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt3 && !ourContext.parameters.opt4) {
i4 = ourContext.parameters.i3 + increment
console.log("ques 5 triggered")
console.log("context are : ", ourContext)
if (opt === "1" && !ourContext.parameters.opt4) {
score4 = ourContext.parameters.score3 + increment
}
else {
score4 = ourContext.parameters.score3
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}.Here is your next question.${data[0].Question[i4]} `)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt4": opt, i4,
score4
}
});
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt4 && !ourContext.parameters.opt5) {
i5 = ourContext.parameters.i4 + increment
console.log("ques 6 triggered")
console.log("context are : ", ourContext)
if (opt === "3" && !ourContext.parameters.opt5) {
score5 = ourContext.parameters.score4 + increment
}
else {
score5 = ourContext.parameters.score4
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}.Here is your next question.${data[0].Question[i5]}`)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt5": opt, i5,
score5
}
});
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt5 && !ourContext.parameters.opt6) {
i6 = ourContext.parameters.i5 + increment
console.log("ques 7 triggered")
console.log("context are : ", ourContext)
if (opt === "2" && !ourContext.parameters.opt6) {
score6 = ourContext.parameters.score5 + increment
}
else {
score6 = ourContext.parameters.score5
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}.Here is your next question.${data[0].Question[i6]}`)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt6": opt, i6,
score6
}
});
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt6 && !ourContext.parameters.opt7) {
i7 = ourContext.parameters.i6 + increment
console.log("ques 8 triggered")
console.log("context are : ", ourContext)
if (opt === "1" && !ourContext.parameters.opt7) {
score7 = ourContext.parameters.score6 + increment
}
else {
score7 = ourContext.parameters.score6
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}.Here is your next question.${data[0].Question[i7]}`)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt7": opt, i7,
score7
}
});
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt7 && !ourContext.parameters.opt8) {
i8 = ourContext.parameters.i7 + increment
console.log("ques 9 triggered")
console.log("context are : ", ourContext)
if (opt === "3" && !ourContext.parameters.opt8) {
score8 = ourContext.parameters.score7 + increment
}
else {
score8 = ourContext.parameters.score7
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}.Here is your next question.${data[0].Question[i8]} `)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt8": opt, i8,
score8
}
});
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt8 && !ourContext.parameters.opt9) {
i9 = ourContext.parameters.i8 + increment
console.log("ques 10 triggered")
console.log("context are : ", ourContext)
if (opt === "2" && !ourContext.parameters.opt9) {
score9 = ourContext.parameters.score8 + increment
}
else {
score9 = ourContext.parameters.score8
}
await Model1.find({}).then(data => {
agent.add(`You said option ${opt}.Here is your next question.${data[0].Question[i9]}`)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt9": opt, i9,
score9
}
});
}).catch(err => {
console.log("Error is : ", err)
})
}
else if (ourContext.parameters.opt9 && !ourContext.parameters.opt10) {
console.log("context are : ", ourContext)
var name = ourContext.parameters.Name
if (opt === "1" && !ourContext.parameters.opt10) {
score10 = ourContext.parameters.score9 + increment
}
else {
score10 = ourContext.parameters.score9
}
Model.find({}).then(data => {
console.log("data is", data)
if (data.filter((val) => val.Roll_No == ourContext.parameters.Roll_No).length) {
Model.findOneAndUpdate({ Roll_No: ourContext.parameters.Roll_No }, { Total_Score_in_Science: score10, _v: 0 }, (err, data) => {
if (err) throw err
else {
console.log("Updated data is", data)
}
})
}
else {
var info = {
Name: name,
Roll_No: ourContext.parameters.Roll_No,
Total_Score_in_Science: score10
}
var saveData = new Model(info);
saveData.save((err, mydata) => {
if (err) {
console.log("error is:", err);
}
else {
console.log("data is : ", mydata)
return
}
});
}
})
agent.add(`Congratulations you answered all 10 questions, ${score10} out of 10 was correct,
Your score is ${(score10 * 100) / 10}%, Do you want me to send your transcript in your email?`)
agent.setContext({
name: "abc",
lifespan: 5,
"parameters": {
"opt10": opt, i,
score10
}
});
}
}