src/EditRecipeTab5.cpp

changeset 142
1caa15a0eefc
parent 141
eea8a9e7e1f6
child 143
8414844c9f8b
--- a/src/EditRecipeTab5.cpp	Mon Apr 18 10:55:33 2022 +0200
+++ b/src/EditRecipeTab5.cpp	Mon Apr 18 20:00:49 2022 +0200
@@ -70,7 +70,7 @@
 	ui->yeastsTable->setItem(i, 1, new QTableWidgetItem(recipe->yeasts.at(i).y_laboratory));
 	ui->yeastsTable->setItem(i, 2, new QTableWidgetItem(recipe->yeasts.at(i).y_product_id));
 
-	item = new QTableWidgetItem(y_types[recipe->yeasts.at(i).y_type]);
+	item = new QTableWidgetItem(y_forms[recipe->yeasts.at(i).y_form]);
         item->setTextAlignment(Qt::AlignCenter|Qt::AlignVCenter);
         ui->yeastsTable->setItem(i, 3, item);
 
@@ -94,9 +94,9 @@
         item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
         ui->yeastsTable->setItem(i, 8, item);
 
-	if (recipe->yeasts.at(i).y_type == 0)
-            item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0'));
-	else if (recipe->yeasts.at(i).y_type == 1)
+	if (recipe->yeasts.at(i).y_form == 0)
+            item = new QTableWidgetItem(QString("%1 pack").arg(recipe->yeasts.at(i).y_amount, 1, 'f', 0, '0'));
+	else if (recipe->yeasts.at(i).y_form == 1)
 	    item = new QTableWidgetItem(QString("%1 gr").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0'));
 	else
 	    item = new QTableWidgetItem(QString("%1 ml").arg(recipe->yeasts.at(i).y_amount * 1000.0, 3, 'f', 2, '0'));
@@ -130,6 +130,90 @@
 }
 
 
+/*
+ * The results are not stored line in EditProduct. This is just a hint.
+ */
+void EditRecipe::calcYeast()
+{
+    double sg = recipe->est_og;
+    double plato = Utils::sg_to_plato(sg);
+    double volume = recipe->batch_size * 0.9;	// Volume min trub chiller loss.
+    bool maybe_starter = false;
+    double pitchrate = 0.75;
+    double initcells = 0;
+
+    qDebug() << "calcYeast()";
+    ui->yeastProcedure->setCurrentIndex(0);
+
+    if (recipe->yeasts.size() == 0)
+	return;		// No yeast in recipe.
+
+    for (int i = 0; i < recipe->yeasts.size(); i++) {
+	if (recipe->yeasts.at(i).y_use == 0) {		// Primary
+	    if (recipe->yeasts.at(i).y_form == 1) {
+		/*
+		 * Dry yeast, build the formule with the yeast parameters.
+		 * Based on https://www.lallemandbrewing.com/en/canada/brewers-corner/brewing-tools/pitching-rate-calculator/
+		 */
+		ui->yeastProcedure->setCurrentIndex(2);
+		ui->lo_gr_hlEdit->setValue(recipe->yeasts.at(i).y_gr_hl_lo);
+		ui->hi_gr_hlEdit->setValue(recipe->yeasts.at(i).y_gr_hl_hi);
+		ui->lo_sgEdit->setValue(recipe->yeasts.at(i).y_sg_lo);
+		ui->hi_sgEdit->setValue(recipe->yeasts.at(i).y_sg_hi);
+		double og = recipe->yeasts.at(i).y_sg_lo;
+		double f1 = recipe->yeasts.at(i).y_gr_hl_lo / 100.0;
+		double f2 = round(f1 / 5 * 1000000.0) / 1000000.0;
+     		double multiplier = (sg <= og) ? f1 : (f1 + f2 * (sg - og) / 0.008);
+		qDebug() << "  sg:" << sg << "og:" << og << "f1:" << f1 << "f2:" << f2 << "multiplier:" << multiplier;
+     		double yeast_grams = round(volume * multiplier * 100.0) / 100.0; // * (100 / dataRecord.starter_viability), 2);
+     		double yeast_gr_hl = round((yeast_grams / (volume * 0.01)) * 100.0) / 100.0;
+		ui->need_grEdit->setValue(yeast_grams);
+		ui->pitch_grEdit->setValue(yeast_gr_hl);
+     		qDebug() << "  need" << yeast_grams << "grams, gr/hl:" << yeast_gr_hl;
+		return;
+	    } else {
+		/*
+		 * Liquid, slant, culture etc.
+		 * pitchrate see https://www.brewersfriend.com/yeast-pitch-rate-and-starter-calculator/
+		 * and http://braukaiser.com/blog/blog/2012/11/03/estimating-yeast-growth/
+		 */
+		ui->yeastProcedure->setCurrentIndex(1);
+		if (recipe->yeasts.at(i).y_type == 0) {		// Lager yeast
+		    pitchrate = 1.5;
+		    if (sg > 1.060)
+			pitchrate = 2.0;
+		} else if (recipe->yeasts.at(i).y_type == 6) {	// Real Kveik
+		    pitchrate = 0.075;
+		} else {
+		    pitchrate = 0.75;
+		    if (sg > 1.060)
+			pitchrate = 1.0;
+		}
+		if (recipe->yeasts.at(i).y_form == 0)
+		    initcells = (recipe->yeasts.at(i).y_cells / 1000000000) * recipe->yeasts.at(i).y_amount * 0.97;	// 97% viability assumed.
+		else
+		    initcells = (recipe->yeasts.at(i).y_cells / 1000000) * recipe->yeasts.at(i).y_amount * 0.97;
+
+		double needed = round(pitchrate * volume * plato * 10.0) / 10.0;
+		double starter = 0;
+		if (needed > initcells) {
+		    maybe_starter = true;
+		    starter = round(needed / 2.0) / 100.0;	// A very rough starter size estimate.
+		}
+
+		ui->pitchrateEdit->setValue(pitchrate);
+		ui->initcellsEdit->setValue(initcells);
+		ui->targetcellsEdit->setValue(needed);
+		ui->starterEdit->setValue(starter);
+
+		qDebug() << "  pitchrate:" << pitchrate << "needed:" << needed << "initcells:" << initcells << "starter" << maybe_starter << "size" << starter;
+	    }
+	    break;
+	}
+    }
+}
+
+
 void EditRecipe::addYeastRow_clicked()
 {
 

mercurial