Showing
2 changed files
with
56 additions
and
35 deletions
| ... | @@ -20,7 +20,7 @@ var app = http.createServer(function(request,response){ | ... | @@ -20,7 +20,7 @@ var app = http.createServer(function(request,response){ |
| 20 | } | 20 | } |
| 21 | else if(pathname === '/countKcal'){ | 21 | else if(pathname === '/countKcal'){ |
| 22 | var title = '칼로리 계산'; | 22 | var title = '칼로리 계산'; |
| 23 | - var description = '성별, 키, 몸무게, 활동량을 입력하시면 일일 권장 섭취량(kcal)를 알려드립니다!'; | 23 | + var description = '성별, 나이, 키, 몸무게, 활동량을 입력하시면 일일 권장 섭취량(kcal)를 알려드립니다!'; |
| 24 | var html = template.html(title,` | 24 | var html = template.html(title,` |
| 25 | <h2>${title}</h2> | 25 | <h2>${title}</h2> |
| 26 | <p>${description}</p> | 26 | <p>${description}</p> |
| ... | @@ -29,16 +29,18 @@ var app = http.createServer(function(request,response){ | ... | @@ -29,16 +29,18 @@ var app = http.createServer(function(request,response){ |
| 29 | <select name="gender"> | 29 | <select name="gender"> |
| 30 | <option value="man">남자</option> | 30 | <option value="man">남자</option> |
| 31 | <option value="woman">여자</option></select | 31 | <option value="woman">여자</option></select |
| 32 | - ><br /> | 32 | + ><br /> |
| 33 | + 나이(세) : <br /> | ||
| 34 | + <input type="text" name="age" /><br /> | ||
| 33 | 키(cm) : <br /> | 35 | 키(cm) : <br /> |
| 34 | <input type="text" name="height" /><br /> | 36 | <input type="text" name="height" /><br /> |
| 35 | 몸무게(kg) : <br /><input type="text" name="weight" /><br /> | 37 | 몸무게(kg) : <br /><input type="text" name="weight" /><br /> |
| 36 | 활동량 :<br /> | 38 | 활동량 :<br /> |
| 37 | <select name="activity"> | 39 | <select name="activity"> |
| 38 | - <option value="low">가벼운 활동(주로 앉아서 생활)</option> | 40 | + <option value="low">앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option> |
| 39 | - <option value="mid">중등 활동(주로 서서 일하거나 생활)</option> | 41 | + <option value="mid">활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option> |
| 40 | - <option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option> | 42 | + <option value="high">많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option> |
| 41 | - <option value="veryHigh">매우 많은 활동(운동선수)</option></select | 43 | + </select |
| 42 | ><br /> | 44 | ><br /> |
| 43 | <input type="submit" value="계산하기" /> | 45 | <input type="submit" value="계산하기" /> |
| 44 | </form>` ); | 46 | </form>` ); |
| ... | @@ -55,24 +57,49 @@ var app = http.createServer(function(request,response){ | ... | @@ -55,24 +57,49 @@ var app = http.createServer(function(request,response){ |
| 55 | request.on('end', function(){ | 57 | request.on('end', function(){ |
| 56 | var post = qs.parse(body); | 58 | var post = qs.parse(body); |
| 57 | var title = '칼로리 계산'; | 59 | var title = '칼로리 계산'; |
| 58 | - var description = '성별, 키, 몸무게, 활동량을 입력하시면 일일 권장 섭취량(kcal)를 알려드립니다!'; | 60 | + var description = '성별, 키, 몸무게, 활동량을 입력하시면 표준체중, 현재 체중을 유지하는데 필요한 열량, 다이어트 열량을 알려드립니다!'; |
| 59 | var gender = post.gender; | 61 | var gender = post.gender; |
| 62 | + var age = post.age; | ||
| 60 | var height = post.height; | 63 | var height = post.height; |
| 61 | var weight = post.weight; | 64 | var weight = post.weight; |
| 65 | + var BMR; //기초대사량(bmr) Harris-BenedictEquation(B.E.E) 방법 | ||
| 66 | + var BMI = (weight/(height*height)*10000).toFixed(1); //비만도 | ||
| 67 | + var BMI_msg = ''; | ||
| 68 | + if(BMI >= 30){ | ||
| 69 | + BMI_msg += '고도비만'; | ||
| 70 | + } | ||
| 71 | + else if(BMI >=25 && BMI <30){ | ||
| 72 | + BMI_msg += '비만'; | ||
| 73 | + } | ||
| 74 | + else if(BMI >=23 && BMI <25){ | ||
| 75 | + BMI_msg += '과체중'; | ||
| 76 | + } | ||
| 77 | + else if(BMI >=18.5 && BMI <23){ | ||
| 78 | + BMI_msg += '정상'; | ||
| 79 | + } | ||
| 80 | + else if(BMI >= 0 && BMI < 18.5){ | ||
| 81 | + BMI_msg += '저체중'; | ||
| 82 | + } | ||
| 83 | + else { | ||
| 84 | + BMI_msg += "Error"; | ||
| 85 | + } | ||
| 62 | var gender_default = ''; | 86 | var gender_default = ''; |
| 63 | if(gender == "man"){ | 87 | if(gender == "man"){ |
| 64 | gender_default = | 88 | gender_default = |
| 65 | `<option value="man" selected>남자</option> | 89 | `<option value="man" selected>남자</option> |
| 66 | <option value="woman">여자</option>`; | 90 | <option value="woman">여자</option>`; |
| 91 | + BMR = (66.5 + 13.75*weight + 5.003*height - 6.755*age).toFixed(1); | ||
| 67 | } | 92 | } |
| 68 | else { | 93 | else { |
| 69 | gender_default = | 94 | gender_default = |
| 70 | `<option value="man" >남자</option> | 95 | `<option value="man" >남자</option> |
| 71 | <option value="woman" selected>여자</option>`; | 96 | <option value="woman" selected>여자</option>`; |
| 97 | + BMR = (655. + 9.563*weight + 1.85*height - 4.676*age).toFixed(1); | ||
| 72 | } | 98 | } |
| 73 | var std_weight = (height*height/10000*((gender =="man") ? 22 : 21)).toFixed(1); //남자면 22, 여자면 21을 곱함. | 99 | var std_weight = (height*height/10000*((gender =="man") ? 22 : 21)).toFixed(1); //남자면 22, 여자면 21을 곱함. |
| 74 | var activity = post.activity; | 100 | var activity = post.activity; |
| 75 | var activity_idx; | 101 | var activity_idx; |
| 102 | + var TDEE; //Total Daily Energy Expenditure 현재 체중을 유지하기 위한 열량 | ||
| 76 | var activity_default = ''; | 103 | var activity_default = ''; |
| 77 | var weight_gap = (weight - std_weight).toFixed(1); | 104 | var weight_gap = (weight - std_weight).toFixed(1); |
| 78 | var weightMsg = ""; | 105 | var weightMsg = ""; |
| ... | @@ -87,44 +114,36 @@ var app = http.createServer(function(request,response){ | ... | @@ -87,44 +114,36 @@ var app = http.createServer(function(request,response){ |
| 87 | } | 114 | } |
| 88 | switch(activity){ | 115 | switch(activity){ |
| 89 | case "low": | 116 | case "low": |
| 90 | - activity_idx = 25; | 117 | + activity_idx = 1.53; |
| 118 | + TDEE = (BMR*activity_idx).toFixed(1); | ||
| 91 | activity_default = ` | 119 | activity_default = ` |
| 92 | - <option value="low" selected>가벼운 활동(주로 앉아서 생활)</option> | 120 | + <option value="low" selected>앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option> |
| 93 | - <option value="mid">중등 활동(주로 서서 일하거나 생활)</option> | 121 | + <option value="mid">활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option> |
| 94 | - <option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option> | 122 | + <option value="high">활발히 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option> |
| 95 | - <option value="veryHigh">매우 많은 활동(운동선수)</option></select> | 123 | + </select> |
| 96 | ` | 124 | ` |
| 97 | break; | 125 | break; |
| 98 | case "mid": | 126 | case "mid": |
| 99 | - activity_idx = 30; | 127 | + activity_idx = 1.76; |
| 100 | - activity_default = ` | 128 | + TDEE = (BMR*activity_idx).toFixed(1); |
| 101 | - <option value="low" >가벼운 활동(주로 앉아서 생활)</option> | ||
| 102 | - <option value="mid" selected>중등 활동(주로 서서 일하거나 생활)</option> | ||
| 103 | - <option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option> | ||
| 104 | - <option value="veryHigh">매우 많은 활동(운동선수)</option></select> | ||
| 105 | - ` | ||
| 106 | - break; | ||
| 107 | - case "high": | ||
| 108 | - activity_idx = 35; | ||
| 109 | activity_default = ` | 129 | activity_default = ` |
| 110 | - <option value="low" >가벼운 활동(주로 앉아서 생활)</option> | 130 | + <option value="low" >앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option> |
| 111 | - <option value="mid" >중등 활동(주로 서서 일하거나 생활)</option> | 131 | + <option value="mid" selected>활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option> |
| 112 | - <option value="high" selected>많은 활동(건설, 농업 등 노동이 많은 일)</option> | 132 | + <option value="high">많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option> |
| 113 | - <option value="veryHigh">매우 많은 활동(운동선수)</option></select> | 133 | + </select> |
| 114 | ` | 134 | ` |
| 115 | break; | 135 | break; |
| 116 | default: | 136 | default: |
| 117 | - activity_idx = 40; | 137 | + activity_idx = 2.25; |
| 138 | + TDEE = (BMR*activity_idx).toFixed(1); | ||
| 118 | activity_default = ` | 139 | activity_default = ` |
| 119 | - <option value="low" >가벼운 활동(주로 앉아서 생활)</option> | 140 | + <option value="low" >앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option> |
| 120 | - <option value="mid" >중등 활동(주로 서서 일하거나 생활)</option> | 141 | + <option value="mid" >활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option> |
| 121 | - <option value="high" >많은 활동(건설, 농업 등 노동이 많은 일)</option> | 142 | + <option value="high" selected>많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option> |
| 122 | - <option value="veryHigh" selected>매우 많은 활동(운동선수)</option></select> | 143 | + </select> |
| 123 | ` | 144 | ` |
| 124 | } | 145 | } |
| 125 | - | 146 | + |
| 126 | - | ||
| 127 | - var recommended_kcal_day = (std_weight*activity_idx).toFixed(); | ||
| 128 | var html = template.html(title,` | 147 | var html = template.html(title,` |
| 129 | <h2>${title}</h2> | 148 | <h2>${title}</h2> |
| 130 | <p>${description}</p> | 149 | <p>${description}</p> |
| ... | @@ -144,7 +163,9 @@ var app = http.createServer(function(request,response){ | ... | @@ -144,7 +163,9 @@ var app = http.createServer(function(request,response){ |
| 144 | <br> | 163 | <br> |
| 145 | 표준체중 : ${std_weight}kg <br> | 164 | 표준체중 : ${std_weight}kg <br> |
| 146 | ${weightMsg}<br> | 165 | ${weightMsg}<br> |
| 147 | - 하루 권장 섭취량 : ${recommended_kcal_day}kcal | 166 | + BMI 지수 : ${BMI} / 당신은 ${BMI_msg} 입니다. <br> |
| 167 | + 기초 대사량 : ${BMR}kcal <br> | ||
| 168 | + 현재 체중 유지를 위한 열량 : ${TDEE}kcal <br> | ||
| 148 | </form> | 169 | </form> |
| 149 | ` ); | 170 | ` ); |
| 150 | 171 | ... | ... |
File moved
-
Please register or login to post a comment