1 /**********************************************************************
3 * Description: Application for calculating nutrient intake
4 * Author: Agnibho Mondal
5 * Website: http://code.agnibho.com
6 **********************************************************************
7 Copyright (c) 2013-2015 Agnibho Mondal
9 **********************************************************************
10 This file is part of Diet-Survey.
12 Diet-Survey is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 Diet-Survey is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with Diet-Survey. If not, see <http://www.gnu.org/licenses/>.
24 **********************************************************************/
33 $(document
).ready(function(){
34 $("#js-check").hide();
36 $("#date-month").change(function(e
){
37 adjust_day($(e
.target
).val());
42 $("#block-wait").modal("show");
43 $.get("ajax.php?initdata=true", function(data
, state
){
44 $("#block-wait").modal("hide");
46 init
=JSON
.parse(data
);
48 customfood
=init
.custom
;
49 for(i
=0; i
<foodlist
.length
; i
++){
50 $("#food-name").append("<option>"+foodlist
[i
]+"</option>");
54 $("#connect-fail").modal("show");
58 $("#edit-member").on("show.bs.modal", function(){
59 $("#member-name").val("");
60 $("#member-age").val("");
61 $("[name='member-sex']").removeProp("checked");
62 $("#member-female-npnl").prop("checked", "true");
63 $("#member-work-box").hide();
64 $("#female-special").hide();
66 $("#member-age").change(function(){
69 $("[name='member-sex']").change(function(){
72 $("#save-member").click(function(){
74 mem
.name
=$("#member-name").val();
75 if(mem
.name
.length
==0){
76 alert("Name can't be empty");
79 mem
.age
=$("#member-age").val();
80 if(mem
.age
=="" || isNaN(mem
.age
) || mem
.age
<0 || mem
.age
>100){
81 alert("Please enter correct age");
84 if($("#member-sex-male").is(":checked")){
87 else if($("#member-sex-female").is(":checked")){
91 alert("Please select sex");
95 mem
.work
=$("#member-work").val();
96 if(mem
.age
<=45 && mem
.sex
=="Female"){
97 if($("#member-female-npnl").is(":checked")){
100 if($("#member-female-pregnant").is(":checked")){
103 if($("#member-female-lactating-lt6").is(":checked")){
106 if($("#member-female-lactating-gt6").is(":checked")){
111 family
.members
.push(mem
);
113 $("#edit-member").modal("hide");
115 $("#family-members").on("click", ".remove-member", function(e
){
116 family
.members
.splice($(e
.target
).data("id"), 1);
120 $("#edit-food").on("show.bs.modal", function(){
121 $("#food-name").val("");
122 $("#food-amount").val("");
125 $("#add-food").click(function(){
127 item
.name
=$("#food-name").val();
128 item
.amount
=$("#food-amount").val();
130 alert("Please select a food");
133 if(item
.amount
=="" || isNaN(item
.amount
) || item
.amount
<=0){
134 alert("Please enter correct amount");
139 $("#edit-food").modal("hide");
141 $("#launch-custom").click(function(){
142 $("#edit-food").modal("hide");
143 $("#customize-food").modal("show");
145 $("#food-list").on("click", ".remove-food", function(e
){
146 foods
.splice($(e
.target
).data("id"), 1);
150 $("#customize-food").on("show.bs.modal", function(){
153 $("#custom-save").click(function(){
156 $("#custom-existing").on("click", ".custom-delete", function(e
){
157 del_id
=$(e
.target
).data("id");
158 $("#customize-food :input, #customize-food :button").prop("disabled", "disabled");
159 $.post("ajax.php", {"delete_custom_food":del_id
}, function(data
, state
){
160 if(state
=="success" && JSON
.parse(data
).flag
){
161 customfood
.splice(del_id
, 1);
165 alert("Server sync failed");
167 $("#customize-food :input, #customize-food :button").removeProp("disabled", "disabled");
171 $("#get-result").click(function(){
172 family
.head
=$("#family-head").val();
173 family
.date
=[$("#date-day").val(), $("#date-month").val(), $("#date-year").val()];
174 if(family
.head
.length
==0){
175 alert("Please enter the name of the head of the family");
178 else if(family
.members
.length
==0){
179 alert("Please add family members");
181 else if(foods
.length
==0){
182 alert("Please add consumed foods");
194 $.extend(true, compact
.subjects
, family
.members
);
195 $.extend(true, compact
.foods
, foods
);
196 for(i
=0; i
<compact
.subjects
.length
; i
++){
197 delete compact
.subjects
[i
].name
;
199 for(i
=0; i
<compact
.foods
.length
; i
++){
200 delete compact
.foods
[i
].amount
;
202 $("#block-wait").modal("show");
203 $.post("ajax.php", compact
, function(string
, status
){
204 $("#block-wait").modal("hide");
205 if(status
=="success"){
206 data
=JSON
.parse(string
);
207 for(i
=0; i
<data
["rda"].length
; i
++){
208 family
.members
[i
].rda
=data
["rda"][i
];
210 for(i
=0; i
<foods
.length
; i
++){
211 foods
[i
].value
=data
["val"][foods
[i
].name
];
218 $("#connect-fail").modal("show");
223 function calculate(){
224 for(i
=0; i
<foods
.length
; i
++){
226 foods
[i
].intake
.energy
=foods
[i
].value
.energy
*foods
[i
].amount
/100;
227 foods
[i
].intake
.protein
=foods
[i
].value
.protein
*foods
[i
].amount
/100;
228 foods
[i
].intake
.iron
=foods
[i
].value
.iron
*foods
[i
].amount
/100;
229 foods
[i
].intake
.vitA
=foods
[i
].value
.vitA
*foods
[i
].amount
/100;
230 foods
[i
].intake
.thiamine
=foods
[i
].value
.thiamine
*foods
[i
].amount
/100;
231 foods
[i
].intake
.riboflavin
=foods
[i
].value
.riboflavin
*foods
[i
].amount
/100;
232 foods
[i
].intake
.vitC
=foods
[i
].value
.vitC
*foods
[i
].amount
/100;
235 total
.intake
.energy
=0
236 total
.intake
.protein
=0
239 total
.intake
.thiamine
=0
240 total
.intake
.riboflavin
=0
242 for(i
=0; i
<foods
.length
; i
++){
243 total
.intake
.energy
=total
.intake
.energy
+foods
[i
].intake
.energy
;
244 total
.intake
.protein
=total
.intake
.protein
+foods
[i
].intake
.protein
;
245 total
.intake
.iron
=total
.intake
.iron
+foods
[i
].intake
.iron
;
246 total
.intake
.vitA
=total
.intake
.vitA
+foods
[i
].intake
.vitA
;
247 total
.intake
.thiamine
=total
.intake
.thiamine
+foods
[i
].intake
.thiamine
;
248 total
.intake
.riboflavin
=total
.intake
.riboflavin
+foods
[i
].intake
.riboflavin
;
249 total
.intake
.vitC
=total
.intake
.vitC
+foods
[i
].intake
.vitC
;
251 total
.requirement
={};
252 total
.requirement
.energy
=0
253 total
.requirement
.protein
=0
254 total
.requirement
.iron
=0
255 total
.requirement
.vitA
=0
256 total
.requirement
.thiamine
=0
257 total
.requirement
.riboflavin
=0
258 total
.requirement
.vitC
=0
259 for(i
=0; i
<family
.members
.length
; i
++){
260 total
.requirement
.energy
=total
.requirement
.energy
+family
.members
[i
].rda
.energy
;
261 total
.requirement
.protein
=total
.requirement
.protein
+family
.members
[i
].rda
.protein
;
262 total
.requirement
.iron
=total
.requirement
.iron
+family
.members
[i
].rda
.iron
;
263 total
.requirement
.vitA
=total
.requirement
.vitA
+family
.members
[i
].rda
.vitA
;
264 total
.requirement
.thiamine
=total
.requirement
.thiamine
+family
.members
[i
].rda
.thiamine
;
265 total
.requirement
.riboflavin
=total
.requirement
.riboflavin
+family
.members
[i
].rda
.riboflavin
;
266 total
.requirement
.vitC
=total
.requirement
.vitC
+family
.members
[i
].rda
.vitC
;
269 total
.diff
.energy
={};
270 total
.diff
.protein
={};
273 total
.diff
.thiamine
={};
274 total
.diff
.riboflavin
={};
276 if(total
.requirement
.energy
>total
.intake
.energy
){
277 total
.diff
.energy
.state
="-";
278 total
.diff
.energy
.value
=total
.requirement
.energy
-total
.intake
.energy
281 total
.diff
.energy
.state
="+";
282 total
.diff
.energy
.value
=total
.intake
.energy
-total
.requirement
.energy
284 if(total
.requirement
.protein
>total
.intake
.protein
){
285 total
.diff
.protein
.state
="-";
286 total
.diff
.protein
.value
=total
.requirement
.protein
-total
.intake
.protein
289 total
.diff
.protein
.state
="+";
290 total
.diff
.protein
.value
=total
.intake
.protein
-total
.requirement
.protein
292 if(total
.requirement
.iron
>total
.intake
.iron
){
293 total
.diff
.iron
.state
="-";
294 total
.diff
.iron
.value
=total
.requirement
.iron
-total
.intake
.iron
297 total
.diff
.iron
.state
="+";
298 total
.diff
.iron
.value
=total
.intake
.iron
-total
.requirement
.iron
300 if(total
.requirement
.vitA
>total
.intake
.vitA
){
301 total
.diff
.vitA
.state
="-";
302 total
.diff
.vitA
.value
=total
.requirement
.vitA
-total
.intake
.vitA
305 total
.diff
.vitA
.state
="+";
306 total
.diff
.vitA
.value
=total
.intake
.vitA
-total
.requirement
.vitA
308 if(total
.requirement
.thiamine
>total
.intake
.thiamine
){
309 total
.diff
.thiamine
.state
="-";
310 total
.diff
.thiamine
.value
=total
.requirement
.thiamine
-total
.intake
.thiamine
313 total
.diff
.thiamine
.state
="+";
314 total
.diff
.thiamine
.value
=total
.intake
.thiamine
-total
.requirement
.thiamine
316 if(total
.requirement
.riboflavin
>total
.intake
.riboflavin
){
317 total
.diff
.riboflavin
.state
="-";
318 total
.diff
.riboflavin
.value
=total
.requirement
.riboflavin
-total
.intake
.riboflavin
321 total
.diff
.riboflavin
.state
="+";
322 total
.diff
.riboflavin
.value
=total
.intake
.riboflavin
-total
.requirement
.riboflavin
324 if(total
.requirement
.vitC
>total
.intake
.vitC
){
325 total
.diff
.vitC
.state
="-";
326 total
.diff
.vitC
.value
=total
.requirement
.vitC
-total
.intake
.vitC
329 total
.diff
.vitC
.state
="+";
330 total
.diff
.vitC
.value
=total
.intake
.vitC
-total
.requirement
.vitC
335 function adjust_member(){
336 age
=$("#member-age").val();
338 if($("#member-sex-female").is(":checked")){
342 $("#member-work-box").show();
344 $("#female-special").show();
347 $("#female-special").hide();
351 $("#member-work-box").hide();
352 $("#female-special").hide();
356 function show_members(){
357 $("#family-members").html("");
358 for(i
=0; i
<family
.members
.length
; i
++){
359 $("#family-members").append(display_member(family
.members
[i
], i
));
363 function show_foods(){
364 $("#food-list").html('<tr><th class="col-xs-6">Food Name</th><th class="col-xs-5">Amount (gm or ml)</th><th class="col-xs-1">Remove</th></tr>');
365 for(i
=0; i
<foods
.length
; i
++){
366 $("#food-list").append(display_food(foods
[i
], i
));
370 function show_custom_foods(){
371 $("#custom-existing").html("<tr><th>Name</th><th>Energy</th><th>Protein</th><th>Iron</th><th>Vitamin A</th><th>Thiamine</th><th>Riboflavin</th><th>Vitamin C</th><th>Delete</th></tr>");
372 for(i
=0; i
<customfood
.length
; i
++){
373 $("#custom-existing").append('<tr><td>'+customfood
[i
].name
+'</td><td>'+customfood
[i
].energy
+'</td><td>'+customfood
[i
].protein
+'</td><td>'+customfood
[i
].iron
+'</td><td>'+customfood
[i
].vitA
+'</td><td>'+customfood
[i
].thiamine
+'</td><td>'+customfood
[i
].riboflavin
+'</td><td>'+customfood
[i
].vitC
+'</td><td class="text-center"><a href="#custom-existing" data-id="'+i
+'" class="text-danger"><span class="glyphicon glyphicon-remove custom-delete" data-id="'+i
+'"></span></a></td></tr>');
376 function save_custom_food(){
378 sv
.name
=$("#custom-name").val();
379 sv
.energy
=$("#custom-energy").val();
380 sv
.protein
=$("#custom-protein").val();
381 sv
.iron
=$("#custom-iron").val();
382 sv
.vitA
=$("#custom-vitA").val();
383 sv
.thiamine
=$("#custom-thiamine").val();
384 sv
.riboflavin
=$("#custom-riboflavin").val();
385 sv
.vitC
=$("#custom-vitC").val();
387 alert("Please enter name");
390 else if(!foodlist
.indexOf(sv
.name
)==-1){
391 alert("The food is already present");
394 else if(!(check(sv
.energy
) && check(sv
.protein
) && check(sv
.iron
) && check(sv
.vitA
) && check(sv
.thiamine
) && check(sv
.riboflavin
) && check(sv
.vitC
))){
395 alert("Please enter proper nutritional values");
398 $("#customize-food :input, #customize-food :button").prop("disabled", "disabled");
399 $.post("ajax.php", sv
, function(data
, state
){
400 if(state
=="success" && JSON
.parse(data
).flag
){
402 foodlist
.push(sv
.name
);
404 for(i
=0; i
<foodlist
.length
; i
++){
405 $("#food-name").append("<option>"+foodlist
[i
]+"</option>");
409 alert("Server sync failed");
411 $("#customize-food :input, #customize-food :button").removeProp("disabled");
415 if(val
=="" || isNaN(val
) || val
<0){
424 function show_result(){
425 $("#initial").hide();
426 $("#final").slideDown();
428 $("#show-hof").text(family
.head
);
429 $("#show-date").text(family
.date
[0]+"-"+family
.date
[1]+"-"+family
.date
[2]);
431 $("#show-members").html("<tr><th>Name</th><th>Age</th><th>Sex</th></tr>");
432 $("#show-member-points").html("");
433 for(i
=0; i
<family
.members
.length
; i
++){
434 $("#show-members").append("<tr><td>"+family
.members
[i
].name
+"</td><td>"+family
.members
[i
].age
+" years</td><td>"+family
.members
[i
].sex
+"</td></tr>");
435 if(family
.members
[i
].age
>=18){
436 $("#show-member-points").append('<li class="list-group-item">'+family
.members
[i
].name
+' is a '+family
.members
[i
].work
+' worker</li>');
437 if(family
.members
[i
].age
<=45 && family
.members
[i
].sex
=="Female"){
438 if(family
.members
[i
].state
=="pregnant"){
439 $("#show-member-points").append('<li class="list-group-item">'+family
.members
[i
].name
+' is pregnant</li>');
441 else if(family
.members
[i
].state
=="lactb6"){
442 $("#show-member-points").append('<li class="list-group-item">'+family
.members
[i
].name
+' is lactating (below 6 months)</li>');
444 if(family
.members
[i
].state
=="lacto6"){
445 $("#show-member-points").append('<li class="list-group-item">'+family
.members
[i
].name
+' is lactating (over 6 months)</li>');
451 $("#show-foods").html("<tr><th>Name</th><th>Amount (mg or ml)</th></tr>");
452 for(i
=0; i
<foods
.length
; i
++){
453 $("#show-foods").append("<tr><td>"+foods
[i
].name
+"</td><td>"+foods
[i
].amount
+"</td></tr>");
456 $("#show-requirement").html("<tr><th>Member</th><th>Energy</th><th>Protein</th><th>Iron</th><th>Vitamin A</th><th>Thiamine</th><th>Riboflavin</th><th>Vitamin C</th></tr>");
457 for(i
=0; i
<family
.members
.length
; i
++){
458 $("#show-requirement").append("<tr><td>"+family
.members
[i
].name
+"</td><td>"+family
.members
[i
].rda
.energy
.toFixed(2)+" kcal</td><td>"+family
.members
[i
].rda
.protein
.toFixed(2)+" gm</td><td>"+family
.members
[i
].rda
.iron
.toFixed(2)+" mg</td><td>"+family
.members
[i
].rda
.vitA
.toFixed(2)+" μg</td><td>"+family
.members
[i
].rda
.thiamine
.toFixed(2)+" mg</td><td>"+family
.members
[i
].rda
.riboflavin
.toFixed(2)+" mg</td><td>"+family
.members
[i
].rda
.vitC
.toFixed(2)+" mg</td></tr>");
460 $("#show-requirement").append("<tr><th>Total</th><th>"+total
.requirement
.energy
.toFixed(2)+" kcal</th><th>"+total
.requirement
.protein
.toFixed(2)+" gm</th><th>"+total
.requirement
.iron
.toFixed(2)+" mg</th><th>"+total
.requirement
.vitA
.toFixed(2)+" μg</th><th>"+total
.requirement
.thiamine
.toFixed(2)+" mg</th><th>"+total
.requirement
.riboflavin
.toFixed(2)+" mg</th><th>"+total
.requirement
.vitC
.toFixed(2)+" mg</th></tr>");
462 $("#show-value").html("<tr><th>Food</th><th>Energy</th><th>Protein</th><th>Iron</th><th>Vitamin A</th><th>Thiamine</th><th>Riboflavin</th><th>Vitamin C</th></tr>");
463 for(i
=0; i
<foods
.length
; i
++){
464 $("#show-value").append("<tr><td>"+foods
[i
].name
+"</td><td>"+foods
[i
].intake
.energy
.toFixed(2)+"</td><td>"+foods
[i
].intake
.protein
.toFixed(2)+"</td><td>"+foods
[i
].intake
.iron
.toFixed(2)+"</td><td>"+foods
[i
].intake
.vitA
.toFixed(2)+"</td><td>"+foods
[i
].intake
.thiamine
.toFixed(2)+"</td><td>"+foods
[i
].intake
.riboflavin
.toFixed(2)+"</td><td>"+foods
[i
].intake
.vitC
.toFixed(2)+"</td></tr>");
466 $("#show-value").append("<tr><th>Total</th><th>"+total
.intake
.energy
.toFixed(2)+"</th><th>"+total
.intake
.protein
.toFixed(2)+"</th><th>"+total
.intake
.iron
.toFixed(2)+"</th><th>"+total
.intake
.vitA
.toFixed(2)+"</th><th>"+total
.intake
.thiamine
.toFixed(2)+"</th><th>"+total
.intake
.riboflavin
.toFixed(2)+"</th><th>"+total
.intake
.vitC
.toFixed(2)+"</th></tr>");
468 $("#show-compare").html("<tr><th>Nutrient</th><th>Requirement</th><th>Intake</th><th>Deficeiency / Excess</th></tr>");
469 $("#show-summary").html("");
470 if(total
.diff
.energy
.state
=="+"){
471 $("#show-compare").append("<tr><td>Energy</td><td>"+total
.requirement
.energy
.toFixed(2)+"</td><td>"+total
.intake
.energy
.toFixed(2)+"</td><td>"+total
.diff
.energy
.value
.toFixed(2)+" excess</td></tr>");
472 $("#show-summary").append("<li class='list-group-item list-group-item-success'>Energy consumption is excess by "+((total
.diff
.energy
.value
*100)/total.requirement.energy).toFixed(2)+"%</li>");
475 $("#show
-compare
").append("<tr
><td
>Energy
</td><td>"+total.requirement.energy.toFixed(2)+"</td
><td
>"+total.intake.energy.toFixed(2)+"</td><td>"+total.diff.energy.value.toFixed(2)+" deficient</td
></tr
>");
476 $("#show
-summary
").append("<li
class='list-group-item list-group-item-danger'>Energy consumption is deficient by
"+((total.diff.energy.value*100)/total.requirement.energy).toFixed(2)+"%</li
>");
478 if(total.diff.protein.state=="+"){
479 $("#show
-compare
").append("<tr
><td
>Protein
</td><td>"+total.requirement.protein.toFixed(2)+"</td
><td
>"+total.intake.protein.toFixed(2)+"</td><td>"+total.diff.protein.value.toFixed(2)+" excess</td
></tr
>");
480 $("#show
-summary
").append("<li
class='list-group-item list-group-item-success'>Protein consumption is excess by
"+((total.diff.protein.value*100)/total.requirement.protein).toFixed(2)+"%</li
>");
483 $("#show
-compare
").append("<tr
><td
>Protein
</td><td>"+total.requirement.protein.toFixed(2)+"</td
><td
>"+total.intake.protein.toFixed(2)+"</td><td>"+total.diff.protein.value.toFixed(2)+" deficient</td
></tr
>");
484 $("#show
-summary
").append("<li
class='list-group-item list-group-item-danger'>Protein consumption is deficient by
"+((total.diff.protein.value*100)/total.requirement.protein).toFixed(2)+"%</li
>");
486 if(total.diff.iron.state=="+"){
487 $("#show
-compare
").append("<tr
><td
>Iron
</td><td>"+total.requirement.iron.toFixed(2)+"</td
><td
>"+total.intake.iron.toFixed(2)+"</td><td>"+total.diff.iron.value.toFixed(2)+" excess</td
></tr
>");
488 $("#show
-summary
").append("<li
class='list-group-item list-group-item-success'>Iron consumption is excess by
"+((total.diff.iron.value*100)/total.requirement.iron).toFixed(2)+"%</li
>");
491 $("#show
-compare
").append("<tr
><td
>Iron
</td><td>"+total.requirement.iron.toFixed(2)+"</td
><td
>"+total.intake.iron.toFixed(2)+"</td><td>"+total.diff.iron.value.toFixed(2)+" deficient</td
></tr
>");
492 $("#show
-summary
").append("<li
class='list-group-item list-group-item-danger'>Iron consumption is deficient by
"+((total.diff.iron.value*100)/total.requirement.iron).toFixed(2)+"%</li
>");
494 if(total.diff.vitA.state=="+"){
495 $("#show
-compare
").append("<tr
><td
>Vitamin A
</td><td>"+total.requirement.vitA.toFixed(2)+"</td
><td
>"+total.intake.vitA.toFixed(2)+"</td><td>"+total.diff.vitA.value.toFixed(2)+" excess</td
></tr
>");
496 $("#show
-summary
").append("<li
class='list-group-item list-group-item-success'>Vitamin A consumption is excess by
"+((total.diff.vitA.value*100)/total.requirement.vitA).toFixed(2)+"%</li
>");
499 $("#show
-compare
").append("<tr
><td
>Vitamin A
</td><td>"+total.requirement.vitA.toFixed(2)+"</td
><td
>"+total.intake.vitA.toFixed(2)+"</td><td>"+total.diff.vitA.value.toFixed(2)+" deficient</td
></tr
>");
500 $("#show
-summary
").append("<li
class='list-group-item list-group-item-danger'>Vitamin A consumption is deficient by
"+((total.diff.vitA.value*100)/total.requirement.vitA).toFixed(2)+"%</li
>");
502 if(total.diff.thiamine.state=="+"){
503 $("#show
-compare
").append("<tr
><td
>Thiamine
</td><td>"+total.requirement.thiamine.toFixed(2)+"</td
><td
>"+total.intake.thiamine.toFixed(2)+"</td><td>"+total.diff.thiamine.value.toFixed(2)+" excess</td
></tr
>");
504 $("#show
-summary
").append("<li
class='list-group-item list-group-item-success'>Thiamine consumption is excess by
"+((total.diff.thiamine.value*100)/total.requirement.thiamine).toFixed(2)+"%</li
>");
507 $("#show
-compare
").append("<tr
><td
>Thiamine
</td><td>"+total.requirement.thiamine.toFixed(2)+"</td
><td
>"+total.intake.thiamine.toFixed(2)+"</td><td>"+total.diff.thiamine.value.toFixed(2)+" deficient</td
></tr
>");
508 $("#show
-summary
").append("<li
class='list-group-item list-group-item-danger'>Thiamine consumption is deficient by
"+((total.diff.thiamine.value*100)/total.requirement.thiamine).toFixed(2)+"%</li
>");
510 if(total.diff.riboflavin.state=="+"){
511 $("#show
-compare
").append("<tr
><td
>Riboflavin
</td><td>"+total.requirement.riboflavin.toFixed(2)+"</td
><td
>"+total.intake.riboflavin.toFixed(2)+"</td><td>"+total.diff.riboflavin.value.toFixed(2)+" excess</td
></tr
>");
512 $("#show
-summary
").append("<li
class='list-group-item list-group-item-success'>Riboflavin consumption is excess by
"+((total.diff.riboflavin.value*100)/total.requirement.riboflavin).toFixed(2)+"%</li
>");
515 $("#show
-compare
").append("<tr
><td
>Riboflavin
</td><td>"+total.requirement.riboflavin.toFixed(2)+"</td
><td
>"+total.intake.riboflavin.toFixed(2)+"</td><td>"+total.diff.riboflavin.value.toFixed(2)+" deficient</td
></tr
>");
516 $("#show
-summary
").append("<li
class='list-group-item list-group-item-danger'>Riboflavin consumption is deficient by
"+((total.diff.riboflavin.value*100)/total.requirement.riboflavin).toFixed(2)+"%</li
>");
518 if(total.diff.vitC.state=="+"){
519 $("#show
-compare
").append("<tr
><td
>Vitamin C
</td><td>"+total.requirement.vitC.toFixed(2)+"</td
><td
>"+total.intake.vitC.toFixed(2)+"</td><td>"+total.diff.vitC.value.toFixed(2)+" excess</td
></tr
>");
520 $("#show
-summary
").append("<li
class='list-group-item list-group-item-success'>Vitamin C consumption is excess by
"+((total.diff.vitC.value*100)/total.requirement.vitC).toFixed(2)+"%</li
>");
523 $("#show
-compare
").append("<tr
><td
>Vitamin C
</td><td>"+total.requirement.vitC.toFixed(2)+"</td
><td
>"+total.intake.vitC.toFixed(2)+"</td><td>"+total.diff.vitC.value.toFixed(2)+" deficient</td
></tr
>");
524 $("#show
-summary
").append("<li
class='list-group-item list-group-item-danger'>Vitamin C consumption is deficient by
"+((total.diff.vitC.value*100)/total.requirement.vitC).toFixed(2)+"%</li
>");
528 function enum_date(){
529 for(i=2010; i<=2020; i++){
531 $("#date
-year
").append("<option selected
>"+i+"</option
>");
534 $("#date
-year
").append("<option
>"+i+"</option
>");
537 for(i=1; i<=12; i++){
539 $("#date
-month
").append("<option selected
>"+i+"</option
>");
542 $("#date
-month
").append("<option
>"+i+"</option
>");
548 function adjust_day(month){
553 else if(month==4||month==6||month==9||month==11){
556 day=$("#date
-day
").val();
557 $("#date
-day
").html("");
561 for(i=1; i<=lim; i++){
563 $("#date
-day
").append("<option selected
>"+i+"</option
>");
566 $("#date
-day
").append("<option
>"+i+"</option
>");
571 function display_member(mem, i){
572 html='<div class="panel panel
-success
">'
573 +'<div class="panel
-heading
">'
575 +'<div class="col
-xs
-offset
-11 col
-xs
-1"><span data-id="'+i+'" class="point remove
-member text
-warning
"><span data-id="'+i+'" class="glyphicon glyphicon
-remove
"></span></span></div>'
578 +'<div class="panel
-body
">'
579 +'<form class="form
-horizontal
" role="form
">'
580 +'<div class="form
-group
">'
581 +'<label class="col
-sm
-3 control
-label
">Name:</label>'
582 +'<div class="col
-sm
-9">'
583 +'<p class="form
-control
-static">'+mem.name+'</p>'
586 +'<div class="form
-group
">'
587 +'<label class="col
-sm
-3 control
-label
">Age:</label>'
588 +'<div class="col
-sm
-9">'
589 +'<p class="form
-control
-static">'+mem.age+'</p>'
592 +'<div class="form
-group
">'
593 +'<label class="col
-sm
-3 control
-label
">Sex:</label>'
594 +'<div class="col
-sm
-9">'
595 +'<p class="form
-control
-static">'+mem.sex+'</p>'
599 html=html+'<div class="form
-group
">'
600 +'<label class="col
-sm
-3 control
-label
">Work Type:</label>'
601 +'<div class="col
-sm
-9">'
602 +'<p class="form
-control
-static">'+mem.work+'</p>'
608 if(mem.age>=18 && mem.age<=45 && mem.sex=="Female
"){
609 if(mem.state=="npnl
"){
612 else if(mem.state=="preg
"){
615 else if(mem.state=="lactb6
"){
616 state="Lactating
, below
6 months
";
618 else if(mem.state=="lacto6
"){
619 state="Lactating
, over
6 months
";
622 html=html+'<div class="panel
-footer
">'
623 +'<div class="text
-center
">'
624 +'<p class="form
-control
-static">'+state+'</p>'
633 function display_food(item, i){
634 html='<tr><td class="col
-xs
-6">'+item.name+'</td><td class="col
-xs
-5">'+item.amount+'</td><td class="col
-xs
-1 text
-center
"><span class="point remove
-food text
-warning
" data-id="'+i+'"><span class="glyphicon glyphicon
-remove
" data-id="'+i+'"></span></span></td></tr>';
638 function draw_bar_diagram(){
640 labels: ["Energy
", "Protein
", "Iron
", "Vitamine A
", "Thiamine
", "Riboflavin
", "Vitamin C
"],
644 fillColor: "rgba(151,187,205,0.5)",
645 strokeColor: "rgba(151,187,205,0.8)",
646 highlightFill: "rgba(151,187,205,0.75)",
647 highlightStroke: "rgba(151,187,205,1)",
648 data: [parseFloat(((total.intake.energy*100)/total.requirement.energy).toFixed(2)), parseFloat(((total.intake.protein*100)/total.requirement.protein).toFixed(2)), parseFloat(((total.intake.iron*100)/total.requirement.iron).toFixed(2)), parseFloat(((total.intake.vitA*100)/total.requirement.vitA).toFixed(2)), parseFloat(((total.intake.thiamine*100)/total.requirement.thiamine).toFixed(2)), parseFloat(((total.intake.riboflavin*100)/total.requirement.riboflavin).toFixed(2)), parseFloat(((total.intake.vitC*100)/total.requirement.vitC).toFixed(2))]
654 var ctx=$("#bar
-diagram
").get(0).getContext("2d
");
655 var diagram=new Chart(ctx).Bar(data);