김동진

countKcal 기능 안정화

...@@ -117,3 +117,7 @@ dist ...@@ -117,3 +117,7 @@ dist
117 117
118 118
119 package-lock.json 119 package-lock.json
120 +
121 +#db
122 +lib/db.js
123 +lib/appkey.js
...\ No newline at end of file ...\ No newline at end of file
......
1 var key = { 1 var key = {
2 kakaomapKey : "900b1f5dd2fee32f1ee91d18266bbfe4", 2 kakaomapKey : "900b1f5dd2fee32f1ee91d18266bbfe4",
3 - kakaoRestKey : "ab6b32bc5d4705f517ee753c63be465c",
4 }; 3 };
5 4
6 module.exports = key; //key을 바깥에서 사용할 수 있도록 exports한다. 5 module.exports = key; //key을 바깥에서 사용할 수 있도록 exports한다.
......
1 var qs = require('querystring'); 1 var qs = require('querystring');
2 var template = require('./template.js'); 2 var template = require('./template.js');
3 var db = require('./db.js'); 3 var db = require('./db.js');
4 +const { type } = require('jquery');
4 exports.countKcal = function(request, response){ 5 exports.countKcal = function(request, response){
5 var title = '칼로리 계산'; 6 var title = '칼로리 계산';
6 var description = '맞춤 권장 칼로리와 섭취 음식 칼로리 중 하나를 선택해 주세요.'; 7 var description = '맞춤 권장 칼로리와 섭취 음식 칼로리 중 하나를 선택해 주세요.';
...@@ -22,12 +23,6 @@ exports.countKcal = function(request, response){ ...@@ -22,12 +23,6 @@ exports.countKcal = function(request, response){
22 } 23 }
23 </style> 24 </style>
24 </head> 25 </head>
25 -
26 -
27 -
28 - <br><br>
29 - <hr width = "100%" color ="#213b19">
30 - <br><br>
31 <style type="text/css"> 26 <style type="text/css">
32 div{ 27 div{
33 28
...@@ -73,7 +68,6 @@ exports.countKcal_body = function(request, response){ ...@@ -73,7 +68,6 @@ exports.countKcal_body = function(request, response){
73 var title = '칼로리 계산'; 68 var title = '칼로리 계산';
74 var description = '개인의 신체 정보에 맞는 일일 권장 섭취량(kcal)를 알려드립니다!'; 69 var description = '개인의 신체 정보에 맞는 일일 권장 섭취량(kcal)를 알려드립니다!';
75 var html = template.html(title,` 70 var html = template.html(title,`
76 - <br><br><br>
77 <div style= "font-size:20px;"> 71 <div style= "font-size:20px;">
78 72
79 <h2><font color="black">${title}<br><div style= "font-size:20px;"><br>${description}</font></div></h2> 73 <h2><font color="black">${title}<br><div style= "font-size:20px;"><br>${description}</font></div></h2>
...@@ -121,6 +115,7 @@ exports.countKcal_body_process = function(request, response){ ...@@ -121,6 +115,7 @@ exports.countKcal_body_process = function(request, response){
121 var targetWeight = post.targetWeight; 115 var targetWeight = post.targetWeight;
122 var BMR; //기초대사량(bmr) Harris-BenedictEquation(B.E.E) 방법 116 var BMR; //기초대사량(bmr) Harris-BenedictEquation(B.E.E) 방법
123 var BMI = (weight/(height*height)*10000).toFixed(1); //비만도 117 var BMI = (weight/(height*height)*10000).toFixed(1); //비만도
118 + BMI = Number(BMI);
124 var BMI_msg = ''; 119 var BMI_msg = '';
125 if(BMI >= 30){ 120 if(BMI >= 30){
126 BMI_msg += '고도비만'; 121 BMI_msg += '고도비만';
...@@ -153,12 +148,13 @@ exports.countKcal_body_process = function(request, response){ ...@@ -153,12 +148,13 @@ exports.countKcal_body_process = function(request, response){
153 <option value="woman" selected>여자</option>`; 148 <option value="woman" selected>여자</option>`;
154 BMR = (655. + 9.563*weight + 1.85*height - 4.676*age).toFixed(1); 149 BMR = (655. + 9.563*weight + 1.85*height - 4.676*age).toFixed(1);
155 } 150 }
156 - var std_weight = (height*height/10000*((gender =="man") ? 22 : 21)).toFixed(1); //남자면 22, 여자면 21을 곱함. 151 + BMR = Number(BMR);
152 + var std_weight = Number((height*height/10000*((gender =="man") ? 22 : 21)).toFixed(1)); //남자면 22, 여자면 21을 곱함.
157 var activity = post.activity; 153 var activity = post.activity;
158 var activity_idx; 154 var activity_idx;
159 - var TDEE; //Total Daily Energy Expenditure 현재 체중을 유지하기 위한 열량 155 + var TDEE = 0; //Total Daily Energy Expenditure 현재 체중을 유지하기 위한 열량
160 var activity_default = ''; 156 var activity_default = '';
161 - var weight_gap = (weight - std_weight).toFixed(1); 157 + var weight_gap = Number((weight - std_weight).toFixed(1));
162 var weightMsg = ""; 158 var weightMsg = "";
163 if(weight_gap > 0){ 159 if(weight_gap > 0){
164 weightMsg += `표준 체중보다 ${weight_gap}kg 많습니다.` 160 weightMsg += `표준 체중보다 ${weight_gap}kg 많습니다.`
...@@ -197,36 +193,48 @@ exports.countKcal_body_process = function(request, response){ ...@@ -197,36 +193,48 @@ exports.countKcal_body_process = function(request, response){
197 <option value="high" selected>많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option> 193 <option value="high" selected>많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option>
198 ` 194 `
199 } 195 }
196 + TDEE = Number(TDEE);
200 var totalKcal; //빼거나 쪄야할 총 칼로리 197 var totalKcal; //빼거나 쪄야할 총 칼로리
201 var foodKcal; //하루에 더 먹거나 덜 먹어야할 칼로리 198 var foodKcal; //하루에 더 먹거나 덜 먹어야할 칼로리
202 - var kcalMsg = '하루에 먹어야할 ' 199 + var kcalMsg = '하루에 먹어야할 ';
203 if(weight > targetWeight){ 200 if(weight > targetWeight){
204 totalKcal = (weight - targetWeight)*7700; //빼야할 총 칼로리/다이어트 201 totalKcal = (weight - targetWeight)*7700; //빼야할 총 칼로리/다이어트
205 - foodKcal = (totalKcal/targetDay).toFixed(1); 202 + foodKcal = Number((totalKcal/targetDay).toFixed(1));
206 kcalMsg += `다이어트 칼로리 : ${(TDEE - foodKcal).toFixed(1)}kcal`; 203 kcalMsg += `다이어트 칼로리 : ${(TDEE - foodKcal).toFixed(1)}kcal`;
207 } 204 }
208 else if(weight == targetWeight) { 205 else if(weight == targetWeight) {
209 -
210 kcalMsg =""; 206 kcalMsg ="";
211 } 207 }
212 else if(weight < targetWeight) { 208 else if(weight < targetWeight) {
213 totalKcal = (targetWeight-weight)*7700; //쩌야할 총 칼로리/벌크업 209 totalKcal = (targetWeight-weight)*7700; //쩌야할 총 칼로리/벌크업
214 - foodKcal = (totalKcal/targetDay).toFixed(1); 210 + foodKcal = Number((totalKcal/targetDay).toFixed(1));
215 - kcalMsg += `벌크업 칼로리 : ${(TDEE - foodKcal).toFixed(1)}kcal`; 211 + var bulkUpKcal = foodKcal+TDEE;
212 +
213 + kcalMsg += `벌크업 칼로리 : ${(bulkUpKcal)}kcal`;
216 } 214 }
217 var html = template.html(title,` 215 var html = template.html(title,`
218 <h2>${title}</h2> 216 <h2>${title}</h2>
219 <p>${description}</p> 217 <p>${description}</p>
218 + <script>
219 + var msg = '${kcalMsg}';
220 +
221 + if(msg==""){
222 + msg = '현재 체중 유지를 위한 열량 : ${TDEE}kcal'
223 + }
224 + sessionStorage.setItem('KcalMsg', msg);
225 + </script>
220 <form action="/countKcal_body_process" method="post" > 226 <form action="/countKcal_body_process" method="post" >
227 + 나이(세) : <br />
228 + <input type="text" name="age" value="${age}"/><br />
221 성별 :<br /> 229 성별 :<br />
222 <select name="gender"> 230 <select name="gender">
223 ${gender_default} 231 ${gender_default}
224 </select> 232 </select>
225 <br /> 233 <br />
226 - 키(cm) : <br /><input type="text" name="height" placeholder="${height}" /><br /> 234 + 키(cm) : <br /><input type="text" name="height" value="${height}" /><br />
227 - 몸무게(kg) : <br /><input type="text" name="weight" placeholder="${weight}"/><br /> 235 + 몸무게(kg) : <br /><input type="text" name="weight" value="${weight}"/><br />
228 - 목표체중(kg) : <br /><input type="text" name="targetWeight" placeholder="${targetWeight}"/><br /> 236 + 목표체중(kg) : <br /><input type="text" name="targetWeight" value="${targetWeight}"/><br />
229 - 목표기간(일) : <br /><input type="text" name="targetDay" placeholder="${targetDay}"/><br /> 237 + 목표기간(일) : <br /><input type="text" name="targetDay" value="${targetDay}"/><br />
230 활동량 :<br /> 238 활동량 :<br />
231 <select name="activity"> 239 <select name="activity">
232 ${activity_default} 240 ${activity_default}
...@@ -254,7 +262,6 @@ exports.countKcal_food = function(request,response){ ...@@ -254,7 +262,6 @@ exports.countKcal_food = function(request,response){
254 var title = '음식 칼로리 계산'; 262 var title = '음식 칼로리 계산';
255 var description = '오늘 먹은 음식의 총 칼로리를 계산해드립니다!'; 263 var description = '오늘 먹은 음식의 총 칼로리를 계산해드립니다!';
256 var html = template.html(title,` 264 var html = template.html(title,`
257 - <br><br><br>
258 <h2>${title}</h2> 265 <h2>${title}</h2>
259 <p>${description}</p> 266 <p>${description}</p>
260 <form action="/countKcal_food_process" method="post"> 267 <form action="/countKcal_food_process" method="post">
...@@ -391,7 +398,7 @@ function foodTable(foodInfo, list, num){ ...@@ -391,7 +398,7 @@ function foodTable(foodInfo, list, num){
391 +'</td><td>'+kcal+'</td></tr>'; 398 +'</td><td>'+kcal+'</td></tr>';
392 var str = sessionStorage.getItem('table'); 399 var str = sessionStorage.getItem('table');
393 str = str.replace(table,''); 400 str = str.replace(table,'');
394 - console.log("str:"+str) 401 + //console.log("str:"+str)
395 sessionStorage.setItem('table',str); 402 sessionStorage.setItem('table',str);
396 clickedRow.remove(); 403 clickedRow.remove();
397 cntRm += 1; 404 cntRm += 1;
...@@ -411,7 +418,12 @@ function foodTable(foodInfo, list, num){ ...@@ -411,7 +418,12 @@ function foodTable(foodInfo, list, num){
411 var td = tr.children(); 418 var td = tr.children();
412 totalKcal +=Number(td.eq(5).text()) 419 totalKcal +=Number(td.eq(5).text())
413 }); 420 });
414 - $("#selectedFood").after("<p>총 칼로리 : "+ totalKcal.toFixed(2) +"kcal</p>"); 421 + var KcalMsg = sessionStorage.getItem('KcalMsg');
422 + //console.log("kcalMsg:"+KcalMsg);
423 + if (KcalMsg == null){
424 + KcalMsg = "<a href='/countKcal_body'>맞춤 권장 칼로리 계산하러 가기</a>"
425 + }
426 + $("#WriteTotalKcal").html("<p>총 칼로리 : "+ Number(totalKcal.toFixed(2)) +"kcal</p><p>"+KcalMsg+"</p>")
415 //console.log("totalKcal:"+totalKcal); 427 //console.log("totalKcal:"+totalKcal);
416 }); 428 });
417 //console.log(sessionStorage.getItem('table')); 429 //console.log(sessionStorage.getItem('table'));
...@@ -434,6 +446,8 @@ function foodTable(foodInfo, list, num){ ...@@ -434,6 +446,8 @@ function foodTable(foodInfo, list, num){
434 <td>칼로리(kcal)</td> 446 <td>칼로리(kcal)</td>
435 </tr> 447 </tr>
436 </table> 448 </table>
449 +
450 + <div id = "WriteTotalKcal" style=text-align:left;></div>
437 <style> 451 <style>
438 table{ 452 table{
439 border-collapse: collapse; 453 border-collapse: collapse;
......
...@@ -5,18 +5,15 @@ exports.foodInfo = function(request, response){ ...@@ -5,18 +5,15 @@ exports.foodInfo = function(request, response){
5 var title = '음식 영양정보'; 5 var title = '음식 영양정보';
6 var description = '음식을 검색하면 음식의 칼로리, 탄수화물, 단백질, 지방, 나트륨의 정보를 알려드립니다!'; 6 var description = '음식을 검색하면 음식의 칼로리, 탄수화물, 단백질, 지방, 나트륨의 정보를 알려드립니다!';
7 var html = template.html(title,` 7 var html = template.html(title,`
8 - <br><br><br>
9 <h2>${title}</h2> 8 <h2>${title}</h2>
10 <p>${description}</p> 9 <p>${description}</p>
11 <form action="/foodInfo_search" method="post"> 10 <form action="/foodInfo_search" method="post">
12 <input type = 'text' name = 'search' placeholder = '검색어 입력' maxlength = 255 value = "" autocomplete = "off"> 11 <input type = 'text' name = 'search' placeholder = '검색어 입력' maxlength = 255 value = "" autocomplete = "off">
13 <button type = "submit" name = "click">검색</button> 12 <button type = "submit" name = "click">검색</button>
14 </form> 13 </form>
15 -
16 `); 14 `);
17 response.writeHead(200); 15 response.writeHead(200);
18 response.end(html); 16 response.end(html);
19 -
20 } 17 }
21 function foodTable(foodInfo, list, num){ 18 function foodTable(foodInfo, list, num){
22 var tag = ''; 19 var tag = '';
...@@ -61,7 +58,6 @@ function foodTable(foodInfo, list, num){ ...@@ -61,7 +58,6 @@ function foodTable(foodInfo, list, num){
61 `; 58 `;
62 return tag; 59 return tag;
63 } 60 }
64 -
65 exports.foodInfo_search = function(request, response){ 61 exports.foodInfo_search = function(request, response){
66 var body = ''; 62 var body = '';
67 request.on('data', function(data){ 63 request.on('data', function(data){
...@@ -85,7 +81,6 @@ exports.foodInfo_search = function(request, response){ ...@@ -85,7 +81,6 @@ exports.foodInfo_search = function(request, response){
85 } 81 }
86 } 82 }
87 var html = template.html(title,` 83 var html = template.html(title,`
88 - <br><br><br>
89 <h2>${title}</h2> 84 <h2>${title}</h2>
90 <p>${description}</p> 85 <p>${description}</p>
91 <form action="/foodInfo_search" method="post"> 86 <form action="/foodInfo_search" method="post">
......
...@@ -3,9 +3,6 @@ exports.home = function(request, response){ ...@@ -3,9 +3,6 @@ exports.home = function(request, response){
3 var title = 'HealthProtector란?'; 3 var title = 'HealthProtector란?';
4 var description = '개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.'; 4 var description = '개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.';
5 var html = template.html(title,` 5 var html = template.html(title,`
6 -
7 - <br><br><br>
8 -
9 <style> 6 <style>
10 @import url('https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap'); 7 @import url('https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap');
11 8
...@@ -28,8 +25,6 @@ exports.home = function(request, response){ ...@@ -28,8 +25,6 @@ exports.home = function(request, response){
28 } 25 }
29 </div> 26 </div>
30 </style> 27 </style>
31 -
32 -
33 <div style= font-size:40px;background-image:url("https://source.unsplash.com/jFCViYFYcus");padding:50px;> 28 <div style= font-size:40px;background-image:url("https://source.unsplash.com/jFCViYFYcus");padding:50px;>
34 29
35 <h1 style=font-family: 'Do Hyeon', sans-serif;><a href="/"><font color="white">HealthProtector</font></a></h1> 30 <h1 style=font-family: 'Do Hyeon', sans-serif;><a href="/"><font color="white">HealthProtector</font></a></h1>
...@@ -38,9 +33,7 @@ exports.home = function(request, response){ ...@@ -38,9 +33,7 @@ exports.home = function(request, response){
38 <div style= font-size:20px;text-align:left;width: 100%;float:left:> 33 <div style= font-size:20px;text-align:left;width: 100%;float:left:>
39 <h2><font color="black">&nbsp &nbsp &nbspOur Services</font></h2> 34 <h2><font color="black">&nbsp &nbsp &nbspOur Services</font></h2>
40 </div> 35 </div>
41 -
42 36
43 -
44 <div style= width:30%;float:left;padding:5px;> 37 <div style= width:30%;float:left;padding:5px;>
45 <div style="color : gray";> 38 <div style="color : gray";>
46 <i class="fas fa-calculator fa-3x"></i> 39 <i class="fas fa-calculator fa-3x"></i>
......
...@@ -7,9 +7,7 @@ exports.searchGym = function(request, response){ ...@@ -7,9 +7,7 @@ exports.searchGym = function(request, response){
7 <style> 7 <style>
8 @import url('https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap'); 8 @import url('https://fonts.googleapis.com/css2?family=Do+Hyeon&display=swap');
9 </style> 9 </style>
10 - <br><br>
11 <div style= "font-size:25px; background-color:#ffffff"> 10 <div style= "font-size:25px; background-color:#ffffff">
12 -
13 <h2><font color="black">${title}<br><div style= "font-size:20px;font-family: 'Do Hyeon', sans-serif;">${description}</font></div></h2> 11 <h2><font color="black">${title}<br><div style= "font-size:20px;font-family: 'Do Hyeon', sans-serif;">${description}</font></div></h2>
14 </div> 12 </div>
15 <style> 13 <style>
......
...@@ -18,7 +18,6 @@ module.exports = { ...@@ -18,7 +18,6 @@ module.exports = {
18 18
19 <style type="text/css"> 19 <style type="text/css">
20 div{ 20 div{
21 -
22 text-align:center; 21 text-align:center;
23 border:1px solid none; 22 border:1px solid none;
24 margin:0px 0px 0px 0px; 23 margin:0px 0px 0px 0px;
...@@ -28,7 +27,6 @@ module.exports = { ...@@ -28,7 +27,6 @@ module.exports = {
28 } 27 }
29 </div> 28 </div>
30 </style> 29 </style>
31 -
32 <div style="font-family: 'Do Hyeon', sans-serif;";> 30 <div style="font-family: 'Do Hyeon', sans-serif;";>
33 31
34 <h3 style=width:180px;float:left;><a href="/"><font color="black">HealthProtector</font></a></h3> 32 <h3 style=width:180px;float:left;><a href="/"><font color="black">HealthProtector</font></a></h3>
...@@ -38,7 +36,7 @@ module.exports = { ...@@ -38,7 +36,7 @@ module.exports = {
38 <h3 style=width:150px;float:right;><a href="/"><font color="black">About us</font></a></h3> 36 <h3 style=width:150px;float:right;><a href="/"><font color="black">About us</font></a></h3>
39 37
40 </div> 38 </div>
41 - 39 + <hr width = "100%" color ="#213b19" style=margin:0px;>
42 ${body} 40 ${body}
43 <div style= width:100%;font-size:9px;position:fixed;bottom:0;float:left;padding:0px;background-color:#213b19;> 41 <div style= width:100%;font-size:9px;position:fixed;bottom:0;float:left;padding:0px;background-color:#213b19;>
44 <h5><font color="white" font size = 2px;>Copyright(C) HealThProtector 2020</font></h5> 42 <h5><font color="white" font size = 2px;>Copyright(C) HealThProtector 2020</font></h5>
......
...@@ -43,6 +43,9 @@ var app = http.createServer(function(request,response){ ...@@ -43,6 +43,9 @@ var app = http.createServer(function(request,response){
43 else if(pathname === '/countKcal_food_process'){ 43 else if(pathname === '/countKcal_food_process'){
44 countKcal.countKcal_food_process(request,response); 44 countKcal.countKcal_food_process(request,response);
45 } 45 }
46 + else if(pathname === '/aboutUs'){
47 + home.aboutUs(request, response);
48 + }
46 else{ 49 else{
47 response.writeHead(404); 50 response.writeHead(404);
48 response.end("Not found"); 51 response.end("Not found");
......