Minkyung Ko

Edit percent code

Showing 1 changed file with 33 additions and 24 deletions
...@@ -328,6 +328,7 @@ apiRouter.post('/question14', (req, res) => { ...@@ -328,6 +328,7 @@ apiRouter.post('/question14', (req, res) => {
328 apiRouter.post('/result', (req, res) => { 328 apiRouter.post('/result', (req, res) => {
329 var mesg = req.body.userRequest.utterance; 329 var mesg = req.body.userRequest.utterance;
330 var userId = req.body.userRequest.user.id; 330 var userId = req.body.userRequest.user.id;
331 + mbtiper = ['','','','','','','',''];
331 var mbti = ''; 332 var mbti = '';
332 if (mesg == "네"){ 333 if (mesg == "네"){
333 mbti = 'N'; 334 mbti = 'N';
...@@ -336,24 +337,42 @@ apiRouter.post('/result', (req, res) => { ...@@ -336,24 +337,42 @@ apiRouter.post('/result', (req, res) => {
336 mbti = 'S'; 337 mbti = 'S';
337 } 338 }
338 userDB[userId][1] += mbti; 339 userDB[userId][1] += mbti;
339 - console.log(userDB[userId]); 340 + var e = 0;
340 - console.log(mbtiper); 341 + var n = 0;
341 - var e = calc(userDB[userId], 'E'); 342 + var f = 0;
343 + var j = 0;
344 + for(i=0; i<2; i++){
345 + if(userDB[userId][0][i] == "E"){
346 + e++;
347 + }
348 + }
349 + for(i=0; i<2; i++){
350 + if(userDB[userId][1][i] == "N"){
351 + n++;
352 + }
353 + }
354 + for(i=0; i<1; i++){
355 + if(userDB[userId][2][i] == "F"){
356 + f++;
357 + }
358 + }
359 + for(i=0; i<2; i++){
360 + if(userDB[userId][3][i] == "J"){
361 + j++;
362 + }
363 + }
342 var i = 2-e; 364 var i = 2-e;
343 - var n = calc(userDB[userId], 'N');
344 var s = 2-n; 365 var s = 2-n;
345 - var f = calc(userDB[userId], 'F');
346 var t = 1-f; 366 var t = 1-f;
347 - var j = calc(userDB[userId], 'J');
348 var p = 2-j; 367 var p = 2-j;
349 - mbtiper.push(20 * e); 368 + mbtiper[0] += 20 * e;
350 - mbtiper.push(20 * i); 369 + mbtiper[1] += 20 * i;
351 - mbtiper.push(20 * n); 370 + mbtiper[2] += 20 * n;
352 - mbtiper.push(20 * s); 371 + mbtiper[3] += 20 * s;
353 - mbtiper.push(20 * f); 372 + mbtiper[4] += 20 * t;
354 - mbtiper.push(20 * t); 373 + mbtiper[5] += 20 * f;
355 - mbtiper.push(20 * j); 374 + mbtiper[6] += 20 * j;
356 - mbtiper.push(20 * p); 375 + mbtiper[7] += 20 * p;
357 if(mbtiper[0]>mbtiper[1]){ 376 if(mbtiper[0]>mbtiper[1]){
358 userDB[userId][4] += 'E'; 377 userDB[userId][4] += 'E';
359 } else { 378 } else {
...@@ -401,16 +420,6 @@ apiRouter.post('/result', (req, res) => { ...@@ -401,16 +420,6 @@ apiRouter.post('/result', (req, res) => {
401 res.status(200).send(responseBody); 420 res.status(200).send(responseBody);
402 }); 421 });
403 422
404 - function calc(array, mbti_cap) {
405 - var result = 0;
406 - for (var k = 0; k < 5; k++) {
407 - if(array[k] == 'mbti_cap') {
408 - result += 1;
409 - }
410 - }
411 - return result;
412 -}
413 -
414 apiRouter.post('/percent', (req, res) => { 423 apiRouter.post('/percent', (req, res) => {
415 const responseBody = { 424 const responseBody = {
416 version: "2.0", 425 version: "2.0",
......