]> Softwares of Agnibho - dietsurvey.git/blob - src/output.vue
Table scroll on narrow screen
[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 <div class="table-responsive">
37 <table class="table">
38 <thead>
39 <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>
40 </thead>
41 <tbody>
42 <tr v-for="i in calcVal.req.list">
43 <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>
44 </tr>
45 </tbody>
46 <thead>
47 <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>
48 </thead>
49 </table>
50 </div>
51 </div>
52 </div>
53 <!-- Consumption -->
54 <div class="panel panel-info">
55 <div class="panel-heading">
56 <div class="panel-title"><h3>Nutritional Value of Consumed Foods</h3></div>
57 </div>
58 <div class="panel-body">
59 <div class="table-responsive">
60 <table class="table">
61 <thead>
62 <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>
63 </thead>
64 <tbody>
65 <tr v-for="i in calcVal.intk.list">
66 <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>
67 </tr>
68 </tbody>
69 <thead>
70 <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>
71 </thead>
72 </table>
73 </div>
74 </div>
75 </div>
76 <!-- Comparison -->
77 <div class="panel panel-info">
78 <div class="panel-heading">
79 <div class="panel-title"><h3>Requirement vs Intake Comparison</h3></div>
80 </div>
81 <div class="panel-body">
82 <div class="table-responsive">
83 <table class="table">
84 <thead><tr><th>Nutrient</th><th>Total Requirement</th><th>Total Intake</th><th>Excess /Deficiency</th></tr></thead>
85 <tbody>
86 <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>
87 <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>
88 <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>
89 <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>
90 <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>
91 <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>
92 <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>
93 </tbody>
94 </table>
95 </div>
96 </div>
97 </div>
98 <!-- Summary -->
99 <div class="panel panel-info">
100 <div class="panel-heading">
101 <div class="panel-title"><h3>Summary</h3></div>
102 </div>
103 <div class="panel-body">
104 <ul class="list-group col-md-offset-4 col-md-4">
105 <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>
106 <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>
107 <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>
108 <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>
109 <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>
110 <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>
111 <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>
112 </ul>
113 </div>
114 </div>
115 <hr>
116 </div>
117 </div>
118 </template>
119
120 <script>
121 export default {
122 name:"Output",
123 props:["dataObj", "dataRef"],
124 filters:{
125 dec2: function(v){
126 return Math.round(v*100)/100;
127 },
128 cmp: function(v, f){
129 if(f==1){
130 if(v<0) return "deficit";
131 else return "excess";
132 }if(f==2){
133 if(v<0) return "Deficit by "+Math.abs(Math.round(v*100)/100);
134 else return "Excess by "+Math.abs(Math.round(v*100)/100);
135 }
136 else{
137 return Math.abs(Math.round(v*100)/100);
138 }
139 }
140 },
141 methods:{
142 colorCls: function(v){
143 if (v<0) return {"list-group-item-danger": true};
144 else return {"list-group-item-success": true};
145 }
146 },
147 computed:{
148 calcVal: function(){
149 var rda=this.dataRef.rda;
150 var val=this.dataRef.food;
151 var root={};
152 // Requirement Calculation
153 root.req={};
154 root.req.list=[];
155 root.req.total={};
156 for(var i=0; i<this.dataObj.family.length; i++){
157 var mem=this.dataObj.family[i];
158 var buff={};
159 // Retrieve individual rda
160 // Female
161 if(mem.sex=="f"){
162 if(mem.age>=18){
163 if(mem.state=="preg"){
164 buff=rda.filter(function(d){
165 return d.subject=="pregnant";
166 })[0];
167 }
168 else if(mem.state=="lact-6"){
169 buff=rda.filter(function(d){
170 return d.subject=="lactating_below6";
171 })[0];
172 }
173 else if(mem.state=="lact+6"){
174 buff=rda.filter(function(d){
175 return d.subject=="lactating_above6";
176 })[0];
177 }
178 else if(mem.state=="npnl"){
179 if(mem.work=="sedentary"){
180 buff=rda.filter(function(d){
181 return d.subject=="female_sedentary";
182 })[0];
183 }
184 else if(mem.work=="moderate"){
185 buff=rda.filter(function(d){
186 return d.subject=="female_moderate";
187 })[0];
188 }
189 else if(mem.work=="heavy"){
190 buff=rda.filter(function(d){
191 return d.subject=="female_heavy";
192 })[0];
193 }
194 }
195 else{
196 return false;
197 }
198 }
199 else if(mem.age<18 && mem.age>0){
200 buff=rda.filter(function(d){
201 return d.subject=="female_"+mem.age+"y";
202 })[0];
203 }
204 else if(mem.month>=9){
205 buff=rda.filter(function(d){
206 return d.subject=="infant_9m-12m";
207 })[0];
208 }
209 else if(mem.month>=6){
210 buff=rda.filter(function(d){
211 return d.subject=="infant_6m-9m";
212 })[0];
213 }
214 else if(mem.month>=0){
215 if(mem.month===""){
216 return false;
217 }
218 buff=rda.filter(function(d){
219 return d.subject=="infant_0m-6m";
220 })[0];
221 }
222 else{
223 return false;
224 }
225 }
226 // Male
227 else if(mem.sex=="m"){
228 if(mem.age>=18){
229 if(mem.work=="sedentary"){
230 buff=rda.filter(function(d){
231 return d.subject=="male_sedentary";
232 })[0];
233 }
234 else if(mem.work=="moderate"){
235 buff=rda.filter(function(d){
236 return d.subject=="male_moderate";
237 })[0];
238 }
239 else if(mem.work=="heavy"){
240 buff=rda.filter(function(d){
241 return d.subject=="male_heavy";
242 })[0];
243 }
244 else{
245 return false;
246 }
247 }
248 else if(mem.age<18 && mem.age>0){
249 buff=rda.filter(function(d){
250 return d.subject=="male_"+mem.age+"y";
251 })[0];
252 }
253 else if(mem.month>=9){
254 buff=rda.filter(function(d){
255 return d.subject=="infant_9m-12m";
256 })[0];
257 }
258 else if(mem.month>=6){
259 buff=rda.filter(function(d){
260 return d.subject=="infant_6m-9m";
261 })[0];
262 }
263 else if(mem.month>=0){
264 if(mem.month===""){
265 return false;
266 }
267 buff=rda.filter(function(d){
268 return d.subject=="infant_0m-6m";
269 })[0];
270 }
271 else{
272 return false;
273 }
274 }
275 else{
276 return false;
277 }
278 buff.name=mem.name;
279 root.req.list.push(buff);
280 }
281 root.req.total.energy=0;
282 root.req.total.protein=0;
283 root.req.total.iron=0;
284 root.req.total.vitA=0;
285 root.req.total.thiamine=0;
286 root.req.total.riboflavin=0;
287 root.req.total.vitC=0;
288 for(var i=0; i<root.req.list.length; i++){
289 root.req.total.energy = +root.req.total.energy + +root.req.list[i].energy;
290 root.req.total.protein = +root.req.total.protein + +root.req.list[i].protein;
291 root.req.total.iron = +root.req.total.iron + +root.req.list[i].iron;
292 root.req.total.vitA = +root.req.total.vitA + +root.req.list[i].vitA;
293 root.req.total.thiamine = +root.req.total.thiamine + +root.req.list[i].thiamine;
294 root.req.total.riboflavin = +root.req.total.riboflavin + +root.req.list[i].riboflavin;
295 root.req.total.vitC = +root.req.total.vitC + +root.req.list[i].vitC;
296 }
297 // Intake Calculation
298 root.intk={};
299 root.intk.list=[];
300 root.intk.total={};
301 for(var i=0; i<this.dataObj.food.length; i++){
302 var food=this.dataObj.food[i];
303 var buff={};
304 if(food.name!=="" && food.amount!=="" && food.amount>=0){
305 buff.name=food.name;
306 buff.energy=val.filter(function(d){
307 return d.name==buff.name;
308 })[0].energy*food.amount/100;
309 buff.protein=val.filter(function(d){
310 return d.name==buff.name;
311 })[0].protein*food.amount/100;
312 buff.iron=val.filter(function(d){
313 return d.name==buff.name;
314 })[0].iron*food.amount/100;
315 buff.vitA=val.filter(function(d){
316 return d.name==buff.name;
317 })[0].vitA*food.amount/100;
318 buff.thiamine=val.filter(function(d){
319 return d.name==buff.name;
320 })[0].thiamine*food.amount/100;
321 buff.riboflavin=val.filter(function(d){
322 return d.name==buff.name;
323 })[0].riboflavin*food.amount/100;
324 buff.vitC=val.filter(function(d){
325 return d.name==buff.name;
326 })[0].vitC*food.amount/100;
327 root.intk.list.push(buff);
328 }
329 else{
330 return false;
331 }
332
333 }
334 root.intk.total.energy=0;
335 root.intk.total.protein=0;
336 root.intk.total.iron=0;
337 root.intk.total.vitA=0;
338 root.intk.total.thiamine=0;
339 root.intk.total.riboflavin=0;
340 root.intk.total.vitC=0;
341 for(var i=0; i<root.intk.list.length; i++){
342 root.intk.total.energy = +root.intk.total.energy + +root.intk.list[i].energy;
343 root.intk.total.protein = +root.intk.total.protein + +root.intk.list[i].protein;
344 root.intk.total.iron = +root.intk.total.iron + +root.intk.list[i].iron;
345 root.intk.total.vitA = +root.intk.total.vitA + +root.intk.list[i].vitA;
346 root.intk.total.thiamine = +root.intk.total.thiamine + +root.intk.list[i].thiamine;
347 root.intk.total.riboflavin = +root.intk.total.riboflavin + +root.intk.list[i].riboflavin;
348 root.intk.total.vitC = +root.intk.total.vitC + +root.intk.list[i].vitC;
349 }
350 // Comparison
351 root.comp={};
352 root.comp.energy = [ +root.intk.total.energy - +root.req.total.energy , (+root.intk.total.energy - +root.req.total.energy)*100/(+root.req.total.energy)];
353 root.comp.protein = [ +root.intk.total.protein - +root.req.total.protein , (+root.intk.total.protein - +root.req.total.protein)*100/(+root.req.total.protein)];
354 root.comp.iron = [ +root.intk.total.iron - +root.req.total.iron , (+root.intk.total.iron - +root.req.total.iron)*100/(+root.req.total.iron)];
355 root.comp.vitA = [ +root.intk.total.vitA - +root.req.total.vitA , (+root.intk.total.vitA - +root.req.total.vitA)*100/(+root.req.total.vitA)];
356 root.comp.thiamine = [ +root.intk.total.thiamine - +root.req.total.thiamine , (+root.intk.total.thiamine - +root.req.total.thiamine)*100/(+root.req.total.thiamine)];
357 root.comp.riboflavin = [ +root.intk.total.riboflavin - +root.req.total.riboflavin , (+root.intk.total.riboflavin - +root.req.total.riboflavin)*100/(+root.req.total.riboflavin)];
358 root.comp.vitC = [ +root.intk.total.vitC - +root.req.total.vitC , (+root.intk.total.vitC - +root.req.total.vitC)*100/(+root.req.total.vitC)];
359 return root;
360 }
361 }
362 }
363 </script>