www/js/prod_edit.js

changeset 278
dc22dd5d77fd
parent 273
19606adfea42
child 280
c1f2a90c93ca
equal deleted inserted replaced
277:7776b3c68c46 278:dc22dd5d77fd
52 var est_mash_sg = 0; 52 var est_mash_sg = 0;
53 var psugar = 0; // Percentage real sugars 53 var psugar = 0; // Percentage real sugars
54 var pcara = 0; // Percentage cara/crystal malts 54 var pcara = 0; // Percentage cara/crystal malts
55 var svg = 77; // Default attenuation 55 var svg = 77; // Default attenuation
56 var mashkg = 0; // Malt in mash weight 56 var mashkg = 0; // Malt in mash weight
57 var pitchrate = 0.75; // Yeast pitch rate default
58 var initcells = 0; // Initial yeast cell count
57 59
58 var hop_flavour = 0; 60 var hop_flavour = 0;
59 var hop_aroma = 0; 61 var hop_aroma = 0;
60 var mash_infuse = 0; 62 var mash_infuse = 0;
61 var last_base = ''; 63 var last_base = '';
193 195
194 // Recalculate volumes. 196 // Recalculate volumes.
195 var aboil_volume = parseFloat(dataRecord.batch_size); 197 var aboil_volume = parseFloat(dataRecord.batch_size);
196 if (dataRecord.brew_aboil_volume > 0) 198 if (dataRecord.brew_aboil_volume > 0)
197 aboil_volume = dataRecord.brew_aboil_volume / 1.04; // volume @ 20 degrees 199 aboil_volume = dataRecord.brew_aboil_volume / 1.04; // volume @ 20 degrees
200 if (dataRecord.brew_fermenter_tcloss == 0) {
201 dataRecord.brew_fermenter_tcloss = dataRecord.eq_trub_chiller_loss;
202 $("#brew_fermenter_tcloss").val(dataRecord.brew_fermenter_tcloss);
203 }
198 dataRecord.brew_fermenter_volume = aboil_volume - dataRecord.brew_fermenter_tcloss + dataRecord.brew_fermenter_extrawater; 204 dataRecord.brew_fermenter_volume = aboil_volume - dataRecord.brew_fermenter_tcloss + dataRecord.brew_fermenter_extrawater;
199 $("#brew_fermenter_volume").val(dataRecord.brew_fermenter_volume); 205 $("#brew_fermenter_volume").val(dataRecord.brew_fermenter_volume);
200 // Estimated needed sparge water corrected for the temperature. 206 // Estimated needed sparge water corrected for the temperature.
201 var spoelw = (dataRecord.boil_size - mash_infuse + (mashkg * my_grain_absorbtion) + dataRecord.eq_lauter_deadspace) * 1.03; 207 var spoelw = (dataRecord.boil_size - mash_infuse + (mashkg * my_grain_absorbtion) + dataRecord.eq_lauter_deadspace) * 1.03;
202 $("#brew_sparge_est").val(spoelw); 208 $("#brew_sparge_est").val(spoelw);
251 $("#perc_cara").jqxProgressBar('val', pcara); 257 $("#perc_cara").jqxProgressBar('val', pcara);
252 calcStage(); 258 calcStage();
253 259
254 // Calculate estimated svg. 260 // Calculate estimated svg.
255 svg = 0; // default. 261 svg = 0; // default.
262 initcells = 0;
256 var rows = $('#yeastGrid').jqxGrid('getrows'); 263 var rows = $('#yeastGrid').jqxGrid('getrows');
257 for (var i = 0; i < rows.length; i++) { 264 for (var i = 0; i < rows.length; i++) {
258 var row = rows[i]; 265 var row = rows[i];
259 if (row.y_use == 0) { // Primary 266 if (row.y_use == 0) { // Primary
260 if (parseFloat(row.y_attenuation) > svg) 267 if (parseFloat(row.y_attenuation) > svg)
261 svg = parseFloat(row.y_attenuation); // Take the highest if multiple yeasts. 268 svg = parseFloat(row.y_attenuation); // Take the highest if multiple yeasts.
269 if (row.y_form == 0)
270 initcells += (parseFloat(row.y_cells) / 1000000000) * parseFloat(row.y_amount);
271 else
272 initcells += (parseFloat(row.y_cells) / 1000000) * parseFloat(row.y_amount);
262 } 273 }
263 // TODO: brett in secondary ?? 274 // TODO: brett in secondary ??
264 } 275 }
265 if (svg == 0) 276 if (svg == 0)
266 svg = 77; 277 svg = 77;
282 if ((dataRecord.stage >= 6) && (dataRecord.fg > 0.990) && (dataRecord.fg < dataRecord.brew_fermenter_sg)) { 293 if ((dataRecord.stage >= 6) && (dataRecord.fg > 0.990) && (dataRecord.fg < dataRecord.brew_fermenter_sg)) {
283 svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.fg) / (dataRecord.brew_fermenter_sg - 1); 294 svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.fg) / (dataRecord.brew_fermenter_sg - 1);
284 //console.log("real svg:"+svg); 295 //console.log("real svg:"+svg);
285 } 296 }
286 297
298 $("#yeast_cells").val(initcells);
299 $("#need_cells").val(getNeededYeastCells());
287 }; 300 };
288 301
289 /* 302 /*
290 * Change OG of recipe but keep the water volumes. 303 * Change OG of recipe but keep the water volumes.
291 */ 304 */
314 var amount = row.f_percentage / 100 * totmass; 327 var amount = row.f_percentage / 100 * totmass;
315 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount); 328 $("#fermentableGrid").jqxGrid('setcellvalue', i, "f_amount", amount);
316 } 329 }
317 } 330 }
318 }; 331 };
332
333 function getNeededYeastCells() {
334
335 var sg = dataRecord.brew_fermenter_sg;
336 if (sg <= 1.0001 && dataRecord.fg > 1.000)
337 sg = dataRecord.fg;
338 else if (sg <= 1.0001)
339 sg = dataRecord.est_og;
340 var plato = sg_to_plato(sg);
341
342 var volume = dataRecord.brew_fermenter_volume;
343 if (volume <= 0)
344 volume = dataRecord.batch_size - dataRecord.eq_trub_chiller_loss;
345
346 //console.log("getNeededYeastCells f:"+f+" volume:"+volume+" plato:"+plato+" sg:"+sg);
347 var result = pitchrate * volume * plato;
348 //console.log("getNeededYeastCells("+pitchrate+"): "+result+" billion cells");
349 return result;
350 }
319 351
320 function hopFlavourContribution(bt, vol, use, amount) { 352 function hopFlavourContribution(bt, vol, use, amount) {
321 var result; 353 var result;
322 354
323 if (use == 1) { // First wort 355 if (use == 1) { // First wort
385 $('#est_ibu2').val(total_ibus); 417 $('#est_ibu2').val(total_ibus);
386 $("#hop_flavour").jqxProgressBar('val', hop_flavour); 418 $("#hop_flavour").jqxProgressBar('val', hop_flavour);
387 $("#hop_aroma").jqxProgressBar('val', hop_aroma); 419 $("#hop_aroma").jqxProgressBar('val', hop_aroma);
388 $("#brew_fermenter_ibu").val(ferm_ibus); 420 $("#brew_fermenter_ibu").val(ferm_ibus);
389 calcStage(); 421 calcStage();
422 };
423
424 /*
425 * http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
426 *
427 * stype: 0=stirred, 1=shaken, 2=simple
428 * totcells: initial cells
429 * egrams: gram extract
430 */
431 function getGrowthRate(stype, totcells, egrams){
432
433 /* Cells per grams extract (B/g) */
434 var cpe = totcells / egrams;
435
436 if (cpe > 3.5)
437 return 0; // no growth
438 if (stype == 2)
439 return 0.4; // simple starter
440 if (stype == 1)
441 return 0.62; // shaken starter
442 if (cpe <= 1.4) // stirred starter
443 return 1.4;
444 return 2.33 - (.67 * cpe );
445 };
446
447 function calcStep(svol, stype, start) {
448
449 var gperpoint = 2.72715; //number of grams of extract per point of starter gravity per liter
450 var prate = start/svol * 1000;
451 var irate = Math.round(prate * 10) / 10;
452 var egrams = (dataRecord.starter_sg - 1) * svol * gperpoint;
453 var grate = getGrowthRate(stype, start, egrams);
454 var ncells = Math.round(egrams * grate);
455 var totcells = parseFloat(ncells) + start;
456 console.log("svol:"+svol+" start:"+start+" irate:"+irate+" egrams:"+egrams+" grate:"+grate+" ncells:"+ncells);
457 return {
458 svol: svol,
459 irate: irate,
460 prate: Math.round(prate * 10)/10,
461 ncells: ncells,
462 totcells: totcells,
463 growf: Math.round(ncells/start*100)/100
464 };
465 }
466
467 /*
468 * Calculate all starter steps.
469 * stype: final starter type: 0 = stirred, 1 = shaked, 2 = simple.
470 * start: initial cells in billions
471 * needed: needed cells in billions
472 *
473 * result: all values updated.
474 */
475 function calcSteps(stype, start, needed) {
476
477 var uvols = [ 20, 40, 60, 80, 100, 150, 200, 250, 375, 500, 625, 750, 875, 1000, 1250, 1500, 2000, 2500, 3000, 4000, 5000 ];
478 var mvols = uvols.length;
479 var svol = 0;
480 var lasti = 0;
481 var result = {};
482
483 /*
484 * If no values are set, auto calculate the starter.
485 */
486 if ((parseFloat($("#prop1_volume").jqxNumberInput('decimal')) + parseFloat($("#prop2_volume").jqxNumberInput('decimal')) +
487 parseFloat($("#prop3_volume").jqxNumberInput('decimal')) + parseFloat($("#prop4_volume").jqxNumberInput('decimal'))) == 0) {
488 // clear by default
489 for (var i = 1; i < 5; i++) {
490 $("#prop"+i+"_type").hide();
491 $("#r"+i+"_pmpt").show();
492 $("#prop"+i+"_type").val(stype);
493 $("#prop"+i+"_volume").hide();
494 $("#prop"+i+"_volume").val(0);
495 $("#prop"+i+"_irate").hide();
496 $("#prop"+i+"_ncells").hide();
497 $("#prop"+i+"_tcells").hide();
498 $("#prop"+i+"_growf").hide();
499 }
500 if (start > needed) {
501 return; // no starter needed
502 }
503 $("#prop1_type").show();
504 $("#r1_pmpt").hide();
505 $("#prop1_volume").show();
506 $("#prop1_irate").show();
507 $("#prop1_ncells").show();
508 $("#prop1_tcells").show();
509 $("#prop1_growf").show();
510 for (var i = lasti; i <= mvols; i++) {
511 lasti = i;
512 svol = uvols[lasti];
513 result = calcStep(svol, stype, start);
514 if (result.irate < 25) {
515 // inocculation rate too low, backup one step and break out.
516 lasti = i - 1;
517 svol = uvols[lasti];
518 result = calcStep(svol, stype, start);
519 break;
520 }
521 if (result.totcells > needed || i == mvols) { // hit the target or loops done
522 break;
523 }
524 }
525 $("#prop1_volume").val(result.svol / 1000); // to liters
526 $("#prop1_irate").val(result.prate);
527 $("#prop1_ncells").val(result.ncells);
528 $("#prop1_tcells").val(result.totcells);
529 $("#prop1_growf").val(result.growf);
530 if (result.totcells > needed)
531 return; // hit the target
532
533 // second stage
534 $("#r2_pmpt").hide();
535 $("#prop2_type").val(stype);
536 $("#prop2_type").show();
537 $("#prop2_volume").show();
538 $("#prop2_irate").show();
539 $("#prop2_ncells").show();
540 $("#prop2_tcells").show();
541 $("#prop2_growf").show();
542 for (var i = lasti; i <= mvols; i++) {
543 lasti = i;
544 svol = uvols[lasti];
545 result = calcStep(svol, stype, $("#prop1_tcells").val());
546 if (result.irate < 25) {
547 lasti = i - 1;
548 svol = uvols[lasti];
549 result = calcStep(svol, stype, $("#prop1_tcells").val());
550 break;
551 }
552 if (result.totcells > needed || i == mvols) { // hit the target or loops done
553 break;
554 }
555 }
556 $("#prop2_volume").val(result.svol / 1000); // to liters
557 $("#prop2_irate").val(result.prate);
558 $("#prop2_ncells").val(result.ncells);
559 $("#prop2_tcells").val(result.totcells);
560 $("#prop2_growf").val(result.growf);
561 if (result.totcells > needed)
562 return; // hit the target
563
564 // third stage
565 $("#r3_pmpt").hide();
566 $("#prop3_type").val(stype);
567 $("#prop3_type").show();
568 $("#prop3_volume").show();
569 $("#prop3_irate").show();
570 $("#prop3_ncells").show();
571 $("#prop3_tcells").show();
572 $("#prop3_growf").show();
573 for (var i = lasti; i <= mvols; i++) {
574 lasti = i;
575 svol = uvols[lasti];
576 result = calcStep(svol, stype, $("#prop2_tcells").val());
577 if (result.irate < 25) {
578 lasti = i - 1;
579 svol = uvols[lasti];
580 result = calcStep(svol, stype, $("#prop2_tcells").val());
581 break;
582 }
583 if (result.totcells > needed || i == mvols) { // hit the target or loops done
584 break;
585 }
586 }
587 $("#prop3_volume").val(result.svol / 1000); // to liters
588 $("#prop3_irate").val(result.prate);
589 $("#prop3_ncells").val(result.ncells);
590 $("#prop3_tcells").val(result.totcells);
591 $("#prop3_growf").val(result.growf);
592 if (result.totcells > needed)
593 return; // hit the target
594
595 // fourth stage
596 $("#r4_pmpt").hide();
597 $("#prop4_type").val(stype);
598 $("#prop4_type").show();
599 $("#prop4_volume").show();
600 $("#prop4_irate").show();
601 $("#prop4_ncells").show();
602 $("#prop4_tcells").show();
603 $("#prop4_growf").show();
604 for (var i = lasti; i <= mvols; i++) {
605 lasti = i;
606 svol = uvols[lasti];
607 result = calcStep(svol, stype, $("#prop3_tcells").val());
608 if (result.totcells > needed || i == mvols) { // hit the target or loops done
609 $("#prop4_volume").val(result.svol / 1000); // to liters
610 $("#prop4_irate").val(result.prate);
611 $("#prop4_ncells").val(result.ncells);
612 $("#prop4_tcells").val(result.totcells);
613 $("#prop4_growf").val(result.growf);
614 return;
615 }
616 }
617 } else {
618 // recalculate
619 if (dataRecord.prop1_volume > 0) {
620 $("#r1_pmpt").hide();
621 $("#prop1_type").show();
622 $("#prop1_volume").show();
623 $("#prop1_irate").show();
624 $("#prop1_ncells").show();
625 $("#prop1_tcells").show();
626 $("#prop1_growf").show();
627 result = calcStep($("#prop1_volume").val() * 1000, dataRecord.prop1_type, start);
628 $("#prop1_irate").val(result.prate);
629 $("#prop1_ncells").val(result.ncells);
630 $("#prop1_tcells").val(result.totcells);
631 $("#prop1_growf").val(result.growf);
632 }
633 if (dataRecord.prop2_volume > 0) {
634 $("#r2_pmpt").hide();
635 $("#prop2_type").show();
636 $("#prop2_volume").show();
637 $("#prop2_irate").show();
638 $("#prop2_ncells").show();
639 $("#prop2_tcells").show();
640 $("#prop2_growf").show();
641 result = calcStep($("#prop2_volume").val() * 1000, dataRecord.prop2_type, $("#prop1_tcells").val());
642 $("#prop2_irate").val(result.prate);
643 $("#prop2_ncells").val(result.ncells);
644 $("#prop2_tcells").val(result.totcells);
645 $("#prop2_growf").val(result.growf);
646 }
647 if (dataRecord.prop3_volume > 0) {
648 $("#r3_pmpt").hide();
649 $("#prop3_type").show();
650 $("#prop3_volume").show();
651 $("#prop3_irate").show();
652 $("#prop3_ncells").show();
653 $("#prop3_tcells").show();
654 $("#prop3_growf").show();
655 result = calcStep($("#prop3_volume").val() * 1000, dataRecord.prop3_type, $("#prop2_tcells").val());
656 $("#prop3_irate").val(result.prate);
657 $("#prop3_ncells").val(result.ncells);
658 $("#prop3_tcells").val(result.totcells);
659 $("#prop3_growf").val(result.growf);
660 }
661 if (dataRecord.prop4_volume > 0) {
662 $("#r4_pmpt").hide();
663 $("#prop4_type").show();
664 $("#prop4_volume").show();
665 $("#prop4_irate").show();
666 $("#prop4_ncells").show();
667 $("#prop4_tcells").show();
668 $("#prop4_growf").show();
669 result = calcStep($("#prop4_volume").val() * 1000, dataRecord.prop4_type, $("#prop3_tcells").val());
670 $("#prop4_irate").val(result.prate);
671 $("#prop4_ncells").val(result.ncells);
672 $("#prop4_tcells").val(result.totcells);
673 $("#prop4_growf").val(result.growf);
674 }
675
676 }
677 }
678
679 function calcYeast() {
680
681 // Also in calcFermentables()
682 $("#yeast_cells").val(initcells);
683
684 if (!(rows = $('#yeastGrid').jqxGrid('getrows'))) {
685 return; // grid not yet loaded.
686 }
687 var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
688 if (rowscount == 0)
689 return; // no yeast in recipe
690
691 for (var i = 0; i < rowscount; i++) {
692 var row = $("#yeastGrid").jqxGrid('getrowdata', i);
693 if (row.y_use == 0) { // primary
694 // pitchrate see https://www.brewersfriend.com/yeast-pitch-rate-and-starter-calculator/
695 // and http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
696 pitchrate = 0.75;
697 if (dataRecord.est_og > 1.060)
698 pitchrate = 1.0;
699 if (row.y_type == 0) // lager yeast
700 pitchrate *= 2;
701
702 if (row.y_form == 1) { // dry yeast
703 } else { // possible starter needed
704 }
705 }
706 }
707 var needed = getNeededYeastCells();
708 console.log("calcYeast() pitchrate:"+pitchrate+" start:"+initcells+" needed:"+needed);
709 calcSteps(dataRecord.starter_type, initcells, needed);
710 //console.log("calcYeast() pitchrate:"+pitchrate+" needed:"+needed);
711 $("#need_cells").val(needed);
712
713 $("#r1_irate").html("");
714 $("#r1_growf").html("");
715 $("#r1_tcells").html("");
716 if (parseFloat($("#prop1_volume").val()) > 0) {
717 if ((parseFloat($("#prop1_irate").val()) < 25) || (parseFloat($("#prop1_irate").val()) > 100)) {
718 $("#r1_irate").html("<img src='images/dialog-error.png'>");
719 } else {
720 $("#r1_irate").html("<img src='images/dialog-ok-apply.png'>");
721 }
722 if (parseFloat($("#prop1_growf").val()) < 1)
723 $("#r1_growf").html("<img src='images/dialog-error.png'>");
724 if (($("#prop1_type").val() > 0) && (parseFloat($("#prop1_growf").val()) > 3))
725 $("#r1_growf").html("<img src='images/dialog-error.png'>");
726 if (parseFloat($("#prop1_tcells").val()) > needed)
727 $("#r1_tcells").html("<img src='images/dialog-ok-apply.png'>");
728 }
729 $("#r2_irate").html("");
730 $("#r2_growf").html("");
731 $("#r2_tcells").html("");
732 if (parseFloat($("#prop2_volume").val()) > 0) {
733 if ((parseFloat($("#prop2_irate").val()) < 25) || (parseFloat($("#prop2_irate").val()) > 100)) {
734 $("#r2_irate").html("<img src='images/dialog-error.png'>");
735 } else {
736 $("#r2_irate").html("<img src='images/dialog-ok-apply.png'>");
737 }
738 if (parseFloat($("#prop2_growf").val()) < 1)
739 $("#r2_growf").html("<img src='images/dialog-error.png'>");
740 if (($("#prop2_type").val() > 0) && (parseFloat($("#prop2_growf").val()) > 3))
741 $("#r2_growf").html("<img src='images/dialog-error.png'>");
742 if (parseFloat($("#prop2_tcells").val()) > needed)
743 $("#r2_tcells").html("<img src='images/dialog-ok-apply.png'>");
744 }
745 $("#r3_irate").html("");
746 $("#r3_growf").html("");
747 $("#r3_tcells").html("");
748 if (parseFloat($("#prop3_volume").val()) > 0) {
749 if ((parseFloat($("#prop3_irate").val()) < 25) || (parseFloat($("#prop3_irate").val()) > 100)) {
750 $("#r3_irate").html("<img src='images/dialog-error.png'>");
751 } else {
752 $("#r3_irate").html("<img src='images/dialog-ok-apply.png'>");
753 }
754 if (parseFloat($("#prop3_growf").val()) < 1)
755 $("#r3_growf").html("<img src='images/dialog-error.png'>");
756 if (($("#prop3_type").val() > 0) && (parseFloat($("#prop3_growf").val()) > 3))
757 $("#r3_growf").html("<img src='images/dialog-error.png'>");
758 if (parseFloat($("#prop3_tcells").val()) > needed)
759 $("#r3_tcells").html("<img src='images/dialog-ok-apply.png'>");
760 }
761 $("#r4_irate").html("");
762 $("#r4_growf").html("");
763 $("#r4_tcells").html("");
764 if (parseFloat($("#prop4_volume").val()) > 0) {
765 if ((parseFloat($("#prop4_irate").val()) < 25) || (parseFloat($("#prop4_irate").val()) > 100)) {
766 $("#r4_irate").html("<img src='images/dialog-error.png'>");
767 } else {
768 $("#r4_irate").html("<img src='images/dialog-ok-apply.png'>");
769 }
770 if (parseFloat($("#prop4_growf").val()) < 1)
771 $("#r4_growf").html("<img src='images/dialog-error.png'>");
772 if (($("#prop4_type").val() > 0) && (parseFloat($("#prop4_growf").val()) > 3))
773 $("#r4_growf").html("<img src='images/dialog-error.png'>");
774 if (parseFloat($("#prop4_tcells").val()) > needed)
775 $("#r4_tcells").html("<img src='images/dialog-ok-apply.png'>");
776 } else {
777 $("#r4_irate").html("");
778 }
390 }; 779 };
391 780
392 function adjustHops(factor) { 781 function adjustHops(factor) {
393 782
394 console.log("adjustHops("+factor+")"); 783 console.log("adjustHops("+factor+")");
452 if (row.y_form == 1) { // Only adjust dry yeast 841 if (row.y_form == 1) { // Only adjust dry yeast
453 var amount = row.y_amount * factor; 842 var amount = row.y_amount * factor;
454 $("#yeastGrid").jqxGrid('setcellvalue', i, "y_amount", amount); 843 $("#yeastGrid").jqxGrid('setcellvalue', i, "y_amount", amount);
455 } 844 }
456 } 845 }
457 // TODO: adjust starter size 846
847 calcYeast();
458 }; 848 };
459 849
460 function adjustWaters(factor) { 850 function adjustWaters(factor) {
461 851
462 console.log("adjustWaters("+factor+")"); 852 console.log("adjustWaters("+factor+")");
1238 function calcFermentation() { 1628 function calcFermentation() {
1239 if (dataRecord.brew_fermenter_sg < 1.020) 1629 if (dataRecord.brew_fermenter_sg < 1.020)
1240 return; 1630 return;
1241 if ((dataRecord.primary_end_sg > 0.990) && (dataRecord.primary_end_sg < dataRecord.brew_fermenter_sg)) { 1631 if ((dataRecord.primary_end_sg > 0.990) && (dataRecord.primary_end_sg < dataRecord.brew_fermenter_sg)) {
1242 var primary_svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.primary_end_sg) / (dataRecord.brew_fermenter_sg - 1); 1632 var primary_svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.primary_end_sg) / (dataRecord.brew_fermenter_sg - 1);
1243 console.log("primary svg: "+primary_svg); 1633 //console.log("primary svg: "+primary_svg);
1244 $("#primary_svg").val(primary_svg); 1634 $("#primary_svg").val(primary_svg);
1245 if ((dataRecord.fg > 0.990) && (dataRecord.fg < dataRecord.brew_fermenter_sg)) { 1635 if ((dataRecord.fg > 0.990) && (dataRecord.fg < dataRecord.brew_fermenter_sg)) {
1246 var final_svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.fg) / (dataRecord.brew_fermenter_sg - 1); 1636 var final_svg = 100 * (dataRecord.brew_fermenter_sg - dataRecord.fg) / (dataRecord.brew_fermenter_sg - 1);
1247 $("#final_svg").val(final_svg); 1637 $("#final_svg").val(final_svg);
1248 var ABV = abvol(dataRecord.brew_fermenter_sg, dataRecord.fg); 1638 var ABV = abvol(dataRecord.brew_fermenter_sg, dataRecord.fg);
1439 console.log("calcInit()"); 1829 console.log("calcInit()");
1440 1830
1441 calcMashEfficiency(); 1831 calcMashEfficiency();
1442 calcEfficiencyBeforeBoil(); 1832 calcEfficiencyBeforeBoil();
1443 calcEfficiencyAfterBoil(); 1833 calcEfficiencyAfterBoil();
1834
1835 $("#starter_enable").on('checked', function (event) {
1836 dataRecord.starter_enable = 1;
1837 $("#propagator").show();
1838 $("#starter_type").jqxDropDownList( {disabled: false });
1839 $("#starter_try").jqxButton({ disabled: false });
1840 $("#starter_sg").jqxNumberInput({ spinButtons: true, readOnly: false, width: 110 });
1841 calcYeast();
1842 });
1843 $("#starter_enable").on('unchecked', function (event) {
1844 dataRecord.starter_enable = 0;
1845 $("#propagator").hide();
1846 $("#starter_type").jqxDropDownList( {disabled: true });
1847 $("#starter_try").jqxButton({ disabled: true });
1848 $("#starter_sg").jqxNumberInput({ spinButtons: false, readOnly: true, width: 90 });
1849 });
1850 $("#starter_try").click(function () {
1851 $("#prop1_volume").val(0);
1852 $("#prop2_volume").val(0);
1853 $("#prop3_volume").val(0);
1854 $("#prop4_volume").val(0);
1855 calcYeast();
1856 });
1857 $('#starter_type').on('change', function (event) {
1858 if (event.args) {
1859 var index = event.args.index;
1860 dataRecord.starter_type = index;
1861 calcYeast();
1862 }
1863 });
1864 $('#starter_sg').on('change', function (event) {
1865 if (event.args) {
1866 dataRecord.starter_sg = event.args.value;
1867 calcYeast();
1868 }
1869 });
1870 $('#prop1_type').on('change', function (event) {
1871 if (event.args) {
1872 var index = event.args.index;
1873 dataRecord.prop1_type = index;
1874 calcYeast();
1875 }
1876 });
1877 $('#prop1_volume').on('change', function (event) {
1878 if (event.args) {
1879 dataRecord.prop1_volume = event.args.value;
1880 calcYeast();
1881 }
1882 });
1883 $('#prop2_type').on('change', function (event) {
1884 if (event.args) {
1885 var index = event.args.index;
1886 dataRecord.prop2_type = index;
1887 calcYeast();
1888 }
1889 });
1890 $('#prop2_volume').on('change', function (event) {
1891 if (event.args) {
1892 dataRecord.prop2_volume = event.args.value;
1893 calcYeast();
1894 }
1895 });
1896 $('#prop3_type').on('change', function (event) {
1897 if (event.args) {
1898 var index = event.args.index;
1899 dataRecord.prop3_type = index;
1900 calcYeast();
1901 }
1902 });
1903 $('#prop3_volume').on('change', function (event) {
1904 if (event.args) {
1905 dataRecord.prop3_volume = event.args.value;
1906 calcYeast();
1907 }
1908 });
1909 $('#prop4_type').on('change', function (event) {
1910 if (event.args) {
1911 var index = event.args.index;
1912 dataRecord.prop4_type = index;
1913 calcYeast();
1914 }
1915 });
1916 $('#prop4_volume').on('change', function (event) {
1917 if (event.args) {
1918 dataRecord.prop4_volume = event.args.value;
1919 calcYeast();
1920 }
1921 });
1444 1922
1445 $("#calc_acid").on('checked', function (event) { 1923 $("#calc_acid").on('checked', function (event) {
1446 dataRecord.calc_acid = 1; 1924 dataRecord.calc_acid = 1;
1447 calcWater(); 1925 calcWater();
1448 }); 1926 });
1589 console.log("est_og change:"+event.args.value); 2067 console.log("est_og change:"+event.args.value);
1590 $('#est_og2').val(event.args.value); 2068 $('#est_og2').val(event.args.value);
1591 calcFermentablesFromOG(event.args.value); // Adjust fermentables amounts 2069 calcFermentablesFromOG(event.args.value); // Adjust fermentables amounts
1592 calcFermentables(); // Update the recipe details 2070 calcFermentables(); // Update the recipe details
1593 calcIBUs(); // and the IBU's. 2071 calcIBUs(); // and the IBU's.
2072 calcYeast();
1594 }); 2073 });
1595 $('#mash_ph').on('change', function (event) { 2074 $('#mash_ph').on('change', function (event) {
1596 dataRecord.mash_ph = parseFloat(event.args.value); 2075 dataRecord.mash_ph = parseFloat(event.args.value);
1597 calcWater(); 2076 calcWater();
1598 }); 2077 });
1666 2145
1667 $("#brew_fermenter_extrawater").on('change', function (event) { 2146 $("#brew_fermenter_extrawater").on('change', function (event) {
1668 dataRecord.brew_fermenter_extrawater = parseFloat(event.args.value); 2147 dataRecord.brew_fermenter_extrawater = parseFloat(event.args.value);
1669 calcFermentables(); 2148 calcFermentables();
1670 calcIBUs(); 2149 calcIBUs();
2150 calcYeast();
1671 }); 2151 });
1672 $("#brew_fermenter_tcloss").on('change', function (event) { 2152 $("#brew_fermenter_tcloss").on('change', function (event) {
1673 dataRecord.brew_fermenter_tcloss = parseFloat(event.args.value); 2153 dataRecord.brew_fermenter_tcloss = parseFloat(event.args.value);
1674 calcFermentables(); 2154 calcFermentables();
1675 calcIBUs(); 2155 calcIBUs();
2156 calcYeast();
1676 }); 2157 });
1677 2158
1678 $("#BLog").jqxButton({ disabled: (dataRecord.log_brew) ? false:true }); 2159 $("#BLog").jqxButton({ disabled: (dataRecord.log_brew) ? false:true });
1679 $("#FLog").jqxButton({ disabled: (dataRecord.log_fermentation) ? false:true }); 2160 $("#FLog").jqxButton({ disabled: (dataRecord.log_fermentation) ? false:true });
1680 }; 2161 };
1960 w2_ph: parseFloat($("#w2_ph").jqxNumberInput('decimal')), 2441 w2_ph: parseFloat($("#w2_ph").jqxNumberInput('decimal')),
1961 w2_cost: dataRecord.w2_cost, 2442 w2_cost: dataRecord.w2_cost,
1962 wa_acid_name: $("#wa_acid_name").val(), 2443 wa_acid_name: $("#wa_acid_name").val(),
1963 wa_acid_perc: parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')), 2444 wa_acid_perc: parseFloat($("#wa_acid_perc").jqxNumberInput('decimal')),
1964 wa_base_name: $("#wa_base_name").val(), 2445 wa_base_name: $("#wa_base_name").val(),
2446 starter_enable: dataRecord.starter_enable,
2447 starter_type: $("#starter_type").val(),
2448 starter_sg: parseFloat($("#starter_sg").jqxNumberInput('decimal')),
2449 prop1_type: $("#prop1_type").val(),
2450 prop1_volume: parseFloat($("#prop1_volume").jqxNumberInput('decimal')),
2451 prop2_type: $("#prop2_type").val(),
2452 prop2_volume: parseFloat($("#prop2_volume").jqxNumberInput('decimal')),
2453 prop3_type: $("#prop3_type").val(),
2454 prop3_volume: parseFloat($("#prop3_volume").jqxNumberInput('decimal')),
2455 prop4_type: $("#prop4_type").val(),
2456 prop4_volume: parseFloat($("#prop4_volume").jqxNumberInput('decimal')),
1965 fermentables: fermentablerow, 2457 fermentables: fermentablerow,
1966 hops: hoprow, 2458 hops: hoprow,
1967 miscs: miscrow, 2459 miscs: miscrow,
1968 yeasts: yeastrow, 2460 yeasts: yeastrow,
1969 mashs: mashrow 2461 mashs: mashrow
2151 { name: 'w2_ph', type: 'float' }, 2643 { name: 'w2_ph', type: 'float' },
2152 { name: 'w2_cost', type: 'float' }, 2644 { name: 'w2_cost', type: 'float' },
2153 { name: 'wa_acid_name', type: 'int' }, 2645 { name: 'wa_acid_name', type: 'int' },
2154 { name: 'wa_acid_perc', type: 'int' }, 2646 { name: 'wa_acid_perc', type: 'int' },
2155 { name: 'wa_base_name', type: 'int' }, 2647 { name: 'wa_base_name', type: 'int' },
2648 { name: 'starter_enable', type: 'int' },
2649 { name: 'starter_type', type: 'int' },
2650 { name: 'starter_sg', type: 'float' },
2651 { name: 'prop1_type', type: 'int' },
2652 { name: 'prop1_volume', type: 'float' },
2653 { name: 'prop2_type', type: 'int' },
2654 { name: 'prop2_volume', type: 'float' },
2655 { name: 'prop3_type', type: 'int' },
2656 { name: 'prop3_volume', type: 'float' },
2657 { name: 'prop4_type', type: 'int' },
2658 { name: 'prop4_volume', type: 'float' },
2156 { name: 'fermentables', type: 'array' }, 2659 { name: 'fermentables', type: 'array' },
2157 { name: 'hops', type: 'array' }, 2660 { name: 'hops', type: 'array' },
2158 { name: 'miscs', type: 'array' }, 2661 { name: 'miscs', type: 'array' },
2159 { name: 'yeasts', type: 'array' }, 2662 { name: 'yeasts', type: 'array' },
2160 { name: 'mashs', type: 'array' } 2663 { name: 'mashs', type: 'array' }
2341 $("#w2_ph").val(dataRecord.w2_ph); 2844 $("#w2_ph").val(dataRecord.w2_ph);
2342 $("#w2_cost").val(dataRecord.w2_cost); 2845 $("#w2_cost").val(dataRecord.w2_cost);
2343 $("#wa_acid_name").val(dataRecord.wa_acid_name); 2846 $("#wa_acid_name").val(dataRecord.wa_acid_name);
2344 $("#wa_acid_perc").val(dataRecord.wa_acid_perc); 2847 $("#wa_acid_perc").val(dataRecord.wa_acid_perc);
2345 $("#wa_base_name").val(dataRecord.wa_base_name); 2848 $("#wa_base_name").val(dataRecord.wa_base_name);
2849 $("#starter_enable").val(dataRecord.starter_enable);
2850 $("#starter_type").val(dataRecord.starter_type);
2851 $("#starter_sg").val(dataRecord.starter_sg);
2852 $("#prop1_type").val(dataRecord.prop1_type);
2853 $("#prop1_volume").val(dataRecord.prop1_volume);
2854 $("#prop2_type").val(dataRecord.prop2_type);
2855 $("#prop2_volume").val(dataRecord.prop2_volume);
2856 $("#prop3_type").val(dataRecord.prop3_type);
2857 $("#prop3_volume").val(dataRecord.prop3_volume);
2858 $("#prop4_type").val(dataRecord.prop4_type);
2859 $("#prop4_volume").val(dataRecord.prop4_volume);
2346 editFermentable(dataRecord); 2860 editFermentable(dataRecord);
2347 editHop(dataRecord); 2861 editHop(dataRecord);
2348 editMisc(dataRecord); 2862 editMisc(dataRecord);
2349 editYeast(dataRecord); 2863 editYeast(dataRecord);
2350 editMash(dataRecord); 2864 editMash(dataRecord);
3025 } 3539 }
3026 }; 3540 };
3027 var yeastAdapter = new $.jqx.dataAdapter(yeastSource); 3541 var yeastAdapter = new $.jqx.dataAdapter(yeastSource);
3028 $("#yeastGrid").jqxGrid({ 3542 $("#yeastGrid").jqxGrid({
3029 width: 1240, 3543 width: 1240,
3030 height: 400, 3544 height: 350,
3031 source: yeastAdapter, 3545 source: yeastAdapter,
3032 theme: theme, 3546 theme: theme,
3033 selectionmode: 'singlerow', 3547 selectionmode: 'singlerow',
3034 localization: getLocalization(), 3548 localization: getLocalization(),
3035 showtoolbar: true, 3549 showtoolbar: true,
3077 row["y_flocculation"] = datarecord.flocculation; 3591 row["y_flocculation"] = datarecord.flocculation;
3078 row["y_cells"] = datarecord.cells; 3592 row["y_cells"] = datarecord.cells;
3079 row["y_inventory"] = datarecord.inventory; 3593 row["y_inventory"] = datarecord.inventory;
3080 var commit = $("#yeastGrid").jqxGrid('addrow', null, row); 3594 var commit = $("#yeastGrid").jqxGrid('addrow', null, row);
3081 } 3595 }
3596 calcYeast();
3082 $("#yaddrowbutton").jqxDropDownList('clearSelection'); 3597 $("#yaddrowbutton").jqxDropDownList('clearSelection');
3083 }); 3598 });
3084 $("#yinstockbutton").jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) }); 3599 $("#yinstockbutton").jqxCheckBox({ theme: theme, height: 27, disabled: (dataRecord.stage > 3) });
3085 $("#yinstockbutton").on('change', function (event) { 3600 $("#yinstockbutton").on('change', function (event) {
3086 yeastinstock = event.args.checked; 3601 yeastinstock = event.args.checked;
3092 var selectedrowindex = $("#yeastGrid").jqxGrid('getselectedrowindex'); 3607 var selectedrowindex = $("#yeastGrid").jqxGrid('getselectedrowindex');
3093 var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount; 3608 var rowscount = $("#yeastGrid").jqxGrid('getdatainformation').rowscount;
3094 if (selectedrowindex >= 0 && selectedrowindex < rowscount) { 3609 if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
3095 var id = $("#yeastGrid").jqxGrid('getrowid', selectedrowindex); 3610 var id = $("#yeastGrid").jqxGrid('getrowid', selectedrowindex);
3096 var commit = $("#yeastGrid").jqxGrid('deleterow', id); 3611 var commit = $("#yeastGrid").jqxGrid('deleterow', id);
3612 calcYeast();
3097 } 3613 }
3098 }); 3614 });
3099 }, 3615 },
3100 ready: function() { 3616 ready: function() {
3101 calcFermentables(); 3617 calcFermentables();
3618 calcYeast();
3102 $('#jqxTabs').jqxTabs('next'); 3619 $('#jqxTabs').jqxTabs('next');
3103 }, 3620 },
3104 columns: [ 3621 columns: [
3105 { text: 'Gist', datafield: 'y_name' }, 3622 { text: 'Gist', datafield: 'y_name' },
3106 { text: 'Laboratorium', width: 150, datafield: 'y_laboratory' }, 3623 { text: 'Laboratorium', width: 150, datafield: 'y_laboratory' },
3970 // Tab 6, Yeasts 4487 // Tab 6, Yeasts
3971 $("#est_fg2").jqxTooltip({ content: 'Het verwachte eind SG. Dit wordt automatisch berekend.' }); 4488 $("#est_fg2").jqxTooltip({ content: 'Het verwachte eind SG. Dit wordt automatisch berekend.' });
3972 $("#est_fg2").jqxNumberInput( Show3dec ); 4489 $("#est_fg2").jqxNumberInput( Show3dec );
3973 $("#est_abv2").jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' }); 4490 $("#est_abv2").jqxTooltip({ content: 'Alcohol volume %. Dit wordt automatisch berekend.' });
3974 $("#est_abv2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true }); 4491 $("#est_abv2").jqxNumberInput({ inputMode: 'simple', theme: theme, width: 50, height: 23, decimalDigits: 1, readOnly: true });
4492 $("#yeast_cells").jqxNumberInput( Show1dec );
4493 $("#need_cells").jqxNumberInput( Show1dec );
4494 $("#plato_cells").jqxNumberInput( Show1dec );
3975 $("#popupYeast").jqxWindow({ 4495 $("#popupYeast").jqxWindow({
3976 width: 800, 4496 width: 800,
3977 height: 300, 4497 height: 300,
3978 position: { x: 230, y: 100 }, 4498 position: { x: 230, y: 100 },
3979 resizable: false, 4499 resizable: false,
3984 modalOpacity: 0.40 4504 modalOpacity: 0.40
3985 }); 4505 });
3986 $("#YeastReady").jqxButton({ template: "success", width: '90px', theme: theme }); 4506 $("#YeastReady").jqxButton({ template: "success", width: '90px', theme: theme });
3987 $("#YeastReady").click(function () { 4507 $("#YeastReady").click(function () {
3988 calcFermentables(); 4508 calcFermentables();
4509 calcYeast();
3989 $("#yeastGrid").jqxGrid('sortby', 'y_use', 'asc'); 4510 $("#yeastGrid").jqxGrid('sortby', 'y_use', 'asc');
3990 }); 4511 });
3991 $("#wy_name").jqxInput({ theme: theme, width: 320, height: 23 }); 4512 $("#wy_name").jqxInput({ theme: theme, width: 320, height: 23 });
3992 $("#wy_laboratory").jqxInput({ theme: theme, width: 320, height: 23 }); 4513 $("#wy_laboratory").jqxInput({ theme: theme, width: 320, height: 23 });
3993 $("#wy_product_id").jqxInput({ theme: theme, width: 320, height: 23 }); 4514 $("#wy_product_id").jqxInput({ theme: theme, width: 320, height: 23 });
4036 $("#wy_pmpt_amount").html("Gewicht gram:"); 4557 $("#wy_pmpt_amount").html("Gewicht gram:");
4037 } else { 4558 } else {
4038 $("#wy_pmpt_amount").html("Volume ml:"); 4559 $("#wy_pmpt_amount").html("Volume ml:");
4039 } 4560 }
4040 calcFermentables(); 4561 calcFermentables();
4562 calcYeast();
4041 } 4563 }
4042 }); 4564 });
4043 $("#wy_amount").jqxNumberInput( Spin1dec ); 4565 $("#wy_amount").jqxNumberInput( Spin1dec );
4044 $('#wy_amount').on('change', function (event) { 4566 $('#wy_amount').on('change', function (event) {
4045 console.log("amount changed: "+event.args.value); 4567 console.log("amount changed: "+event.args.value);
4048 var amount = parseFloat(event.args.value); 4570 var amount = parseFloat(event.args.value);
4049 else 4571 else
4050 var amount = parseFloat(event.args.value) / 1000; 4572 var amount = parseFloat(event.args.value) / 1000;
4051 rowdata.y_amount = amount; 4573 rowdata.y_amount = amount;
4052 calcFermentables(); 4574 calcFermentables();
4575 calcYeast();
4053 }); 4576 });
4054 $("#wy_use").jqxDropDownList({ 4577 $("#wy_use").jqxDropDownList({
4055 theme: theme, 4578 theme: theme,
4056 source: YeastUseAdapter, 4579 source: YeastUseAdapter,
4057 valueMember: 'id', 4580 valueMember: 'id',
4065 if (event.args) { 4588 if (event.args) {
4066 var index = event.args.index; 4589 var index = event.args.index;
4067 var rowdata = $("#yeastGrid").jqxGrid('getrowdata', yeastRow); 4590 var rowdata = $("#yeastGrid").jqxGrid('getrowdata', yeastRow);
4068 rowdata.y_use = index; 4591 rowdata.y_use = index;
4069 calcFermentables(); 4592 calcFermentables();
4070 } 4593 calcYeast();
4071 }); 4594 }
4595 });
4596 for (var i = 1; i < 5; i++) {
4597 $("#prop"+i+"_type").jqxDropDownList({
4598 theme: theme,
4599 source: StarterTypeAdapter,
4600 valueMember: 'id',
4601 displayMember: 'nl',
4602 width: 120,
4603 height: 23,
4604 autoDropDownHeight: true
4605 });
4606 $("#prop"+i+"_type").hide();
4607 $("#prop"+i+"_volume").jqxNumberInput( Spin3dec );
4608 $("#prop"+i+"_volume").hide();
4609 $("#prop"+i+"_irate").jqxNumberInput( Show1dec );
4610 $("#prop"+i+"_irate").hide();
4611 $("#prop"+i+"_ncells").jqxNumberInput( Show1dec );
4612 $("#prop"+i+"_ncells").hide();
4613 $("#prop"+i+"_tcells").jqxNumberInput( Show1dec );
4614 $("#prop"+i+"_tcells").hide();
4615 $("#prop"+i+"_growf").jqxNumberInput( Show2dec );
4616 $("#prop"+i+"_growf").hide();
4617 }
4618 $("#starter_enable").jqxCheckBox({ theme: theme, height: 23 });
4619 $("#starter_type").jqxDropDownList({
4620 theme: theme,
4621 source: StarterTypeAdapter,
4622 valueMember: 'id',
4623 displayMember: 'nl',
4624 width: 120,
4625 height: 23,
4626 autoDropDownHeight: true
4627 });
4628 $("#starter_sg").jqxNumberInput( SGopts );
4629 $("#starter_try").jqxButton({ template: "primary", width: '100px', height: 23, theme: theme });
4072 4630
4073 // Tab 7, Mashing 4631 // Tab 7, Mashing
4074 $("#mash_name").jqxTooltip({ content: 'De omschrijving van dit maisch profiel.' }); 4632 $("#mash_name").jqxTooltip({ content: 'De omschrijving van dit maisch profiel.' });
4075 $("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 }); 4633 $("#mash_name").jqxInput({ theme: theme, width: 320, height: 23 });
4076 $("#mash_select").jqxDropDownList({ 4634 $("#mash_select").jqxDropDownList({

mercurial