Showing
1 changed file
with
71 additions
and
29 deletions
... | @@ -305,37 +305,79 @@ apiRouter.post('/question20', (req, res) => { | ... | @@ -305,37 +305,79 @@ apiRouter.post('/question20', (req, res) => { |
305 | 305 | ||
306 | apiRouter.post('/result', (req, res) => { | 306 | apiRouter.post('/result', (req, res) => { |
307 | var userId = req.body.userRequest.user.id; | 307 | var userId = req.body.userRequest.user.id; |
308 | - var mesg = req.body.userRequest.utterance; | 308 | + var mesg = req.body.userRequest.utterance; |
309 | - console.log('[result:user message] ', mesg); | 309 | + var mbti = ''; |
310 | - var mbti = ''; | 310 | + if (mesg == "네") { |
311 | - if (mesg == "네") { | 311 | + mbti = 'J'; |
312 | - mbti = 'J'; | 312 | + } else if (mesg == "아니오") { |
313 | - } else if (mesg == "아니오") { | 313 | + mbti = 'P'; |
314 | - mbti = 'P'; | 314 | + } |
315 | - } | 315 | + userDB[userId][3] += mbti; |
316 | - userDB[userId][3] += mbti; | 316 | + console.log(userDB[userId]); |
317 | - console.log(userDB[userId]); | 317 | + analysis_mbti(userDB[userId]); |
318 | - const responseBody = { | 318 | + const responseBody = { |
319 | - version: "2.0", | 319 | + version: "2.0", |
320 | - template: { | 320 | + template: { |
321 | - outputs: [ | 321 | + outputs: [ |
322 | - { | 322 | + { |
323 | - simpleText: { | 323 | + simpleText: { |
324 | - text: "당신의 MBTI는 : "+userDB[userId] | 324 | + text: "당신의 MBTI는 : "+userDB[userId][4] |
325 | - } | 325 | + |
326 | - } | 326 | + } |
327 | - ], | 327 | + } |
328 | - quickReplies: [{ | 328 | + ], |
329 | - action: "block", | 329 | + quickReplies: [{ |
330 | - label: "MBTI 테스트 다시하기", | 330 | + action: "block", |
331 | - message: "MBTI 테스트 다시하기", | 331 | + label: "MBTI 테스트 다시하기", |
332 | - blockId : "628b7ef293b31d5b60ab4b29" //to question 1 | 332 | + message: "MBTI 테스트 다시하기", |
333 | - }] | 333 | + blockId : "628b7ef293b31d5b60ab4b29" //to question 1 |
334 | - } | 334 | + }] |
335 | - } | 335 | + } |
336 | - res.status(200).send(responseBody); | 336 | + } |
337 | + res.status(200).send(responseBody); | ||
337 | }); | 338 | }); |
338 | 339 | ||
340 | +function analysis_mbti(userdb) { | ||
341 | + var e = count_mbti(userdb[0], 'E'); | ||
342 | + var i = 1-e; //-> 5 | ||
343 | + var n = count_mbti(userdb[1], 'N'); | ||
344 | + var s = 1-n; //-> 5 | ||
345 | + var f = count_mbti(userdb[2], 'F'); | ||
346 | + var t = 2-f; //-> 5 | ||
347 | + var j = count_mbti(userdb[3], 'J'); | ||
348 | + var p = 2-j; //-> 5 | ||
349 | + if (e > i) { | ||
350 | + userdb[4] += 'E'; | ||
351 | + } else { | ||
352 | + userdb[4] += 'I'; | ||
353 | + } | ||
354 | + if (n > s) { | ||
355 | + userdb[4] += 'N'; | ||
356 | + } else { | ||
357 | + userdb[4] += 'S'; | ||
358 | + } | ||
359 | + if (f > t) { | ||
360 | + userdb[4] += 'F'; | ||
361 | + } else { | ||
362 | + userdb[4] += 'T'; | ||
363 | + } | ||
364 | + if (j > p) { | ||
365 | + userdb[4] += 'J'; | ||
366 | + } else { | ||
367 | + userdb[4] += 'P'; | ||
368 | + } | ||
369 | +} | ||
370 | + | ||
371 | +function count_mbti(item_list, mbti_ch) { | ||
372 | + var result = 0; | ||
373 | + for (var i=0; i<5; i++) { | ||
374 | + if(item_list[i] == 'mbti_ch'){ | ||
375 | + result += 1; | ||
376 | + } | ||
377 | + } | ||
378 | + return result; | ||
379 | +} | ||
380 | + | ||
339 | app.listen((process.env.PORT || 3000), function() { | 381 | app.listen((process.env.PORT || 3000), function() { |
340 | console.log('Example skill server listening on port 3000!'); | 382 | console.log('Example skill server listening on port 3000!'); |
341 | }); | 383 | }); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment