김성욱

Add result & detail

Showing 1 changed file with 172 additions and 0 deletions
...@@ -322,6 +322,178 @@ apiRouter.post('/question7', (req, res) => { ...@@ -322,6 +322,178 @@ apiRouter.post('/question7', (req, res) => {
322 res.status(200).send(responseBody); 322 res.status(200).send(responseBody);
323 }); 323 });
324 324
325 +apiRouter.post('/result', (req, res) => {
326 + var userId = req.body.userRequest.user.id;
327 + var mesg = req.body.userRequest.utterance;
328 + console.log('[result:user message] ', mesg);
329 + var mbti = '';
330 + if (mesg == "네") {
331 + mbti = 'T';
332 + } else if (mesg == "아니오") {
333 + mbti = 'F';
334 + }
335 + userDB[userId][2] += mbti;
336 + console.log(userDB[userId]);
337 + result(userDB[userId]);
338 + const responseBody = {
339 + version: "2.0",
340 + template: {
341 + outputs: [
342 + {
343 + simpleText: {
344 + text: "당신의 MBTI는 : "+userDB[userId][4]
345 + }
346 + }
347 + ],
348 + quickReplies: [{
349 + action: "block",
350 + label: "MBTI 테스트 다시하기",
351 + message: "MBTI 테스트 다시하기",
352 + blockId : "6297b10d5ceed96c38544a06"
353 + },
354 + {
355 + action: "block",
356 + label: "자세한 결과 보기",
357 + message: "자세한 결과 보기",
358 + blockId: "6297bc58ab89e678ee86b33a"
359 + }]
360 + }
361 + }
362 + res.status(200).send(responseBody);
363 +});
364 +
365 +apiRouter.post('/detail', (req, res) => {
366 + var userId = req.body.userRequest.user.id;
367 + var mesg = req.body.userRequest.utterance;
368 + var E=0;
369 + var I=0;
370 + var N=0;
371 + var S=0;
372 + var F=0;
373 + var T=0;
374 + var P=0;
375 + var J=0;
376 +
377 + for(let j=0;j<4;j++){
378 + for(let i=0; i<3; i++){
379 + if(j==0){
380 + if(userDB[userId][j][i]=="E"){
381 + E++;
382 + }
383 + else{
384 + I++;
385 + }
386 + }
387 + else if(j==1){
388 + if(userDB[userId][j][i]=="N"){
389 + N++;
390 + }
391 + else{
392 + S++;
393 + }
394 + }
395 + else if(j==2){
396 + if(userDB[userId][j][i]=="F"){
397 + F++;
398 + }
399 + else{
400 + T++;
401 + }
402 + }
403 + else if(j==3){
404 + if(userDB[userId][j][i]=="N"){
405 + P++;
406 + }
407 + else{
408 + J++;
409 + }
410 + }
411 + }
412 + }
413 +
414 + const responseBody = {
415 + version: "2.0",
416 + template: {
417 + outputs: [
418 + {
419 + simpleText: {
420 + text: "E와 I의 비율\nE : "+(E/(E+I)*100)+"%\nI : "+(I/(E+I)*100)+"\nN와 S의 비율\nN : "+(N/(N+S)*100)+"%\nS : "+(S/(N+S)*100)+"\nF와 T의 비율\nF : "+(F/(F+T)*100)+"%\nT : "+(T/(F+T)*100)+"\nJ와 P의 비율\nJ : "+(J/(J+P)*100)+"%\nP : "+(P/(J+P)*100)
421 + }
422 + }
423 + ]
424 + }
425 + }
426 + res.status(200).send(responseBody);
427 +});
428 +
429 +function result(Array){
430 + var E=0;
431 + var I=0;
432 + var N=0;
433 + var S=0;
434 + var F=0;
435 + var T=0;
436 + var P=0;
437 + var J=0;
438 +
439 + for(let j=0;j<4;j++){
440 + for(let i=0; i<3; i++){
441 + if(j==0){
442 + if(Array[j][i]=="E"){
443 + E++;
444 + }
445 + else{
446 + I++;
447 + }
448 + }
449 + else if(j==1){
450 + if(Array[j][i]=="N"){
451 + N++;
452 + }
453 + else{
454 + S++;
455 + }
456 + }
457 + else if(j==2){
458 + if(Array[j][i]=="F"){
459 + F++;
460 + }
461 + else{
462 + T++;
463 + }
464 + }
465 + else if(j==3){
466 + if(Array[j][i]=="N"){
467 + P++;
468 + }
469 + else{
470 + J++;
471 + }
472 + }
473 + }
474 + }
475 +
476 + if(E>I)
477 + Array[4]+='E';
478 + else
479 + Array[4]+='I';
480 +
481 + if(N>S)
482 + Array[4]+='N';
483 + else
484 + Array[4]+='S';
485 +
486 + if(F>T)
487 + Array[4]+='F';
488 + else
489 + Array[4]+='T';
490 +
491 + if(P>J)
492 + Array[4]+='P';
493 + else
494 + Array[4]+='J';
495 +}
496 +
325 app.listen((process.env.PORT || 3000), function() { 497 app.listen((process.env.PORT || 3000), function() {
326 console.log('Example skill server listening on port 3000!'); 498 console.log('Example skill server listening on port 3000!');
327 }); 499 });
...\ No newline at end of file ...\ No newline at end of file
......