Showing
1 changed file
with
44 additions
and
2 deletions
... | @@ -306,7 +306,6 @@ apiRouter.post('/question20', (req, res) => { | ... | @@ -306,7 +306,6 @@ apiRouter.post('/question20', (req, res) => { |
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); | ||
310 | var mbti = ''; | 309 | var mbti = ''; |
311 | if (mesg == "네") { | 310 | if (mesg == "네") { |
312 | mbti = 'J'; | 311 | mbti = 'J'; |
... | @@ -315,13 +314,15 @@ apiRouter.post('/result', (req, res) => { | ... | @@ -315,13 +314,15 @@ apiRouter.post('/result', (req, res) => { |
315 | } | 314 | } |
316 | userDB[userId][3] += mbti; | 315 | userDB[userId][3] += mbti; |
317 | console.log(userDB[userId]); | 316 | 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 | ], |
... | @@ -336,6 +337,47 @@ apiRouter.post('/result', (req, res) => { | ... | @@ -336,6 +337,47 @@ apiRouter.post('/result', (req, res) => { |
336 | res.status(200).send(responseBody); | 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