Implemented pre and after boil volume and sg settings included all calculations.

Sun, 15 May 2022 20:57:03 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 15 May 2022 20:57:03 +0200
changeset 209
19c50b1f58d3
parent 208
615afedbcd25
child 210
b45bd6da5220

Implemented pre and after boil volume and sg settings included all calculations.

src/EditProduct.cpp file | annotate | diff | comparison | revisions
src/EditProduct.h file | annotate | diff | comparison | revisions
src/EditProductTab9.cpp file | annotate | diff | comparison | revisions
ui/EditProduct.ui file | annotate | diff | comparison | revisions
--- a/src/EditProduct.cpp	Sun May 15 11:27:06 2022 +0200
+++ b/src/EditProduct.cpp	Sun May 15 20:57:03 2022 +0200
@@ -940,11 +940,13 @@
     ui->brew_preboilvolEdit->setValue(product->brew_preboil_volume);
     ui->brew_preboilvolShow->setValue(product->boil_size * 1.04);
     ui->brew_preboileffShow->setValue(product->brew_preboil_efficiency);
+    calcEfficiencyBeforeBoil();
     ui->brew_aboilphEdit->setValue(product->brew_aboil_ph);
     ui->brew_aboilsgEdit->setValue(product->brew_aboil_sg);
     ui->brew_aboilvolEdit->setValue(product->brew_aboil_volume);
     ui->brew_aboilvolShow->setValue(product->batch_size * 1.04);
     ui->brew_aboileffShow->setValue(product->brew_aboil_efficiency);
+    calcEfficiencyAfterBoil();
     ui->brew_whirlpool9Edit->setValue(product->brew_whirlpool9);
     ui->brew_whirlpool7Edit->setValue(product->brew_whirlpool7);
     ui->brew_whirlpool6Edit->setValue(product->brew_whirlpool6);
@@ -1087,7 +1089,11 @@
     connect(ui->brew_mashsgEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_mashsg_changed);
     connect(ui->brew_spargephEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_spargeph_changed);
     connect(ui->brew_preboilphEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_preboilph_changed);
+    connect(ui->brew_preboilsgEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_preboilsg_changed);
+    connect(ui->brew_preboilvolEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_preboilvol_changed);
     connect(ui->brew_aboilphEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_aboilph_changed);
+    connect(ui->brew_aboilsgEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_aboilsg_changed);
+    connect(ui->brew_aboilvolEdit, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &EditProduct::brew_aboilvol_changed);
 
     setStage();
 
--- a/src/EditProduct.h	Sun May 15 11:27:06 2022 +0200
+++ b/src/EditProduct.h	Sun May 15 20:57:03 2022 +0200
@@ -149,7 +149,11 @@
     void brew_mashsg_changed(double val);
     void brew_spargeph_changed(double val);
     void brew_preboilph_changed(double val);
+    void brew_preboilsg_changed(double val);
+    void brew_preboilvol_changed(double val);
     void brew_aboilph_changed(double val);
+    void brew_aboilsg_changed(double val);
+    void brew_aboilvol_changed(double val);
 
     /* Modified progress bars */
     void ferment_perc_mash_valueChanged(int value);
@@ -222,6 +226,8 @@
     void calcMash();
     void adjustWaters(double factor);
     void updateBrewday();
+    void calcEfficiencyBeforeBoil();
+    void calcEfficiencyAfterBoil();
 };
 
 #endif
--- a/src/EditProductTab9.cpp	Sun May 15 11:27:06 2022 +0200
+++ b/src/EditProductTab9.cpp	Sun May 15 20:57:03 2022 +0200
@@ -133,6 +133,58 @@
 }
 
 
