공정훈

Update app.js

Showing 1 changed file with 32 additions and 258 deletions
...@@ -41,36 +41,6 @@ apiRouter.post('/sayHello', function(req, res) { ...@@ -41,36 +41,6 @@ apiRouter.post('/sayHello', function(req, res) {
41 res.status(200).send(responseBody); 41 res.status(200).send(responseBody);
42 }); 42 });
43 43
44 -apiRouter.post('/test', (req, res) => {
45 - const responseBody = {
46 - version: "2.0",
47 - template: {
48 - outputs: [
49 - {
50 - simpleText: {
51 - text: '재밌는 MBTI 테스트'
52 - }
53 - }
54 - ],
55 - quickReplies: [
56 - {
57 - action: "block",
58 - label: "할래!",
59 - message: "할래!",
60 - blockId: "6294c3ecf591aa1905548230"
61 - },
62 - {
63 - action: "block",
64 - label: "안 할래",
65 - message: "안 할래",
66 - blockId: "628b7ef293b31d5b60ab4b29"
67 - }
68 - ]
69 - }
70 - }
71 - res.status(200).send(responseBody);
72 -});
73 -
74 apiRouter.post('/question1', (req, res) => { 44 apiRouter.post('/question1', (req, res) => {
75 var userId = req.body.userRequest.user.id; 45 var userId = req.body.userRequest.user.id;
76 var mesg = req.body.userRequest; 46 var mesg = req.body.userRequest;
...@@ -338,13 +308,13 @@ apiRouter.post('/question7', (req, res) => { ...@@ -338,13 +308,13 @@ apiRouter.post('/question7', (req, res) => {
338 action: "block", 308 action: "block",
339 label: "네", 309 label: "네",
340 message: "네", 310 message: "네",
341 - blockId: "6297b3505ceed96c38544a0a" 311 + blockId: "62977ff05ceed96c385449b9"
342 }, 312 },
343 { 313 {
344 action: "block", 314 action: "block",
345 label: "아니오", 315 label: "아니오",
346 message: "아니오", 316 message: "아니오",
347 - blockId: "6297b3505ceed96c38544a0a" 317 + blockId: "62977ff05ceed96c385449b9"
348 } 318 }
349 ] 319 ]
350 } 320 }
...@@ -354,8 +324,16 @@ apiRouter.post('/question7', (req, res) => { ...@@ -354,8 +324,16 @@ apiRouter.post('/question7', (req, res) => {
354 324
355 apiRouter.post('/question8', (req, res) => { 325 apiRouter.post('/question8', (req, res) => {
356 var userId = req.body.userRequest.user.id; 326 var userId = req.body.userRequest.user.id;
357 - userDB[userId] = ['','','','','']; 327 + var mesg = req.body.userRequest.utterance;
358 - console.log(userDB); 328 + console.log('[q2:user message] ', mesg);
329 + var mbti = '';
330 + if (mesg == "네") {
331 + mbti = 'T';
332 + } else if (mesg == "아니오") {
333 + mbti = 'F';
334 + }
335 + userDB[userId][1] += mbti;
336 + console.log(userDB[userId]);
359 const responseBody = { 337 const responseBody = {
360 version: "2.0", 338 version: "2.0",
361 template: { 339 template: {
...@@ -617,13 +595,13 @@ apiRouter.post('/question8', (req, res) => { ...@@ -617,13 +595,13 @@ apiRouter.post('/question8', (req, res) => {
617 action: "block", 595 action: "block",
618 label: "네", 596 label: "네",
619 message: "네", 597 message: "네",
620 - blockId: "62979c9ce7a0253c7662ccd4" 598 + blockId: "6294c3ecf591aa1905548230"
621 }, 599 },
622 { 600 {
623 action: "block", 601 action: "block",
624 label: "아니오", 602 label: "아니오",
625 message: "아니오", 603 message: "아니오",
626 - blockId: "62979c9ce7a0253c7662ccd4" 604 + blockId: "6294c3ecf591aa1905548230"
627 } 605 }
628 ] 606 ]
629 } 607 }
...@@ -632,8 +610,17 @@ apiRouter.post('/question8', (req, res) => { ...@@ -632,8 +610,17 @@ apiRouter.post('/question8', (req, res) => {
632 }); 610 });
633 611
634 apiRouter.post('/question15', (req, res) => { 612 apiRouter.post('/question15', (req, res) => {
613 + var mesg = req.body.userRequest.utterance;
635 var userId = req.body.userRequest.user.id; 614 var userId = req.body.userRequest.user.id;
636 - userDB[userId] = ['','','','','']; 615 + var mbti = '';
616 + if (mesg == "네"){
617 + mbti = 'N';
618 + }
619 + else if (mesg == "아니오") {
620 + mbti = 'S';
621 + }
622 + userDB[userId][0] += mbti;
623 + console.log(userDB);
637 const responseBody = { 624 const responseBody = {
638 version: "2.0", 625 version: "2.0",
639 template: { 626 template: {
...@@ -866,16 +853,15 @@ apiRouter.post('/question20', (req, res) => { ...@@ -866,16 +853,15 @@ apiRouter.post('/question20', (req, res) => {
866 apiRouter.post('/result', (req, res) => { 853 apiRouter.post('/result', (req, res) => {
867 var userId = req.body.userRequest.user.id; 854 var userId = req.body.userRequest.user.id;
868 var mesg = req.body.userRequest.utterance; 855 var mesg = req.body.userRequest.utterance;
869 - console.log('[result:user message] ', mesg);
870 var mbti = ''; 856 var mbti = '';
871 if (mesg == "네") { 857 if (mesg == "네") {
872 - mbti = 'T'; 858 + mbti = 'J';
873 } else if (mesg == "아니오") { 859 } else if (mesg == "아니오") {
874 - mbti = 'F'; 860 + mbti = 'P';
875 } 861 }
876 - userDB[userId][2] += mbti; 862 + userDB[userId][3] += mbti;
877 console.log(userDB[userId]); 863 console.log(userDB[userId]);
878 - result(userDB[userId]); 864 + analysis_mbti(userDB[userId]);
879 const responseBody = { 865 const responseBody = {
880 version: "2.0", 866 version: "2.0",
881 template: { 867 template: {
...@@ -967,228 +953,16 @@ apiRouter.post('/detail', (req, res) => { ...@@ -967,228 +953,16 @@ apiRouter.post('/detail', (req, res) => {
967 res.status(200).send(responseBody); 953 res.status(200).send(responseBody);
968 }); 954 });
969 955
970 -function result(Array){
971 - var E=0;
972 - var I=0;
973 - var N=0;
974 - var S=0;
975 - var F=0;
976 - var T=0;
977 - var P=0;
978 - var J=0;
979 -
980 - for(let j=0;j<4;j++){
981 - for(let i=0; i<3; i++){
982 - if(j==0){
983 - if(Array[j][i]=="E"){
984 - E++;
985 - }
986 - else{
987 - I++;
988 - }
989 - }
990 - else if(j==1){
991 - if(Array[j][i]=="N"){
992 - N++;
993 - }
994 - else{
995 - S++;
996 - }
997 - }
998 - else if(j==2){
999 - if(Array[j][i]=="F"){
1000 - F++;
1001 - }
1002 - else{
1003 - T++;
1004 - }
1005 - }
1006 - else if(j==3){
1007 - if(Array[j][i]=="N"){
1008 - P++;
1009 - }
1010 - else{
1011 - J++;
1012 - }
1013 - }
1014 - }
1015 - }
1016 -
1017 - if(E>I)
1018 - Array[4]+='E';
1019 - else
1020 - Array[4]+='I';
1021 -
1022 - if(N>S)
1023 - Array[4]+='N';
1024 - else
1025 - Array[4]+='S';
1026 -
1027 - if(F>T)
1028 - Array[4]+='F';
1029 - else
1030 - Array[4]+='T';
1031 -
1032 - if(P>J)
1033 - Array[4]+='P';
1034 - else
1035 - Array[4]+='J';
1036 -}
1037 -
1038 -apiRouter.post('/result', (req, res) => {
1039 - var mesg = req.body.userRequest.utterance;
1040 - var userId = req.body.userRequest.user.id;
1041 - mbtiper = ['','','','','','','',''];
1042 - var mbti = '';
1043 - if (mesg == "네"){
1044 - mbti = 'N';
1045 - }
1046 - else if (mesg == "아니오") {
1047 - mbti = 'S';
1048 - }
1049 - userDB[userId][1] += mbti;
1050 - var e = 0;
1051 - var n = 0;
1052 - var f = 0;
1053 - var j = 0;
1054 - for(i=0; i<2; i++){
1055 - if(userDB[userId][0][i] == "E"){
1056 - e++;
1057 - }
1058 - }
1059 - for(i=0; i<2; i++){
1060 - if(userDB[userId][1][i] == "N"){
1061 - n++;
1062 - }
1063 - }
1064 - for(i=0; i<1; i++){
1065 - if(userDB[userId][2][i] == "F"){
1066 - f++;
1067 - }
1068 - }
1069 - for(i=0; i<2; i++){
1070 - if(userDB[userId][3][i] == "J"){
1071 - j++;
1072 - }
1073 - }
1074 - var i = 2-e;
1075 - var s = 2-n;
1076 - var t = 1-f;
1077 - var p = 2-j;
1078 - mbtiper[0] += 20 * e;
1079 - mbtiper[1] += 20 * i;
1080 - mbtiper[2] += 20 * n;
1081 - mbtiper[3] += 20 * s;
1082 - mbtiper[4] += 20 * t;
1083 - mbtiper[5] += 20 * f;
1084 - mbtiper[6] += 20 * j;
1085 - mbtiper[7] += 20 * p;
1086 - if(mbtiper[0]>mbtiper[1]){
1087 - userDB[userId][4] += 'E';
1088 - } else {
1089 - userDB[userId][4] += 'I';
1090 - }
1091 - if(mbtiper[2]>mbtiper[3]){
1092 - userDB[userId][4] += 'N';
1093 - } else {
1094 - userDB[userId][4] += 'S';
1095 - }
1096 - if(mbtiper[4]>mbtiper[5]){
1097 - userDB[userId][4] += 'T';
1098 - } else {
1099 - userDB[userId][4] += 'F';
1100 - }
1101 - if(mbtiper[6]>mbtiper[7]){
1102 - userDB[userId][4] += 'J';
1103 - } else {
1104 - userDB[userId][4] += 'P';
1105 - }
1106 - const responseBody = {
1107 - version: "2.0",
1108 - template: {
1109 - outputs: [
1110 - {
1111 - simpleText: {
1112 - text: "당신의 MBTI는 : "+userDB[userId][4]
1113 - }
1114 - }
1115 - ],
1116 - quickReplies: [{
1117 - action: "block",
1118 - label: "MBTI 테스트 다시하기",
1119 - message: "MBTI 테스트 다시하기",
1120 - blockId : "62977ff05ceed96c385449b9"
1121 - },
1122 - {
1123 - action: "block",
1124 - label: "결과 상세보기",
1125 - message: "결과 상세보기",
1126 - blockId: "62987b78e7a0253c7662dcd9"
1127 - }]
1128 - }
1129 - }
1130 - res.status(200).send(responseBody);
1131 - });
1132 -
1133 -apiRouter.post('/percent', (req, res) => {
1134 - const responseBody = {
1135 - version: "2.0",
1136 - template: {
1137 - outputs: [
1138 - {
1139 - simpleText: {
1140 - text: 'E: '+mbtiper[0]+'%\nI: '+mbtiper[1]+'%\nN: '+mbtiper[2]+'%\nS: '+mbtiper[3]+'%\nT: '+mbtiper[4]+'%\nF: '+mbtiper[5]+'%\nJ: '+mbtiper[6]+'%\nP: '+mbtiper[7]+'%'
1141 - }
1142 - }
1143 - ]
1144 - }
1145 - }
1146 - res.status(200).send(responseBody);
1147 - });
1148 -
1149 -apiRouter.post('/result', (req, res) => {
1150 - var userId = req.body.userRequest.user.id;
1151 - var mesg = req.body.userRequest.utterance;
1152 - var mbti = '';
1153 - if (mesg == "네") {
1154 - mbti = 'J';
1155 - } else if (mesg == "아니오") {
1156 - mbti = 'P';
1157 - }
1158 - userDB[userId][3] += mbti;
1159 - console.log(userDB[userId]);
1160 - analysis_mbti(userDB[userId]);
1161 - const responseBody = {
1162 - version: "2.0",
1163 - template: {
1164 - outputs: [
1165 - {
1166 - simpleText: {
1167 - text: "당신의 MBTI는 : "+userDB[userId][4]
1168 -
1169 - }
1170 - }
1171 - ],
1172 - quickReplies: [{
1173 - action: "block",
1174 - label: "MBTI 테스트 다시하기",
1175 - message: "MBTI 테스트 다시하기",
1176 - blockId : "628b7ef293b31d5b60ab4b29" //to question 1
1177 - }]
1178 - }
1179 - }
1180 - res.status(200).send(responseBody);
1181 -});
1182 956
1183 function analysis_mbti(userdb) { 957 function analysis_mbti(userdb) {
1184 var e = count_mbti(userdb[0], 'E'); 958 var e = count_mbti(userdb[0], 'E');
1185 - var i = 1-e; //-> 5 959 + var i = 5-e;
1186 var n = count_mbti(userdb[1], 'N'); 960 var n = count_mbti(userdb[1], 'N');
1187 - var s = 1-n; //-> 5 961 + var s = 5-n;
1188 var f = count_mbti(userdb[2], 'F'); 962 var f = count_mbti(userdb[2], 'F');
1189 - var t = 2-f; //-> 5 963 + var t = 5-f;
1190 var j = count_mbti(userdb[3], 'J'); 964 var j = count_mbti(userdb[3], 'J');
1191 - var p = 2-j; //-> 5 965 + var p = 5-j;
1192 if (e > i) { 966 if (e > i) {
1193 userdb[4] += 'E'; 967 userdb[4] += 'E';
1194 } else { 968 } else {
......