src/EditProductTab6.cpp

changeset 198
904591820c3d
parent 197
6a5e5b3d0fcd
child 199
59b0bdbb2f9f
equal deleted inserted replaced
197:6a5e5b3d0fcd 198:904591820c3d
137 void EditProduct::initYeast() 137 void EditProduct::initYeast()
138 { 138 {
139 ui->est_og4Edit->setValue(product->est_og); 139 ui->est_og4Edit->setValue(product->est_og);
140 ui->est_fg3Edit->setValue(product->est_fg); 140 ui->est_fg3Edit->setValue(product->est_fg);
141 ui->est_abv2Edit->setValue(product->est_abv); 141 ui->est_abv2Edit->setValue(product->est_abv);
142 ui->productionEdit->setText(product->yeast_prod_date.toString("dd MMM yyyy")); 142 ui->productionEdit->setDate(product->yeast_prod_date);
143 ui->conditionShow->setValue(product->starter_viability); 143 ui->conditionShow->setValue(product->starter_viability);
144 ui->startersgEdit->setValue(product->starter_sg); 144 ui->startersgEdit->setValue(product->starter_sg);
145 ui->pitchrateEdit->setValue(product->yeast_pitchrate); 145 ui->pitchrateEdit->setValue(product->yeast_pitchrate);
146 146
147 ui->yeastsTable->setEditTriggers(QAbstractItemView::NoEditTriggers); 147 ui->yeastsTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
184 // Also in calcFermentables() 184 // Also in calcFermentables()
185 //$('#yeast_cells').val(initcells); 185 //$('#yeast_cells').val(initcells);
186 186
187 if (product->yeasts.size() == 0) 187 if (product->yeasts.size() == 0)
188 return; // No yeast in product. 188 return; // No yeast in product.
189
190 calcViability();
189 191
190 for (int i = 0; i < product->yeasts.size(); i++) { 192 for (int i = 0; i < product->yeasts.size(); i++) {
191 if (product->yeasts.at(i).y_use == YEAST_USE_PRIMARY) { // Primary 193 if (product->yeasts.at(i).y_use == YEAST_USE_PRIMARY) { // Primary
192 if (product->yeasts.at(i).y_form == YEAST_FORMS_DRY) { 194 if (product->yeasts.at(i).y_form == YEAST_FORMS_DRY) {
193 /* 195 /*
234 } 236 }
235 is_changed(); 237 is_changed();
236 ui->pitchrateEdit->setValue(product->yeast_pitchrate); 238 ui->pitchrateEdit->setValue(product->yeast_pitchrate);
237 } 239 }
238 240
239 initcells = (product->yeasts.at(i).y_cells / 1000000) * product->yeasts.at(i).y_amount * 0.97; // cells / ml. 241 initcells = (product->yeasts.at(i).y_cells / 1000000) * product->yeasts.at(i).y_amount * (product->starter_viability / 100.0);
240 if (product->yeasts.at(i).y_form == YEAST_FORMS_LIQUID) 242 if (product->yeasts.at(i).y_form == YEAST_FORMS_LIQUID)
241 initcells = (product->yeasts.at(i).y_cells / 1000000000) * product->yeasts.at(i).y_amount * 0.97; // 97% viability assumed. 243 initcells = (product->yeasts.at(i).y_cells / 1000000000) * product->yeasts.at(i).y_amount * (product->starter_viability / 100.0);
242 244
243 needed = round(product->yeast_pitchrate * volume * plato * 10.0) / 10.0; 245 needed = round(product->yeast_pitchrate * volume * plato * 10.0) / 10.0;
244 if (needed > initcells) { 246 if (needed > initcells) {
245 maybe_starter = true; 247 maybe_starter = true;
246 } 248 }
611 } 613 }
612 } 614 }
613 } 615 }
614 616
615 617
616 void EditProduct::yeast_prod_date_clicked() 618 void EditProduct::calcViability()
617 { 619 {
620 double vpm = 1.00;
621 double max = 100;
622
623 for (int i = 0; i < product->yeasts.size(); i++) {
624 if (product->yeasts.at(i).y_use == 0) {
625 if (product->yeasts.at(i).y_form == 0) { // Liquid
626 vpm = 0.80;
627 max = 97;
628 if (product->yeasts.at(i).y_laboratory == "White Labs") { // PurePitch
629 vpm = 0.95;
630 max = 100;
631 }
632 } else if (product->yeasts.at(i).y_form == 1) { // dry
633 vpm = 0.998;
634 max = 100;
635 } else if (product->yeasts.at(i).y_form == 6) { // dried kveik
636 vpm = 0.92;
637 max = 100;
638 } else { // Slant, Culture, Frozen, Bottle
639 vpm = 0.99;
640 max = 97;
641 }
642 }
643 }
644 qDebug() << "calcViability vpm:" << vpm << "max:" << max;
645
646 double base = max;
647
648 /*
649 * Calculate time days before today. If the date is cleared,
650 * the result is 0 days. Dates in the future are ignored.
651 */
652 int timeDiff = product->yeast_prod_date.daysTo(QDate::currentDate());
653 if (timeDiff < 0)
654 timeDiff == 0;
655
656 double degrade = 1 - ((1 - vpm) / 30.41); // viability degradation per day.
657 for (int i = 0; i < timeDiff; i++) {
658 base = base * degrade;
659 }
660 if (base > max)
661 base = max;
662 base = round(base);
663 product->starter_viability = base;
664 ui->conditionShow->setValue(product->starter_viability);
665 qDebug() << "age" << timeDiff << "degrade" << degrade << "base" << base ;
666 }
667
668
669 void EditProduct::yeast_prod_date_changed(QDate val)
670 {
671 product->yeast_prod_date = ui->productionEdit->nullDate();
672 qDebug() << "yeast_prod_date_changed" << val << product->yeast_prod_date;
673 calcViability();
674 calcYeast();
675 }
676
677
678 void EditProduct::yeast_prod_date_clear()
679 {
680 product->yeast_prod_date = QDate();
681 ui->productionEdit->setDate(QDate());
682 }
683
684
685 void EditProduct::yeast_prod_date_today()
686 {
687 product->yeast_prod_date = QDate::currentDate();
688 ui->productionEdit->setDate(QDate::currentDate());
618 } 689 }
619 690
620 691
621 void EditProduct::yeast_method_changed(int val) 692 void EditProduct::yeast_method_changed(int val)
622 { 693 {
699 qDebug() << "accept"; 770 qDebug() << "accept";
700 calcYeast(); 771 calcYeast();
701 is_changed(); 772 is_changed();
702 } 773 }
703 774
704 disconnect(typeEdit, nullptr, nullptr, nullptr);
705 disconnect(volEdit, nullptr, nullptr, nullptr);
706 disconnect(buttonBox, nullptr, nullptr, nullptr); 775 disconnect(buttonBox, nullptr, nullptr, nullptr);
707 } 776 }
708 777
709 778
710 void EditProduct::addYeastRow_clicked() 779 void EditProduct::addYeastRow_clicked()

mercurial