김동진

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

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
<!DOCTYPE html>
<html>
<head>
<title>HealthProtectorHome</title>
<meta charset="utf-8" />
</head>
<body>
<h1><a href="home.html">HealthProtector</a></h1>
<ol>
<li><a href="1.html">칼로리 계산</a></li>
<li><a href="2.html">음식별 영양정보</a></li>
</ol>
<h2>칼로리 계산</h2>
<form action="./3.html">
성별 :<br />
<select name="sex">
<option value="man">남자</option>
<option value="woman">여자</option></select
><br />
키(cm) : <br />
<input type="text" name="height" /><br />
몸무게(kg) : <br /><input type="text" name="weight" /><br />
활동량 :<br />
<select name="activity">
<option value="low">가벼운 활동(주로 앉아서 생활)</option>
<option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
<option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
<option value="veryHigh">매우 많은 활동(운동선수)</option></select
><br />
<input type="submit" value="계산하기" />
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HealthProtectorHome</title>
<meta charset="utf-8" />
</head>
<body>
<h1><a href="home.html">HealthProtector</a></h1>
<ol>
<li><a href="1.html">칼로리 계산</a></li>
<li><a href="2.html">음식별 영양정보</a></li>
</ol>
<h2>음식별 영양정보</h2>
<p>개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HealthProtectorHome</title>
<meta charset="utf-8" />
</head>
<body>
<h1><a href="home.html">HealthProtector</a></h1>
<ol>
<li><a href="1.html">칼로리 계산</a></li>
<li><a href="2.html">음식별 영양정보</a></li>
</ol>
<h2>칼로리 계산</h2>
<form action="./3.html">
성별 :<br />
<select name="sex">
<option value="man">남자</option>
<option value="woman">여자</option></select
><br />
키(cm) : <br />
<input type="text" name="height" /><br />
몸무게(kg) : <br /><input type="text" name="weight" /><br />
활동량 :<br />
<select name="activity">
<option value="low">가벼운 활동(주로 앉아서 생활)</option>
<option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
<option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
<option value="veryHigh">매우 많은 활동(운동선수)</option></select
><br />
<input type="submit" value="계산하기" />
</form>
일일 권장 섭취량 :
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HealthProtectorHome</title>
<meta charset="utf-8" />
</head>
<body>
<h1><a href="home.html">HealthProtector</a></h1>
<ol>
<li><a href="1.html">칼로리 계산</a></li>
<li><a href="2.html">음식별 영양정보</a></li>
</ol>
<h2>소개</h2>
<p>개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.</p>
</body>
</html>
module.exports = {
html:function(title, body){
return `
<!DOCTYPE html>
<html>
<head>
<title>HelP - ${title}</title>
<meta charset="utf-8" />
</head>
<body>
<h1><a href="/">HealthProtector</a></h1>
<ol>
<li><a href="/countKcal">칼로리 계산</a></li>
<li><a href="2.html">음식별 영양정보</a></li>
</ol>
${body}
</body>
</html>
`
}
}
\ No newline at end of file
var http = require('http');
var fs = require('fs');
var url = require('url');
var qs = require('querystring');
var template = require('./lib/template.js');
var app = http.createServer(function(request,response){
var _url = request.url;
var queryData = url.parse(_url, true).query;
var pathname = url.parse(_url, true).pathname;
if(pathname === '/'){
if(queryData.id === undefined){
var title = '소개';
var description = '개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.';
var html = template.html(title,`
<h2>${title}</h2>
<p>${description}</p>` );
response.writeHead(200);
response.end(html);
}
}
else if(pathname === '/countKcal'){
var title = '칼로리 계산';
var description = '성별, 키, 몸무게, 활동량을 입력하시면 일일 권장 섭취량(kcal)를 알려드립니다!';
var html = template.html(title,`
<h2>${title}</h2>
<p>${description}</p>
<form action="/countKcal_process" method="post" >
성별 :<br />
<select name="gender">
<option value="man">남자</option>
<option value="woman">여자</option></select
><br />
키(cm) : <br />
<input type="text" name="height" /><br />
몸무게(kg) : <br /><input type="text" name="weight" /><br />
활동량 :<br />
<select name="activity">
<option value="low">가벼운 활동(주로 앉아서 생활)</option>
<option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
<option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
<option value="veryHigh">매우 많은 활동(운동선수)</option></select
><br />
<input type="submit" value="계산하기" />
</form>` );
response.writeHead(200);
response.end(html);
}
else if(pathname === '/countKcal_process'){
var body = '';
request.on('data', function(data){
body = body + data;
});
request.on('end', function(){
var post = qs.parse(body);
var title = '칼로리 계산';
var description = '성별, 키, 몸무게, 활동량을 입력하시면 일일 권장 섭취량(kcal)를 알려드립니다!';
var gender = post.gender;
var height = post.height;
var weight = post.weight;
var gender_default = '';
if(gender == "man"){
gender_default =
`<option value="man" selected>남자</option>
<option value="woman">여자</option>`;
}
else {
gender_default =
`<option value="man" >남자</option>
<option value="woman" selected>여자</option>`;
}
var std_weight = (height*height/10000*((gender =="man") ? 22 : 21)).toFixed(1); //남자면 22, 여자면 21을 곱함.
var activity = post.activity;
var activity_idx;
var activity_default = '';
var weight_gap = (weight - std_weight).toFixed(1);
var weightMsg = "";
if(weight_gap > 0){
weightMsg += `표준 체중보다 ${weight_gap}kg 많습니다.`
}
else if(weight_gap < 0){
weightMsg += `표준 체중보다 ${-weight_gap}kg 적습니다.`
}
else {
weightMsg += '표준 체중과 몸무게가 같습니다.'
}
switch(activity){
case "low":
activity_idx = 25;
activity_default = `
<option value="low" selected>가벼운 활동(주로 앉아서 생활)</option>
<option value="mid">중등 활동(주로 서서 일하거나 생활)</option>
<option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
<option value="veryHigh">매우 많은 활동(운동선수)</option></select>
`
break;
case "mid":
activity_idx = 30;
activity_default = `
<option value="low" >가벼운 활동(주로 앉아서 생활)</option>
<option value="mid" selected>중등 활동(주로 서서 일하거나 생활)</option>
<option value="high">많은 활동(건설, 농업 등 노동이 많은 일)</option>
<option value="veryHigh">매우 많은 활동(운동선수)</option></select>
`
break;
case "high":
activity_idx = 35;
activity_default = `
<option value="low" >가벼운 활동(주로 앉아서 생활)</option>
<option value="mid" >중등 활동(주로 서서 일하거나 생활)</option>
<option value="high" selected>많은 활동(건설, 농업 등 노동이 많은 일)</option>
<option value="veryHigh">매우 많은 활동(운동선수)</option></select>
`
break;
default:
activity_idx = 40;
activity_default = `
<option value="low" >가벼운 활동(주로 앉아서 생활)</option>
<option value="mid" >중등 활동(주로 서서 일하거나 생활)</option>
<option value="high" >많은 활동(건설, 농업 등 노동이 많은 일)</option>
<option value="veryHigh" selected>매우 많은 활동(운동선수)</option></select>
`
}
var recommended_kcal_day = (std_weight*activity_idx).toFixed();
var html = template.html(title,`
<h2>${title}</h2>
<p>${description}</p>
<form action="/countKcal_process" >
성별 :<br />
<select name="gender">
${gender_default}
</select>
<br />
키(cm) : <br /><input type="text" name="height" placeholder="${height}" /><br />
몸무게(kg) : <br /><input type="text" name="weight" placeholder="${weight}"/><br />
활동량 :<br />
<select name="activity">
${activity_default}
<br />
<input type="submit" value="계산하기" />
<br>
표준체중 : ${std_weight}kg <br>
${weightMsg}<br>
하루 권장 섭취량 : ${recommended_kcal_day}kcal
</form>
` );
response.writeHead(200);
response.end(html);
});
}
else{
response.writeHead(404);
response.end("Not found");
}
});
app.listen(23000);
\ No newline at end of file
{
"name": "healthprotector",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
하루 권장 칼로리 = 표준체중(kg) * 활동지수
표준체중 = 키(m)*키(m)*a (a = 21(여성), 22(남성))
활동지수 =
{
- 앉아서 주로 생활하거나 매일 가벼운 움직임만 하며 활동량이 적은 경우 : 25
- 규칙적인 생활로 보통의 활동량을 가진 경우, 30~35
- 육체노동 등 평소 신체 활동량이 많은 경우, 40
}
\ No newline at end of file