www/js/rec_edit.js

changeset 343
82184e3be6d9
parent 340
fa4eb830c151
child 347
e6e7ec9e33e0
equal deleted inserted replaced
342:3ac81572bb28 343:82184e3be6d9
289 } else { 289 } else {
290 result = 15.25 / (6 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 21) /6, 2)); 290 result = 15.25 / (6 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 21) /6, 2));
291 if (result < 0.10) 291 if (result < 0.10)
292 result = 0.10; // assume 10% flavourcontribution as a minimum 292 result = 0.10; // assume 10% flavourcontribution as a minimum
293 } 293 }
294 result = (result * amount * 1000) / vol; 294 return (result * amount * 1000) / vol;
295 // console.log("hopFlavourContribution("+bt+","+vol+","+use+","+amount+"): "+result);
296 return result;
297 } 295 }
298 296
299 function hopAromaContribution(bt, vol, use, amount) { 297 function hopAromaContribution(bt, vol, use, amount) {
300 var result = 0; 298 var result = 0;
301 299
302 if (bt > 20) { 300 if (use == 5) { // Dry hop
301 result = 1.33;
302 } else if (bt > 20) {
303 result = 0; 303 result = 0;
304 } else if (bt > 7.5) { 304 } else if (bt > 7.5) {
305 result = 10.03 / (4 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 7.5) /4, 2)); 305 result = 10.03 / (4 * Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * Math.pow((bt - 7.5) /4, 2));
306 } else if (use == 2) { // Boil 306 } else if (use == 2) { // Boil
307 result = 1; 307 result = 1;
308 } else if (use == 3) { // Aroma / vlamuit 308 } else if (use == 3) { // Aroma / vlamuit
309 result = 1.2; 309 result = 1.2;
310 } else if (use == 4) { // Whirlpool 310 } else if (use == 4) { // Whirlpool
311 result = 1.2; 311 result = 1.2;
312 } else if (use == 5) { // Dry hop 312 }
313 result = 1.33; 313 return (result * amount * 1000) / vol;
314 }
315 result = (result * amount * 1000) / vol;
316 // console.log("hopAromaContribution("+bt+","+vol+","+use+","+amount+"): "+result);
317 return result;
318 } 314 }
319 315
320 function calcIBUs() { 316 function calcIBUs() {
321 var total_ibus = 0; 317 var total_ibus = 0;
322 hop_aroma = hop_flavour = 0; 318 hop_aroma = hop_flavour = 0;
323 var rows = $('#hopGrid').jqxGrid('getrows'); 319 var rows = {};
320 if (!(rows = $('#hopGrid').jqxGrid('getrows'))) {
321 return;
322 }
324 for (var i = 0; i < rows.length; i++) { 323 for (var i = 0; i < rows.length; i++) {
325 var row = rows[i]; 324 var row = rows[i];
326 total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size), 325 total_ibus += toIBU(row.h_useat, row.h_form, preboil_sg, parseFloat(dataRecord.batch_size),
327 parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method); 326 parseFloat(row.h_amount), parseFloat(row.h_time), parseFloat(row.h_alpha), dataRecord.ibu_method);
328 hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size), 327 hop_flavour += hopFlavourContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
329 row.h_useat, parseFloat(row.h_amount)); 328 row.h_useat, parseFloat(row.h_amount));
330 hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size), 329 hop_aroma += hopAromaContribution(parseFloat(row.h_time), parseFloat(dataRecord.batch_size),
331 row.h_useat, parseFloat(row.h_amount)); 330 row.h_useat, parseFloat(row.h_amount));
332 } 331 }
333 total_ibus = Math.round(total_ibus); 332 total_ibus = Math.round(total_ibus * 10) / 10;
333 hop_flavour = Math.round(hop_flavour * 100) / 10;
334 hop_aroma = Math.round(hop_aroma * 100) / 10;
335 if (hop_flavour > 100)
336 hop_flavour = 100;
337 if (hop_aroma > 100)
338 hop_aroma = 100;
334 console.log("calcIBUs(): " + total_ibus + " flavour: " + hop_flavour + " aroma: " + hop_aroma); 339 console.log("calcIBUs(): " + total_ibus + " flavour: " + hop_flavour + " aroma: " + hop_aroma);
335 dataRecord.est_ibu = total_ibus; 340 dataRecord.est_ibu = total_ibus;
336 $('#est_ibu').val(total_ibus); 341 $('#est_ibu').val(total_ibus);
337 $('#est_ibu2').val(total_ibus); 342 $('#est_ibu2').val(total_ibus);
338 $("#hop_flavour").jqxProgressBar('val', hop_flavour * 10); 343 $("#hop_flavour").jqxProgressBar('val', hop_flavour);
339 $("#hop_aroma").jqxProgressBar('val', hop_aroma * 10); 344 $("#hop_aroma").jqxProgressBar('val', hop_aroma);
340 }; 345 };
341 346
342 function adjustHops(factor) { 347 function adjustHops(factor) {
343 348
344 console.log("adjustHops("+factor+")"); 349 console.log("adjustHops("+factor+")");

mercurial