+void EditProduct::calcEfficiencyBeforeBoil()
+{
+    double m = 0;
+    double tot;
+    double result = 0;
+
+    if (product->fermentables.size() == 0)
+	return;	// no fermentables loaded yet
+    for (int i = 0; i < product->fermentables.size(); i++) {
+   	if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
+	    m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
+	}
+    }
+    tot = Utils::sg_to_plato(product->brew_preboil_sg) * (product->brew_preboil_volume / 1.04) * product->brew_preboil_sg * 10 / 1000;
+
+    if (m > 0)
+	result = round((tot / m * 100) * 10.0) / 10.0;
+
+    if (result < 0)
+	result = 0;
+    ui->brew_preboileffShow->setValue(result);
+}
+
+
+void EditProduct::brew_preboilsg_changed(double val)
+{
+    if (product->brew_preboil_sg == 0) {
+	product->brew_preboil_sg = product->preboil_sg;
+	const QSignalBlocker blocker1(ui->brew_preboilsgEdit);
+        ui->brew_preboilsgEdit->setValue(product->preboil_sg);
+    } else {
+    	product->brew_preboil_sg = val;
+    }
+    is_changed();
+    calcEfficiencyBeforeBoil();
+}
+
+
+void EditProduct::brew_preboilvol_changed(double val)
+{
+    if (product->brew_preboil_volume == 0) {
+	product->brew_preboil_volume = product->boil_size * 1.04;
+	const QSignalBlocker blocker1(ui->brew_preboilvolEdit);
+        ui->brew_preboilvolEdit->setValue(product->boil_size * 1.04);
+    } else {
+    	product->brew_preboil_volume = val;
+    }
+    is_changed();
+    calcEfficiencyBeforeBoil();
+}
+
+
 void EditProduct::brew_aboilph_changed(double val)
 {
     if (product->brew_aboil_ph == 0) {
@@ -146,3 +198,57 @@
 }
 
 
+void EditProduct::calcEfficiencyAfterBoil()
+{
+    double m = 0;	// Sugars added at mash
+    double b = 0;	// Sugars added at boil
+    double result = 0;
+
+    if (product->fermentables.size() == 0)
+        return; // no fermentables loaded yet
+    for (int i = 0; i < product->fermentables.size(); i++) {
+	if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_MASH) {
+	    m += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
+	} else if (product->fermentables.at(i).f_added == FERMENTABLE_ADDED_BOIL) {
+	    b += product->fermentables.at(i).f_amount * (product->fermentables.at(i).f_yield / 100) * (1 - product->fermentables.at(i).f_moisture / 100);
+	}
+    }
+    double tot = Utils::sg_to_plato(product->brew_aboil_sg) * (product->brew_aboil_volume / 1.04) * product->brew_aboil_sg * 10 / 1000;
+    tot -= b;	// total sugars in wort  minus added sugars.
+
+    if (m > 0)
+	result = round((tot / m * 100) * 10.0) / 10.0;
+    product->brew_aboil_efficiency = result;
+    ui->brew_aboileffShow->setValue(result);
+    calcFermentables();	// This will also recalculate all volumes.
+}
+
+
+void EditProduct::brew_aboilsg_changed(double val)
+{
+    if (product->brew_aboil_sg == 0) {
+        product->brew_aboil_sg = product->est_og3;
+        const QSignalBlocker blocker1(ui->brew_aboilsgEdit);
+        ui->brew_aboilsgEdit->setValue(product->est_og3);
+    } else {
+        product->brew_aboil_sg = val;
+    }
+    is_changed();
+    calcEfficiencyAfterBoil();
+}
+
+
+void EditProduct::brew_aboilvol_changed(double val)
+{
+    if (product->brew_aboil_volume == 0) {
+        product->brew_aboil_volume = product->batch_size * 1.04;
+        const QSignalBlocker blocker1(ui->brew_aboilvolEdit);
+        ui->brew_aboilvolEdit->setValue(product->batch_size * 1.04);
+    } else {
+        product->brew_aboil_volume = val;
+    }
+    is_changed();
+    calcEfficiencyAfterBoil();
+}
+
+
--- a/ui/EditProduct.ui	Sun May 15 11:27:06 2022 +0200
+++ b/ui/EditProduct.ui	Sun May 15 20:57:03 2022 +0200
@@ -6751,7 +6751,7 @@
           <double>100000.000000000000000</double>
          </property>
          <property name="singleStep">
-          <double>1.000000000000000</double>
+          <double>0.100000000000000</double>
          </property>
         </widget>
         <widget class="QDoubleSpinBox" name="brew_preboilvolShow">
@@ -7651,7 +7651,7 @@
           <double>100000.000000000000000</double>
          </property>
          <property name="singleStep">
-          <double>1.000000000000000</double>
+          <double>0.100000000000000</double>
          </property>
         </widget>
         <widget class="QLabel" name="brew_aboilphLabel">

mercurial