김동진

first commit 간단한 칼로리 계산 기능 구현

1 +# Logs
2 +logs
3 +*.log
4 +npm-debug.log*
5 +yarn-debug.log*
6 +yarn-error.log*
7 +lerna-debug.log*
8 +
9 +# Diagnostic reports (https://nodejs.org/api/report.html)
10 +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11 +
12 +# Runtime data
13 +pids
14 +*.pid
15 +*.seed
16 +*.pid.lock
17 +
18 +# Directory for instrumented libs generated by jscoverage/JSCover
19 +lib-cov
20 +
21 +# Coverage directory used by tools like istanbul
22 +coverage
23 +*.lcov
24 +
25 +# nyc test coverage
26 +.nyc_output
27 +
28 +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29 +.grunt
30 +
31 +# Bower dependency directory (https://bower.io/)
32 +bower_components
33 +
34 +# node-waf configuration
35 +.lock-wscript
36 +
37 +# Compiled binary addons (https://nodejs.org/api/addons.html)
38 +build/Release
39 +
40 +# Dependency directories
41 +node_modules/
42 +jspm_packages/
43 +
44 +# Snowpack dependency directory (https://snowpack.dev/)
45 +web_modules/
46 +
47 +# TypeScript cache
48 +*.tsbuildinfo
49 +
50 +# Optional npm cache directory
51 +.npm
52 +
53 +# Optional eslint cache
54 +.eslintcache
55 +
56 +# Microbundle cache
57 +.rpt2_cache/
58 +.rts2_cache_cjs/
59 +.rts2_cache_es/
60 +.rts2_cache_umd/
61 +
62 +# Optional REPL history
63 +.node_repl_history
64 +
65 +# Output of 'npm pack'
66 +*.tgz
67 +
68 +# Yarn Integrity file
69 +.yarn-integrity
70 +
71 +# dotenv environment variables file
72 +.env
73 +.env.test
74 +
75 +# parcel-bundler cache (https://parceljs.org/)
76 +.cache
77 +.parcel-cache
78 +
79 +# Next.js build output
80 +.next
81 +out
82 +
83 +# Nuxt.js build / generate output
84 +.nuxt
85 +dist
86 +
87 +# Gatsby files
88 +.cache/
89 +# Comment in the public line in if your project uses Gatsby and not Next.js
90 +# https://nextjs.org/blog/next-9-1#public-directory-support
91 +# public
92 +
93 +# vuepress build output
94 +.vuepress/dist
95 +
96 +# Serverless directories
97 +.serverless/
98 +
99 +# FuseBox cache
100 +.fusebox/
101 +
102 +# DynamoDB Local files
103 +.dynamodb/
104 +
105 +# TernJS port file
106 +.tern-port
107 +
108 +# Stores VSCode versions used for testing VSCode extensions
109 +.vscode-test
110 +
111 +# yarn v2
112 +.yarn/cache
113 +.yarn/unplugged
114 +.yarn/build-state.yml
115 +.yarn/install-state.gz
116 +.pnp.*
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <title>HealthProtectorHome</title>
5 + <meta charset="utf-8" />
6 + </head>
7 + <body>
8 + <h1><a href="home.html">HealthProtector</a></h1>
9 + <ol>
10 + <li><a href="1.html">칼로리 계산</a></li>
11 + <li><a href="2.html">음식별 영양정보</a></li>
12 + </ol>
13 + <h2>칼로리 계산</h2>
14 + <form action="./3.html">
15 + 성별 :<br />
16 + <select name="sex">
17 + <option value="man">남자</option>
18 + <option value="woman">여자</option></select
19 + ><br />
20 + 키(cm) : <br />
21 + <input type="text" name="height" /><br />
22 + 몸무게(kg) : <br /><input type="text" name="weight" /><br />
23 + 활동량 :<br />
24 + <select name="activity">
25 + <option value="low">가벼운 활동(주로 앉아서 생활)</option>
26 + <option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
27 + <option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
28 + <option value="veryHigh">매우 많은 활동(운동선수)</option></select
29 + ><br />
30 + <input type="submit" value="계산하기" />
31 + </form>
32 + </body>
33 +</html>
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <title>HealthProtectorHome</title>
5 + <meta charset="utf-8" />
6 + </head>
7 + <body>
8 + <h1><a href="home.html">HealthProtector</a></h1>
9 + <ol>
10 + <li><a href="1.html">칼로리 계산</a></li>
11 + <li><a href="2.html">음식별 영양정보</a></li>
12 + </ol>
13 + <h2>음식별 영양정보</h2>
14 + <p>개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.</p>
15 + </body>
16 +</html>
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <title>HealthProtectorHome</title>
5 + <meta charset="utf-8" />
6 + </head>
7 + <body>
8 + <h1><a href="home.html">HealthProtector</a></h1>
9 + <ol>
10 + <li><a href="1.html">칼로리 계산</a></li>
11 + <li><a href="2.html">음식별 영양정보</a></li>
12 + </ol>
13 + <h2>칼로리 계산</h2>
14 + <form action="./3.html">
15 + 성별 :<br />
16 + <select name="sex">
17 + <option value="man">남자</option>
18 + <option value="woman">여자</option></select
19 + ><br />
20 + 키(cm) : <br />
21 + <input type="text" name="height" /><br />
22 + 몸무게(kg) : <br /><input type="text" name="weight" /><br />
23 + 활동량 :<br />
24 + <select name="activity">
25 + <option value="low">가벼운 활동(주로 앉아서 생활)</option>
26 + <option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
27 + <option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
28 + <option value="veryHigh">매우 많은 활동(운동선수)</option></select
29 + ><br />
30 + <input type="submit" value="계산하기" />
31 + </form>
32 + 일일 권장 섭취량 :
33 + </body>
34 +</html>
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <title>HealthProtectorHome</title>
5 + <meta charset="utf-8" />
6 + </head>
7 + <body>
8 + <h1><a href="home.html">HealthProtector</a></h1>
9 + <ol>
10 + <li><a href="1.html">칼로리 계산</a></li>
11 + <li><a href="2.html">음식별 영양정보</a></li>
12 + </ol>
13 + <h2>소개</h2>
14 + <p>개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.</p>
15 + </body>
16 +</html>
1 +module.exports = {
2 + html:function(title, body){
3 + return `
4 + <!DOCTYPE html>
5 + <html>
6 + <head>
7 + <title>HelP - ${title}</title>
8 + <meta charset="utf-8" />
9 + </head>
10 + <body>
11 + <h1><a href="/">HealthProtector</a></h1>
12 + <ol>
13 + <li><a href="/countKcal">칼로리 계산</a></li>
14 + <li><a href="2.html">음식별 영양정보</a></li>
15 + </ol>
16 + ${body}
17 + </body>
18 + </html>
19 +
20 + `
21 + }
22 +}
...\ No newline at end of file ...\ No newline at end of file
1 +var http = require('http');
2 +var fs = require('fs');
3 +var url = require('url');
4 +var qs = require('querystring');
5 +var template = require('./lib/template.js');
6 +var app = http.createServer(function(request,response){
7 + var _url = request.url;
8 + var queryData = url.parse(_url, true).query;
9 + var pathname = url.parse(_url, true).pathname;
10 + if(pathname === '/'){
11 + if(queryData.id === undefined){
12 + var title = '소개';
13 + var description = '개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.';
14 + var html = template.html(title,`
15 + <h2>${title}</h2>
16 + <p>${description}</p>` );
17 + response.writeHead(200);
18 + response.end(html);
19 + }
20 + }
21 + else if(pathname === '/countKcal'){
22 + var title = '칼로리 계산';
23 + var description = '성별, 키, 몸무게, 활동량을 입력하시면 일일 권장 섭취량(kcal)를 알려드립니다!';
24 + var html = template.html(title,`
25 + <h2>${title}</h2>
26 + <p>${description}</p>
27 + <form action="/countKcal_process" method="post" >
28 + 성별 :<br />
29 + <select name="gender">
30 + <option value="man">남자</option>
31 + <option value="woman">여자</option></select
32 + ><br />
33 + 키(cm) : <br />
34 + <input type="text" name="height" /><br />
35 + 몸무게(kg) : <br /><input type="text" name="weight" /><br />
36 + 활동량 :<br />
37 + <select name="activity">
38 + <option value="low">가벼운 활동(주로 앉아서 생활)</option>
39 + <option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
40 + <option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
41 + <option value="veryHigh">매우 많은 활동(운동선수)</option></select
42 + ><br />
43 + <input type="submit" value="계산하기" />
44 + </form>` );
45 + response.writeHead(200);
46 + response.end(html);
47 +
48 +
49 + }
50 + else if(pathname === '/countKcal_process'){
51 + var body = '';
52 + request.on('data', function(data){
53 + body = body + data;
54 + });
55 + request.on('end', function(){
56 + var post = qs.parse(body);
57 + var title = '칼로리 계산';
58 + var description = '성별, 키, 몸무게, 활동량을 입력하시면 일일 권장 섭취량(kcal)를 알려드립니다!';
59 + var gender = post.gender;
60 + var height = post.height;
61 + var weight = post.weight;
62 + var gender_default = '';
63 + if(gender == "man"){
64 + gender_default =
65 + `<option value="man" selected>남자</option>
66 + <option value="woman">여자</option>`;
67 + }
68 + else {
69 + gender_default =
70 + `<option value="man" >남자</option>
71 + <option value="woman" selected>여자</option>`;
72 + }
73 + var std_weight = (height*height/10000*((gender =="man") ? 22 : 21)).toFixed(1); //남자면 22, 여자면 21을 곱함.
74 + var activity = post.activity;
75 + var activity_idx;
76 + var activity_default = '';
77 + var weight_gap = (weight - std_weight).toFixed(1);
78 + var weightMsg = "";
79 + if(weight_gap > 0){
80 + weightMsg += `표준 체중보다 ${weight_gap}kg 많습니다.`
81 + }
82 + else if(weight_gap < 0){
83 + weightMsg += `표준 체중보다 ${-weight_gap}kg 적습니다.`
84 + }
85 + else {
86 + weightMsg += '표준 체중과 몸무게가 같습니다.'
87 + }
88 + switch(activity){
89 + case "low":
90 + activity_idx = 25;
91 + activity_default = `
92 + <option value="low" selected>가벼운 활동(주로 앉아서 생활)</option>
93 + <option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
94 + <option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
95 + <option value="veryHigh">매우 많은 활동(운동선수)</option></select>
96 + `
97 + break;
98 + case "mid":
99 + activity_idx = 30;
100 + activity_default = `
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 = `
110 + <option value="low" >가벼운 활동(주로 앉아서 생활)</option>
111 + <option value="mid" >중등 활동(주로 서서 일하거나 생활)</option>
112 + <option value="high" selected>많은 활동(건설, 농업 등 노동이 많은 일)</option>
113 + <option value="veryHigh">매우 많은 활동(운동선수)</option></select>
114 + `
115 + break;
116 + default:
117 + activity_idx = 40;
118 + activity_default = `
119 + <option value="low" >가벼운 활동(주로 앉아서 생활)</option>
120 + <option value="mid" >중등 활동(주로 서서 일하거나 생활)</option>
121 + <option value="high" >많은 활동(건설, 농업 등 노동이 많은 일)</option>
122 + <option value="veryHigh" selected>매우 많은 활동(운동선수)</option></select>
123 + `
124 + }
125 +
126 +
127 + var recommended_kcal_day = (std_weight*activity_idx).toFixed();
128 + var html = template.html(title,`
129 + <h2>${title}</h2>
130 + <p>${description}</p>
131 + <form action="/countKcal_process" >
132 + 성별 :<br />
133 + <select name="gender">
134 + ${gender_default}
135 + </select>
136 + <br />
137 + 키(cm) : <br /><input type="text" name="height" placeholder="${height}" /><br />
138 + 몸무게(kg) : <br /><input type="text" name="weight" placeholder="${weight}"/><br />
139 + 활동량 :<br />
140 + <select name="activity">
141 + ${activity_default}
142 + <br />
143 + <input type="submit" value="계산하기" />
144 + <br>
145 + 표준체중 : ${std_weight}kg <br>
146 + ${weightMsg}<br>
147 + 하루 권장 섭취량 : ${recommended_kcal_day}kcal
148 + </form>
149 + ` );
150 +
151 +
152 + response.writeHead(200);
153 + response.end(html);
154 + });
155 + }
156 + else{
157 + response.writeHead(404);
158 + response.end("Not found");
159 + }
160 +});
161 +app.listen(23000);
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "name": "healthprotector",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "main.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC"
11 +}
1 +하루 권장 칼로리 = 표준체중(kg) * 활동지수
2 +표준체중 = 키(m)*키(m)*a (a = 21(여성), 22(남성))
3 +활동지수 =
4 +{
5 + - 앉아서 주로 생활하거나 매일 가벼운 움직임만 하며 활동량이 적은 경우 : 25
6 + - 규칙적인 생활로 보통의 활동량을 가진 경우, 30~35
7 + - 육체노동 등 평소 신체 활동량이 많은 경우, 40
8 +
9 +
10 +}
...\ No newline at end of file ...\ No newline at end of file