]> Softwares of Agnibho - dietsurvey.git/blob - src/output.vue
99112b70840b98d81ef0c670dc060a7242664696
[dietsurvey.git] / src / output.vue
1 <!--
2 **********************************************************************
3 * Title: DietSurvey
4 * Description: Nutritional Assessment App
5 * Author: Agnibho Mondal
6 * Website: http://code.agnibho.com
7 **********************************************************************
8 Copyright (c) 2016 Agnibho Mondal
9 All rights reserved
10 **********************************************************************
11 This file is part of DietSurvey.
12
13 DietSurvey is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 DietSurvey is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with DietSurvey. If not, see <http://www.gnu.org/licenses/>.
25 **********************************************************************
26 -->
27 <template>
28 <div v-if="calcVal" class="panel panel-default">
29 <div class="panel-body">
30 <!-- Requirements -->
31 <div class="panel panel-info">
32 <div class="panel-heading">
33 <div class="panel-title"><h3>Nutritional Requirements</h3></div>
34 </div>
35 <div class="panel-body">
36 <table class="table">
37 <thead>
38 <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>
39 </thead>
40 <tbody>
41 <tr v-for="i in calcVal.req.list">
42 <td>{{i.name}}</td><td>{{i.energy|dec2}}</td><td>{{i.protein|dec2}}</td><td>{{i.iron|dec2}}</td><td>{{i.vitA|dec2}}</td><td>{{i.thiamine|dec2}}</td><td>{{i.riboflavin|dec2}}</td><td>{{i.vitC|dec2}}</td>
43 </tr>
44 </tbody>
45 <thead>
46 <tr><th>Total</th><th>{{calcVal.req.total.energy|dec2}}</th><th>{{calcVal.req.total.protein|dec2}}</th><th>{{calcVal.req.total.iron|dec2}}</th><th>{{calcVal.req.total.vitA|dec2}}</th><th>{{calcVal.req.total.thiamine|dec2}}</th><th>{{calcVal.req.total.riboflavin|dec2}}</th><th>{{calcVal.req.total.vitC|dec2}}</th></tr>
47 </thead>
48 </table>
49 </div>
50 </div>
51 <!-- Consumption -->
52 <div class="panel panel-info">
53 <div class="panel-heading">
54 <div class="panel-title"><h3>Nutritional Value of Consumed Foods</h3></div>
55 </div>
56 <div class="panel-body">
57 <table class="table">
58 <thead>
59 <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>
60 </thead>
61 <tbody>
62 <tr v-for="i in calcVal.intk.list">
63 <td>{{i.name}}</td><td>{{i.energy|dec2}}</td><td>{{i.protein|dec2}}</td><td>{{i.iron|dec2}}</td><td>{{i.vitA|dec2}}</td><td>{{i.thiamine|dec2}}</td><td>{{i.riboflavin|dec2}}</td><td>{{i.vitC|dec2}}</td>
64 </tr>
65 </tbody>
66 <thead>
67 <tr><th>Total</th><th>{{calcVal.intk.total.energy|dec2}}</th><th>{{calcVal.intk.total.protein|dec2}}</th><th>{{calcVal.intk.total.iron|dec2}}</th><th>{{calcVal.intk.total.vitA|dec2}}</th><th>{{calcVal.intk.total.thiamine|dec2}}</th><th>{{calcVal.intk.total.riboflavin|dec2}}</th><th>{{calcVal.intk.total.vitC|dec2}}</th></tr>
68 </thead>
69 </table>
70 </div>
71 </div>
72 <!-- Comparison -->
73 <div class="panel panel-info">
74 <div class="panel-heading">
75 <div class="panel-title"><h3>Requirement vs Intake Comparison</h3></div>
76 </div>
77 <div class="panel-body">
78 <table class="table">
79 <thead><tr><th>Nutrient</th><th>Total Requirement</th><th>Total Intake</th><th>Excess /Deficiency</th></tr></thead>
80 <tbody>
81 <tr><td>Energy</td><td>{{calcVal.req.total.energy|dec2}}</td><td>{{calcVal.intk.total.energy|dec2}}</td><td>{{calcVal.comp.energy[0]|cmp(2)}}</td></tr>
82 <tr><td>Protein</td><td>{{calcVal.req.total.protein|dec2}}</td><td>{{calcVal.intk.total.protein|dec2}}</td><td>{{calcVal.comp.protein[0]|cmp(2)}}</td></tr>
83 <tr><td>Iron</td><td>{{calcVal.req.total.iron|dec2}}</td><td>{{calcVal.intk.total.iron|dec2}}</td><td>{{calcVal.comp.iron[0]|cmp(2)}}</td></tr>
84 <tr><td>Vitamin A</td><td>{{calcVal.req.total.vitA|dec2}}</td><td>{{calcVal.intk.total.vitA|dec2}}</td><td>{{calcVal.comp.vitA[0]|cmp(2)}}</td></tr>
85 <tr><td>Thiamine</td><td>{{calcVal.req.total.thiamine|dec2}}</td><td>{{calcVal.intk.total.thiamine|dec2}}</td><td>{{calcVal.comp.thiamine[0]|cmp(2)}}</td></tr>
86 <tr><td>Riboflavin</td><td>{{calcVal.req.total.riboflavin|dec2}}</td><td>{{calcVal.intk.total.riboflavin|dec2}}</td><td>{{calcVal.comp.riboflavin[0]|cmp(2)}}</td></tr>
87 <tr><td>Vitamin C</td><td>{{calcVal.req.total.vitC|dec2}}</td><td>{{calcVal.intk.total.vitC|dec2}}</td><td>{{calcVal.comp.vitC[0]|cmp(2)}}</td></tr>
88 </tbody>
89 </div>
90 </div>
91 <!-- Summary -->
92 <div class="panel panel-info">
93 <div class="panel-heading">
94 <div class="panel-title"><h3>Summary</h3></div>
95 </div>
96 <div class="panel-body">
97 <ul class="list-group col-md-offset-4 col-md-4">
98 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.energy[0])">Energy {{calcVal.comp.energy[0]|cmp(1)}} is {{calcVal.comp.energy[1]|cmp}}%</li>
99 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.protein[0])">Protein {{calcVal.comp.protein[0]|cmp(1)}} is {{calcVal.comp.protein[1]|cmp}}%</li>
100 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.iron[0])">Iron {{calcVal.comp.iron[0]|cmp(1)}} is {{calcVal.comp.iron[1]|cmp}}%</li>
101 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.vitA[0])">Vitamin A {{calcVal.comp.vitA[0]|cmp(1)}} is {{calcVal.comp.vitA[1]|cmp}}%</li>
102 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.thiamine[0])">Thiamine {{calcVal.comp.thiamine[0]|cmp(1)}} is {{calcVal.comp.thiamine[1]|cmp}}%</li>
103 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.riboflavin[0])">Riboflavin {{calcVal.comp.riboflavin[0]|cmp(1)}} is {{calcVal.comp.riboflavin[1]|cmp}}%</li>
104 <li class="list-group-item" v-bind:class="colorCls(calcVal.comp.vitC[0])">Vitamin C {{calcVal.comp.vitC[0]|cmp(1)}} is {{calcVal.comp.vitC[1]|cmp}}%</li>
105 </ul>
106 </div>
107 </div>
108 <hr>
109 </div>
110 </div>
111 </template>
112
113 <script>
114 export default {
115 name:"Output",
116 props:["dataObj", "dataRef"],
117 filters:{
118 dec2: function(v){
119 return Math.round(v*100)/100;
120 },
121 cmp: function(v, f){
122 if(f==1){
123 if(v<0) return "deficit";
124 else return "excess";
125 }if(f==2){
126 if(v<0) return "Deficit by "+Math.abs(Math.round(v*100)/100);
127 else return "Excess by "+Math.abs(Math.round(v*100)/100);
128 }
129 else{
130 return Math.abs(Math.round(v*100)/100);
131 }
132 }
133 },
134 methods:{
135 colorCls: function(v){
136 if (v<0) return {"list-group-item-danger": true};
137 else return {"list-group-item-success": true};
138 }
139 },
140 computed:{
141 calcVal: function(){
142 var rda=this.dataRef.rda;
143 var val=this.dataRef.food;
144 var root={};
145 // Requirement Calculation
146 root.req={};
147 root.req.list=[];
148 root.req.total={};
149 for(var i=0; i<this.dataObj.family.length; i++){
150 var mem=this.dataObj.family[i];
151 var buff={};
152 // Retrieve individual rda
153 // Female
154 if(mem.sex=="f"){
155 if(mem.age>=18){
156 if(mem.state=="preg"){
157 buff=rda.filter(function(d){
158 return d.subject=="pregnant";
159 })[0];
160 }
161 else if(mem.state=="lact-6"){
162 buff=rda.filter(function(d){
163 return d.subject=="lactating_below6";
164 })[0];
165 }
166 else if(mem.state=="lact+6"){
167 buff=rda.filter(function(d){
168 return d.subject=="lactating_above6";
169 })[0];
170 }
171 else if(mem.state=="npnl"){
172 if(mem.work=="sedentary"){
173 buff=rda.filter(function(d){
174 return d.subject=="female_sedentary";
175 })[0];
176 }
177 else if(mem.work=="moderate"){
178 buff=rda.filter(function(d){
179 return d.subject=="female_moderate";
180 })[0];
181 }
182 else if(mem.work=="heavy"){
183 buff=rda.filter(function(d){
184 return d.subject=="female_heavy";
185 })[0];
186 }
187 }
188 else{
189 return false;
190 }
191 }
192 else if(mem.age<18 && mem.age>0){
193 buff=rda.filter(function(d){
194 return d.subject=="female_"+mem.age+"y";
195 })[0];
196 }
197 else if(mem.month>=9){
198 buff=rda.filter(function(d){
199 return d.subject=="infant_9m-12m";
200 })[0];
201 }
202 else if(mem.month>=6){
203 buff=rda.filter(function(d){
204 return d.subject=="infant_6m-9m";
205 })[0];
206 }
207 else if(mem.month>=0){
208 if(mem.month===""){
209 return false;
210 }
211 buff=rda.filter(function(d){
212 return d.subject=="infant_0m-6m";
213 })[0];
214 }
215 else{
216 return false;
217 }
218 }
219 // Male
220 else if(mem.sex=="m"){
221 if(mem.age>=18){
222 if(mem.work=="sedentary"){
223 buff=rda.filter(function(d){
224 return d.subject=="male_sedentary";
225 })[0];
226 }
227 else if(mem.work=="moderate"){
228 buff=rda.filter(function(d){
229 return d.subject=="male_moderate";
230 })[0];
231 }
232 else if(mem.work=="heavy"){
233 buff=rda.filter(function(d){
234 return d.subject=="male_heavy";
235 })[0];
236 }
237 else{
238 return false;
239 }
240 }
241 else if(mem.age<18 && mem.age>0){
242 buff=rda.filter(function(d){
243 return d.subject=="male_"+mem.age+"y";
244 })[0];
245 }
246 else if(mem.month>=9){
247 buff=rda.filter(function(d){
248 return d.subject=="infant_9m-12m";
249 })[0];
250 }
251 else if(mem.month>=6){
252 buff=rda.filter(function(d){
253 return d.subject=="infant_6m-9m";
254 })[0];
255 }
256 else if(mem.month>=0){
257 if(mem.month===""){
258 return false;
259 }
260 buff=rda.filter(function(d){
261 return d.subject=="infant_0m-6m";
262 })[0];
263 }
264 else{
265 return false;
266 }
267 }
268 else{
269 return false;
270 }
271 buff.name=mem.name;
272 root.req.list.push(buff);
273 }
274 root.req.total.energy=0;
275 root.req.total.protein=0;
276 root.req.total.iron=0;
277 root.req.total.vitA=0;
278 root.req.total.thiamine=0;
279 root.req.total.riboflavin=0;
280 root.req.total.vitC=0;
281 for(var i=0; i<root.req.list.length; i++){
282 root.req.total.energy = +root.req.total.energy + +root.req.list[i].energy;
283 root.req.total.protein = +root.req.total.protein + +root.req.list[i].protein;
284 root.req.total.iron = +root.req.total.iron + +root.req.list[i].iron;
285 root.req.total.vitA = +root.req.total.vitA + +root.req.list[i].vitA;
286 root.req.total.thiamine = +root.req.total.thiamine + +root.req.list[i].thiamine;
287 root.req.total.riboflavin = +root.req.total.riboflavin + +root.req.list[i].riboflavin;
288 root.req.total.vitC = +root.req.total.vitC + +root.req.list[i].vitC;
289 }
290 // Intake Calculation
291 root.intk={};
292 root.intk.list=[];
293 root.intk.total={};
294 for(var i=0; i<this.dataObj.food.length; i++){
295 var food=this.dataObj.food[i];
296 var buff={};
297 if(food.name!=="" && food.amount!=="" && food.amount>=0){
298 buff.name=food.name;
299 buff.energy=val.filter(function(d){
300 return d.name==buff.name;
301 })[0].energy*food.amount/100;
302 buff.protein=val.filter(function(d){
303 return d.name==buff.name;
304 })[0].protein*food.amount/100;
305 buff.iron=val.filter(function(d){
306 return d.name==buff.name;
307 })[0].iron*food.amount/100;
308 buff.vitA=val.filter(function(d){
309 return d.name==buff.name;
310 })[0].vitA*food.amount/100;
311 buff.thiamine=val.filter(function(d){
312 return d.name==buff.name;
313 })[0].thiamine*food.amount/100;
314 buff.riboflavin=val.filter(function(d){
315 return d.name==buff.name;
316 })[0].riboflavin*food.amount/100;
317 buff.vitC=val.filter(function(d){
318 return d.name==buff.name;
319 })[0].vitC*food.amount/100;
320 root.intk.list.push(buff);
321 }
322 else{
323 return false;
324 }
325
326 }
327 root.intk.total.energy=0;
328 root.intk.total.protein=0;
329 root.intk.total.iron=0;
330 root.intk.total.vitA=0;
331 root.intk.total.thiamine=0;
332 root.intk.total.riboflavin=0;
333 root.intk.total.vitC=0;
334 for(var i=0; i<root.intk.list.length; i++){
335 root.intk.total.energy = +root.intk.total.energy + +root.intk.list[i].energy;
336 root.intk.total.protein = +root.intk.total.protein + +root.intk.list[i].protein;
337 root.intk.total.iron = +root.intk.total.iron + +root.intk.list[i].iron;
338 root.intk.total.vitA = +root.intk.total.vitA + +root.intk.list[i].vitA;
339 root.intk.total.thiamine = +root.intk.total.thiamine + +root.intk.list[i].thiamine;
340 root.intk.total.riboflavin = +root.intk.total.riboflavin + +root.intk.list[i].riboflavin;
341 root.intk.total.vitC = +root.intk.total.vitC + +root.intk.list[i].vitC;
342 }
343 // Comparison
344 root.comp={};
345 root.comp.energy = [ +root.intk.total.energy - +root.req.total.energy , (+root.intk.total.energy - +root.req.total.energy)*100/(+root.req.total.energy)];
346 root.comp.protein = [ +root.intk.total.protein - +root.req.total.protein , (+root.intk.total.protein - +root.req.total.protein)*100/(+root.req.total.protein)];
347 root.comp.iron = [ +root.intk.total.iron - +root.req.total.iron , (+root.intk.total.iron - +root.req.total.iron)*100/(+root.req.total.iron)];
348 root.comp.vitA = [ +root.intk.total.vitA - +root.req.total.vitA , (+root.intk.total.vitA - +root.req.total.vitA)*100/(+root.req.total.vitA)];
349 root.comp.thiamine = [ +root.intk.total.thiamine - +root.req.total.thiamine , (+root.intk.total.thiamine - +root.req.total.thiamine)*100/(+root.req.total.thiamine)];
350 root.comp.riboflavin = [ +root.intk.total.riboflavin - +root.req.total.riboflavin , (+root.intk.total.riboflavin - +root.req.total.riboflavin)*100/(+root.req.total.riboflavin)];
351 root.comp.vitC = [ +root.intk.total.vitC - +root.req.total.vitC , (+root.intk.total.vitC - +root.req.total.vitC)*100/(+root.req.total.vitC)];
352 return root;
353 }
354 }
355 }
356 </script>