김동진

파일 정리

......@@ -118,4 +118,6 @@ dist
package-lock.json
# db
lib.db.js
\ No newline at end of file
lib.db.js
lib.appkey.js
food.sql
\ No newline at end of file
......
var key = {
kakaomapKey : "900b1f5dd2fee32f1ee91d18266bbfe4"};
module.exports = key; //key을 바깥에서 사용할 수 있도록 exports한다.
var qs = require('querystring');
var template = require('./template.js');
exports.countKcal = function(request, response){
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 />
나이(세) : <br />
<input type="text" name="age" /><br />
키(cm) : <br />
<input type="text" name="height" /><br />
몸무게(kg) : <br /><input type="text" name="weight" /><br />
목표체중(kg) : <br /><input type="text" name="targetWeight" /><br />
목표기간(일) : <br /><input type="text" name="targetDay" /><br />
활동량 :<br />
<select name="activity">
<option value="low">앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option>
<option value="mid">활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option>
<option value="high">많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option>
</select
><br />
<input type="submit" value="계산하기" />
<br><br><br><br>
</form>` );
response.writeHead(200);
response.end(html);
}
exports.countKcal_process = function(request, response){
var body = '';
request.on('data', function(data){
body = body + data;
});
request.on('end', function(){
var post = qs.parse(body);
var title = '칼로리 계산';
var description = '성별, 키, 몸무게, 활동량을 입력하시면 표준체중, 현재 체중을 유지하는데 필요한 열량, 다이어트 열량을 알려드립니다!';
var gender = post.gender; //성별
var age = post.age; //나이
var height = post.height; //키
var weight = post.weight; //현재 체중
var targetDay = post.targetDay //목표기간(일)
var targetWeight = post.targetWeight;
var BMR; //기초대사량(bmr) Harris-BenedictEquation(B.E.E) 방법
var BMI = (weight/(height*height)*10000).toFixed(1); //비만도
var BMI_msg = '';
if(BMI >= 30){
BMI_msg += '고도비만';
}
else if(BMI >=25 && BMI <30){
BMI_msg += '비만';
}
else if(BMI >=23 && BMI <25){
BMI_msg += '과체중';
}
else if(BMI >=18.5 && BMI <23){
BMI_msg += '정상';
}
else if(BMI >= 0 && BMI < 18.5){
BMI_msg += '저체중';
}
else {
BMI_msg += "Error";
}
var gender_default = '';
if(gender == "man"){
gender_default =
`<option value="man" selected>남자</option>
<option value="woman">여자</option>`;
BMR = (66.5 + 13.75*weight + 5.003*height - 6.755*age).toFixed(1);
}
else {
gender_default =
`<option value="man" >남자</option>
<option value="woman" selected>여자</option>`;
BMR = (655. + 9.563*weight + 1.85*height - 4.676*age).toFixed(1);
}
var std_weight = (height*height/10000*((gender =="man") ? 22 : 21)).toFixed(1); //남자면 22, 여자면 21을 곱함.
var activity = post.activity;
var activity_idx;
var TDEE; //Total Daily Energy Expenditure 현재 체중을 유지하기 위한 열량
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 = 1.53;
TDEE = (BMR*activity_idx).toFixed(1);
activity_default = `
<option value="low" selected>앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option>
<option value="mid">활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option>
<option value="high">활발히 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option>
`
break;
case "mid":
activity_idx = 1.76;
TDEE = (BMR*activity_idx).toFixed(1);
activity_default = `
<option value="low" >앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option>
<option value="mid" selected>활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option>
<option value="high">많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option>
`
break;
default:
activity_idx = 2.25;
TDEE = (BMR*activity_idx).toFixed(1);
activity_default = `
<option value="low" >앉아 있거나 가벼운 활동(운동을 거의 또는 전혀하지 않음)</option>
<option value="mid" >활동적 또는 보통 활동(건설노동자 또는 매일 1시간씩 달림)</option>
<option value="high" selected>많은 활동(농업노동자 또는 매일 2시간동안 수영을 함)</option>
`
}
var totalKcal; //빼거나 쪄야할 총 칼로리
var foodKcal; //하루에 더 먹거나 덜 먹어야할 칼로리
var kcalMsg = '하루에 먹어야할 '
if(weight > targetWeight){
totalKcal = (weight - targetWeight)*7700; //빼야할 총 칼로리/다이어트
foodKcal = (totalKcal/targetDay).toFixed(1);
kcalMsg += `다이어트 칼로리 : ${(TDEE - foodKcal).toFixed(1)}kcal`;
}
else if(weight < targetWeight) {
totalKcal = (targetWeight-weight)*7700; //쩌야할 총 칼로리/벌크업
foodKcal = (totalKcal/targetDay).toFixed(1);
kcalMsg += `벌크업 칼로리 : ${(TDEE - foodKcal).toFixed(1)}kcal`;
}
var html = template.html(title,`
<h2>${title}</h2>
<p>${description}</p>
<form action="/countKcal_process" method="post" >
성별 :<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 />
목표체중(kg) : <br /><input type="text" name="targetWeight" placeholder="${targetWeight}"/><br />
목표기간(일) : <br /><input type="text" name="targetDay" placeholder="${targetDay}"/><br />
활동량 :<br />
<select name="activity">
${activity_default}
</select>
<br />
<input type="submit" value="계산하기" />
<br>
표준체중 : ${std_weight}kg <br>
${weightMsg}<br>
BMI 지수 : ${BMI} / 당신은 ${BMI_msg} 입니다. <br>
기초 대사량 : ${BMR}kcal <br>
현재 체중 유지를 위한 열량 : ${TDEE}kcal <br>
${kcalMsg} <br>
<br><br><br><br>
</form>
` );
response.writeHead(200);
response.end(html);
});
}
\ No newline at end of file
var template = require('./template.js');
var qs = require('querystring');
var db = require('./db.js');
exports.foodInfo = function(request, response){
var title = '음식 영양정보';
var description = '음식을 검색하면 음식의 칼로리, 탄수화물, 단백질, 지방, 나트륨의 정보를 알려드립니다!';
var html = template.html(title,`
<h2>${title}</h2>
<p>${description}</p>
<form action="/foodInfo_search" method="post">
<input type = 'text' name = 'search' placeholder = '검색어 입력' maxlength = 255 value = "" autocomplete = "off">
<button type = "submit" name = "click">검색</button>
</form>
`);
response.writeHead(200);
response.end(html);
}
exports.foodInfo_search = function(request, response){
var body = '';
request.on('data', function(data){
body = body + data;
});
request.on('end', function(){
var post = qs.parse(body);
db.query(`SELECT * FROM fooddb`, function (error, foodInfo) {
var title = '음식 영양정보';
var description = '음식을 검색하면 음식의 칼로리, 탄수화물, 단백질, 지방, 나트륨의 정보를 알려드립니다!';
var search = post.search; // 검색어
var num = 0; // 검색된 개수
var foodName = '';
var list = [];
//console.log(foodInfo[0]);
for(var i =0; i<foodInfo.length; i++){
foodName = foodInfo[i].name;
if(foodName.indexOf(search) >=0){
list.push(i);
num +=1;
}
}
var html = template.html(title,`
<h2>${title}</h2>
<p>${description}</p>
<form action="/foodInfo_search" method="post">
<input type = 'text' name = 'search' placeholder = '검색어 입력' maxlength = 255 value = "" autocomplete = "off">
<button type = "submit" name = "click">검색</button>
</form>
<br>
${search}(으)로 검색된 결과 : ${num}
<form action="/foodInfo_chooseAdd_process" method="post">
${template.foodTable(foodInfo, list, num)}
<button type = "submit" name = "chooseAdd">추가하기</button>
</form>
<style>
table{
border-collapse: collapse;
}
td{
border:1px solid black;
}
</style>
`);
response.writeHead(200);
response.end(html);
});
});
}
\ No newline at end of file
......
var template = require('./template.js');
exports.home = function(request, response){
var title = '소개';
var description = '개개인의 신체 정보에 따라 일일 권장 섭취량을 알려주고, 좋아하는 음식을 검색하면 영양정보를 알려주는 사이트 입니다.';
var html = template.html(title,`
<br><br><br><br>
<style>
@import url('https://fonts.googleapis.com/css2?family=Jua&family=Noto+Sans+KR&display=swap');
</style>
<h2 style="font-family: 'Jua', sans-serif;"><font color="red"><text align:center>${title}</font></h2>
<p style="font-family: 'Jua', sans-serif;">${description}</p>` );
response.writeHead(200);
response.end(html);
}
var template = require('./template.js');
var key = require('./appkey.js');
exports.searchGym = function(request, response){
var title = '헬스장 찾기';
var description = '위치를 입력하면 그 주위의 헬스장을 찾아드립니다!';
var html = template.html(title,`
<h2>${title}</h2>
<p>${description}</p>
<div id="map" style="width:500px;height:400px;"></div>
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey=${key.kakaomapKey}"></script>
<script>
var container = document.getElementById('map');//지도를 담을 영역의 DOM 레퍼런스
var options = { //지도를 생성할 때 필요한 기본 옵션
center: new kakao.maps.LatLng(37.247550, 127.078411), //지도의 중심좌표.
level: 3 //지도의 레벨(확대, 축소 정도)
};
var map = new kakao.maps.Map(container, options); //지도 생성 및 객체 리턴
</script>
`);
response.writeHead(200);
response.end(html);
}
\ No newline at end of file
......@@ -9,17 +9,7 @@ module.exports = {
<title>HelP - ${title}</title>
<meta charset="utf-8" />
</head>
<<<<<<< Updated upstream
<body>
<style>
@import url('https://fonts.googleapis.com/css2?family=Jua&family=Noto+Sans+KR&display=swap');
</style>
=======
<body>
>>>>>>> Stashed changes
<style type="text/css">
div{
@import url('https://fonts.googleapis.com/css2?family=Jua&family=Noto+Sans+KR&display=swap');
......@@ -36,9 +26,6 @@ module.exports = {
</div>
</style>
<div style="font-family:'Jua',sans-serif";>
<h3 style=width:180px;float:left;><a href="/"><font color="black">HealthProtector</font></a></h3>
<h3 style=width:120px;float:left;><a href="/countKcal"><font color="black">칼로리 계산</a></h3>
......@@ -51,29 +38,25 @@ module.exports = {
<h1 style="font-family: 'Jua', sans-serif;"><a href="/"><font color="white">HealthProtector</font></a></h1>
</div>
<br>
<div style= width:47%;"font-family:'Jua',sans-serif";float:left;padding:5px;>
<div style= width:31%;"font-family:'Jua',sans-serif";float:left;padding:5px;>
<h2 style="font-family: 'Jua', sans-serif;"><a href="/countKcal"><font color="black">칼로리 계산</a></h2>
<h4 style="font-family: 'Jua', sans-serif;"><font color="gray">자신에게 맞는 일일 권장 섭취량(kcal)를 계산해보세요!</h4>
</div>
<<<<<<< Updated upstream
<div style= width:47%;float:right;font-size:20px;padding:0px;>
=======
<div style= width:47%;float:right;padding:0px;>
>>>>>>> Stashed changes
<div style= width:36%;float:right;padding:0px;>
<h2 style="font-family: 'Jua', sans-serif;"><a href="/foodInfo"><font color="black">음식별 영양정보</a></h2>
<h4 style="font-family: 'Jua', sans-serif;"><font color="gray">음식별 식품 영양정보에 대해 알려드립니다!</h4>
</div>
<br><br><br><br><br>
<<<<<<< Updated upstream
<h1><a href="/">HealthProtector</a></h1>
<ol>
<li><a href="/countKcal">칼로리 계산</a></li>
<li><a href="/foodInfo">음식별 영양정보</a></li>
</ol>
=======
<div style= width:31%;float:right;padding:0px;>
<h2 style="font-family: 'Jua', sans-serif;"><a href="/searchGym"><font color="black">헬스장 찾기</a></h2>
<h4 style="font-family: 'Jua', sans-serif;"><font color="gray">위치를 입력하면 그 주위의 헬스장을 찾아드립니다!</h4>
</div>
<br><br><br><br><br>
>>>>>>> Stashed changes
${body}
<div style= width:100%;font-size:10px;position:fixed;bottom:0;float:left;padding:0px;background-color:#0B610B;>
......
This diff is collapsed. Click to expand it.
......@@ -7,10 +7,6 @@
},
"author": "",
"license": "ISC",
<<<<<<< Updated upstream
=======
>>>>>>> Stashed changes
"directories": {
"lib": "lib"
},
......@@ -18,16 +14,9 @@
"type": "git",
"url": "http://khuhub.khu.ac.kr/2019102154/HealthProtector.git"
},
"description": "",
<<<<<<< Updated upstream
"dependencies": {
"mysql": "^2.18.1",
=======
"dependencies": {
"mysql": "^2.18.1",
"pm2": "^4.5.0",
>>>>>>> Stashed changes
"react": "^17.0.1",
"react-dom": "^17.0.1"
}
......