# HG changeset patch # User Michiel Broek # Date 1673538994 -3600 # Node ID deea5047be325c24a344e0f918f78749d4eb8d76 # Parent 2dfead81c72f9f5f61cba941775dfd04d901f530 Fixed dangling old starter data. Added conditional yeast debug logging. diff -r 2dfead81c72f -r deea5047be32 src/EditProductTab6.cpp --- a/src/EditProductTab6.cpp Thu Jan 12 14:34:14 2023 +0100 +++ b/src/EditProductTab6.cpp Thu Jan 12 16:56:34 2023 +0100 @@ -193,6 +193,7 @@ bool maybe_starter = false; qDebug() << "calcYeast()"; + qDebug() << " " << product->prop_volume[0] << product->prop_volume[1] << product->prop_volume[2] << product->prop_volume[3]; ui->yeastProcedure->setCurrentIndex(0); if (sg <= 1.0001 && product->fg > 1.000) @@ -239,7 +240,9 @@ ui->pitch_grShow->setValue(pitch_gr_hl); ui->pitch_grShow->setStyleSheet((pitch_gr_hl < yeast_gr_hl) ? "background-color: red":""); +#ifdef DEBUG_YEAST qDebug() << " need" << yeast_grams << "grams, gr/hl:" << yeast_gr_hl << "pitch:" << pitch_gr_hl; +#endif return; } else { /* @@ -277,20 +280,35 @@ maybe_starter = true; } +#ifdef DEBUG_YEAST qDebug() << " pitchrate:" << product->yeast_pitchrate << "needed:" << needed << "initcells:" << initcells << "starter" << maybe_starter; +#endif } break; } } if (maybe_starter != product->starter_enable) { + if (product->starter_enable && !maybe_starter) { +#ifdef DEBUG_YEAST + qDebug() << " Clear obsolete starter"; +#endif + for (int i = 0; i < 4; i++) { + product->prop_volume[i] = 0; + product->prop_type[i] = 0; + } + } product->starter_enable = maybe_starter; +#ifdef DEBUG_YEAST qDebug() << " Set starter enable" << maybe_starter; +#endif is_changed(); } if (product->starter_enable) { +#ifdef DEBUG_YEAST qDebug() << " Starter calculate.."; +#endif const QStringList labels({tr("Method"), tr("Volume"), tr("Inj. factor"), tr("New cells"), tr("Total cells"), tr("Grow factor"), "" }); ui->starterTable->show(); @@ -353,8 +371,10 @@ res.ncells = ncells; res.totcells = totcells; res.growf = round((ncells / start) * 100.0) / 100.0; +#ifdef DEBUG_YEAST qDebug() << " calcStep(" << svol << "," << stype << "," << start << ") irate" << irate << "ncells" << res.ncells << "totcells" << res.totcells << "growf" << res.growf; +#endif return res; } @@ -387,7 +407,9 @@ /* * Auto calculate the starter. */ +#ifdef DEBUG_YEAST qDebug() << " calcSteps() auto"; +#endif if (start > needed) return; @@ -455,6 +477,9 @@ product->prop_type[step -1] = product->starter_type; product->prop_volume[step -1] = result.svol / 1000.0; +#ifdef DEBUG_YEAST + qDebug() << " step" << step << "type" << product->prop_type[step -1] << "vol" << product->prop_volume[step -1]; +#endif tcells = result.totcells; if (result.totcells > needed) // Hit the target @@ -465,7 +490,9 @@ /* * Recalculate the starter. */ +#ifdef DEBUG_YEAST qDebug() << " calcSteps() recalculate"; +#endif for (step = 0; step < 4; step++) { if (product->prop_volume[step] > 0) { @@ -524,6 +551,9 @@ product->prop_volume[step + 1] = product->prop_volume[step]; product->prop_type[step + 1] = product->prop_type[step]; } +#ifdef DEBUG_YEAST + qDebug() << " step" << step << "type" << product->prop_type[step] << "vol" << product->prop_volume[step]; +#endif } } } @@ -556,7 +586,9 @@ } } } +#ifdef DEBUG_YEAST qDebug() << "calcViability vpm:" << vpm << "max:" << max; +#endif double base = max; @@ -577,14 +609,15 @@ base = round(base); product->starter_viability = base; ui->conditionShow->setValue(product->starter_viability); +#ifdef DEBUG_YEAST qDebug() << "age" << timeDiff << "degrade" << degrade << "base" << base ; +#endif } void EditProduct::yeast_prod_date_changed(QDate val) { product->yeast_prod_date = ui->productionEdit->nullDate(); - qDebug() << "yeast_prod_date_changed" << val << product->yeast_prod_date; calcViability(); calcYeast(); is_changed(); @@ -607,7 +640,9 @@ void EditProduct::yeast_method_changed(int val) { +#ifdef DEBUG_YEAST qDebug() << "yeast_method_changed" << val; +#endif product->starter_type = val; calcYeast(); is_changed(); @@ -616,7 +651,9 @@ void EditProduct::yeast_starter_sg_changed(double val) { +#ifdef DEBUG_YEAST qDebug() << "yeast_starter_sg_changed" << val; +#endif product->starter_sg = val; calcYeast(); is_changed(); @@ -632,7 +669,9 @@ { QToolButton *pb = qobject_cast(QObject::sender()); int row = pb->objectName().toInt(); +#ifdef DEBUG_YEAST qDebug() << "yeast_starter_edit_clicked" << row; +#endif QDialog* dialog = new QDialog(this); dialog->resize(338, 140); @@ -678,12 +717,9 @@ dialog->setModal(true); dialog->exec(); - if (dialog->result() == QDialog::Rejected) { - qDebug() << "reject"; - } else { + if (dialog->result() != QDialog::Rejected) { product->prop_type[row] = typeEdit->currentIndex(); product->prop_volume[row] = volEdit->value(); - qDebug() << "accept"; calcYeast(); is_changed(); } @@ -696,7 +732,9 @@ { Yeasts newy; +#ifdef DEBUG_YEAST qDebug() << "Add yeast row"; +#endif for (int i = 0; i < product->yeasts.size(); i++) { if (product->yeasts.at(i).amount == 0) @@ -742,7 +780,9 @@ QPushButton *pb = qobject_cast(QObject::sender()); int row = pb->objectName().toInt(); +#ifdef DEBUG_YEAST qDebug() << "Delete yeast row" << row << product->yeasts.size(); +#endif int rc = QMessageBox::warning(this, tr("Delete yeast"), tr("Delete %1").arg(product->yeasts.at(row).name), QMessageBox::Yes | QMessageBox::No, QMessageBox::No); @@ -750,6 +790,18 @@ return; product->yeasts.removeAt(row); + bool primary = false; + for (int i = 0; i < product->yeasts.size(); i++) { + if (product->yeasts.at(i).use == YEAST_USE_PRIMARY) + primary = true; + } + if (! primary) { +#ifdef DEBUG_YEAST + qDebug() << " Clear starter (if any)"; +#endif + for (int i = 0; i < 4; i++) + product->prop_volume[i] = 0; + } is_changed(); emit refreshAll(); } @@ -759,7 +811,9 @@ { QTableWidgetItem *item; +#ifdef DEBUG_YEAST qDebug() << "yeast_amount_changed()" << product->yeasts_row << val; +#endif if (product->yeasts.at(product->yeasts_row).form == YEAST_FORMS_LIQUID) { product->yeasts[product->yeasts_row].amount = val; @@ -791,7 +845,9 @@ if (val < 1) return; +#ifdef DEBUG_YEAST qDebug() << "yeast_select_changed()" << product->yeasts_row << val << instock; +#endif /* * Search the yeast pointed by the index and instock flag. @@ -808,35 +864,37 @@ for (int i = 0; i < (val - 1); i++) { query.next(); } - qDebug() << "found" << query.value(0).toString() << query.value(2).toString(); +#ifdef DEBUG_YEAST + qDebug() << "found" << query.value("name").toString() << query.value("product_id").toString(); +#endif /* * Replace the yeast record contents */ - product->yeasts[product->yeasts_row].name = query.value(0).toString(); - product->yeasts[product->yeasts_row].laboratory = query.value(1).toString(); - product->yeasts[product->yeasts_row].product_id = query.value(2).toString(); - product->yeasts[product->yeasts_row].type = query.value(3).toInt(); - product->yeasts[product->yeasts_row].form = query.value(4).toInt(); - product->yeasts[product->yeasts_row].min_temperature = query.value(5).toDouble(); - product->yeasts[product->yeasts_row].max_temperature = query.value(6).toDouble(); - product->yeasts[product->yeasts_row].flocculation = query.value(7).toInt(); - product->yeasts[product->yeasts_row].attenuation = query.value(8).toDouble(); - product->yeasts[product->yeasts_row].cells = query.value(9).toDouble(); - product->yeasts[product->yeasts_row].tolerance = query.value(10).toDouble(); - product->yeasts[product->yeasts_row].sta1 = query.value(11).toInt() ? true:false; - product->yeasts[product->yeasts_row].bacteria = query.value(12).toInt() ? true:false; - product->yeasts[product->yeasts_row].harvest_top = query.value(13).toInt() ? true:false; - product->yeasts[product->yeasts_row].harvest_time = query.value(14).toInt(); - product->yeasts[product->yeasts_row].pitch_temperature = query.value(15).toDouble(); - product->yeasts[product->yeasts_row].pofpos = query.value(16).toInt() ? true:false; - product->yeasts[product->yeasts_row].zymocide = query.value(17).toInt(); - product->yeasts[product->yeasts_row].gr_hl_lo = query.value(18).toInt(); - product->yeasts[product->yeasts_row].sg_lo = query.value(19).toDouble(); - product->yeasts[product->yeasts_row].gr_hl_hi = query.value(20).toInt(); - product->yeasts[product->yeasts_row].sg_hi = query.value(21).toDouble(); - product->yeasts[product->yeasts_row].cost = query.value(22).toDouble(); - product->yeasts[product->yeasts_row].inventory = query.value(23).toDouble(); + product->yeasts[product->yeasts_row].name = query.value("name").toString(); + product->yeasts[product->yeasts_row].laboratory = query.value("laboratory").toString(); + product->yeasts[product->yeasts_row].product_id = query.value("product_id").toString(); + product->yeasts[product->yeasts_row].type = query.value("type").toInt(); + product->yeasts[product->yeasts_row].form = query.value("form").toInt(); + product->yeasts[product->yeasts_row].min_temperature = query.value("min_temperature").toDouble(); + product->yeasts[product->yeasts_row].max_temperature = query.value("max_temperature").toDouble(); + product->yeasts[product->yeasts_row].flocculation = query.value("flocculation").toInt(); + product->yeasts[product->yeasts_row].attenuation = query.value("attenuation").toDouble(); + product->yeasts[product->yeasts_row].cells = query.value("cells").toDouble(); + product->yeasts[product->yeasts_row].tolerance = query.value("tolerance").toDouble(); + product->yeasts[product->yeasts_row].sta1 = query.value("sta1").toInt() ? true:false; + product->yeasts[product->yeasts_row].bacteria = query.value("bacteria").toInt() ? true:false; + product->yeasts[product->yeasts_row].harvest_top = query.value("harvest_top").toInt() ? true:false; + product->yeasts[product->yeasts_row].harvest_time = query.value("harvest_time").toInt(); + product->yeasts[product->yeasts_row].pitch_temperature = query.value("pitch_temperature").toDouble(); + product->yeasts[product->yeasts_row].pofpos = query.value("pofpos").toInt() ? true:false; + product->yeasts[product->yeasts_row].zymocide = query.value("zymocide").toInt(); + product->yeasts[product->yeasts_row].gr_hl_lo = query.value("gr_hl_lo").toInt(); + product->yeasts[product->yeasts_row].sg_lo = query.value("sg_lo").toDouble(); + product->yeasts[product->yeasts_row].gr_hl_hi = query.value("gr_hl_hi").toInt(); + product->yeasts[product->yeasts_row].sg_hi = query.value("sg_hi").toDouble(); + product->yeasts[product->yeasts_row].cost = query.value("cost").toDouble(); + product->yeasts[product->yeasts_row].inventory = query.value("inventory").toDouble(); /* * Update the visible fields @@ -901,7 +959,23 @@ item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter); ui->yeastsTable->setItem(product->yeasts_row, 9, item); - //calcYeast(); + /* + * If there is no need for a starter, wipe it. + */ + bool maybe_starter = false; + for (int i = 0; i < product->yeasts.size(); i++) { + if (product->yeasts.at(i).use == YEAST_USE_PRIMARY && + ! ((product->yeasts.at(i).form == YEAST_FORMS_DRY) || (product->yeasts.at(i).form == YEAST_FORMS_DRIED))) + maybe_starter = true; + } + if (! maybe_starter) { +#ifdef DEBUG_YEAST + qDebug() << " Clear starter (if any)"; +#endif + for (int i = 0; i < 4; i++) + product->prop_volume[i] = 0; + } + is_changed(); emit refreshAll(); } @@ -911,7 +985,9 @@ { QSqlQuery query; +#ifdef DEBUG_YEAST qDebug() << "yeast_instock_changed()" << product->yeasts_row << val; +#endif this->yselectEdit->setCurrentIndex(-1); this->yselectEdit->clear(); @@ -933,7 +1009,9 @@ void EditProduct::yeast_useat_changed(int val) { +#ifdef DEBUG_YEAST qDebug() << "yeast_useat_changed()" << product->yeasts_row << val; +#endif product->yeasts[product->yeasts_row].use = val; QTableWidgetItem *item = new QTableWidgetItem(QCoreApplication::translate("YeastUse", g_yeast_use[val])); @@ -953,7 +1031,9 @@ QPushButton *pb = qobject_cast(QObject::sender()); product->yeasts_row = pb->objectName().toInt(); +#ifdef DEBUG_YEAST qDebug() << "Edit yeast row" << product->yeasts_row; +#endif Yeasts backup = product->yeasts.at(product->yeasts_row); QDialog* dialog = new QDialog(this); @@ -1070,7 +1150,9 @@ dialog->setModal(true); dialog->exec(); if (dialog->result() == QDialog::Rejected) { +#ifdef DEBUG_YEAST qDebug() << "reject and rollback"; +#endif product->yeasts[product->yeasts_row] = backup; } else { diff -r 2dfead81c72f -r deea5047be32 src/global.h --- a/src/global.h Thu Jan 12 14:34:14 2023 +0100 +++ b/src/global.h Thu Jan 12 16:56:34 2023 +0100 @@ -12,8 +12,9 @@ * Debug log switches for building */ // #define DEBUG_IBU 1 -#define DEBUG_FERMENTABLES 1 -#define DEBUG_VOLUMES 1 +// #define DEBUG_FERMENTABLES 1 +#define DEBUG_YEAST 1 +#define DEBUG_WATER 1 #define Ka1 0.0000004445 #define Ka2 0.0000000000468 diff -r 2dfead81c72f -r deea5047be32 translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Thu Jan 12 14:34:14 2023 +0100 +++ b/translations/bmsapp_en.ts Thu Jan 12 16:56:34 2023 +0100 @@ -3347,7 +3347,7 @@ - + Volume @@ -4225,7 +4225,7 @@ - + Delete %1 @@ -4260,7 +4260,7 @@ - + Use at: @@ -4274,7 +4274,7 @@ - + In stock: @@ -4416,8 +4416,8 @@ - - + + Amount in gr: @@ -4456,8 +4456,8 @@ - - + + Amount in ml: @@ -4468,13 +4468,13 @@ - + Primary - + Secondary @@ -4530,89 +4530,89 @@ - + Method - + Inj. factor - + New cells - + Total cells - + Grow factor - + Start step type: - + Starter step volume: - + Stirred - + Shaken - + Simple - + Delete yeast - - + + Total packs: - + Yeast name: - - + + Laboratory: - + Select yeast: - + Tertiary - + Bottle diff -r 2dfead81c72f -r deea5047be32 translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Thu Jan 12 14:34:14 2023 +0100 +++ b/translations/bmsapp_nl.ts Thu Jan 12 16:56:34 2023 +0100 @@ -3156,7 +3156,7 @@ - + Volume Volume @@ -4633,7 +4633,7 @@ - + Delete %1 @@ -4668,7 +4668,7 @@ - + Use at: Toevoegen bij: @@ -4682,7 +4682,7 @@ - + In stock: In voorraad: @@ -4824,8 +4824,8 @@ - - + + Amount in gr: Gewicht in gr: @@ -4883,8 +4883,8 @@ - - + + Amount in ml: Hoeveelheid in ml: @@ -4895,13 +4895,13 @@ - + Primary Hoofdgisting - + Secondary Nagisting/lagering @@ -4957,89 +4957,89 @@ Gist is al verwerkt - + Method Methode - + Inj. factor Injectie - + New cells Celgroei - + Total cells Totaal - + Grow factor Groeifactor - + Start step type: Starter stap type: - + Starter step volume: Starter stap volume: - + Stirred Geroerd - + Shaken Geschud - + Simple Simpel - + Delete yeast Verwijder gist - - + + Total packs: Aantal pakken: - + Yeast name: Gist naam: - - + + Laboratory: Laboratorium: - + Select yeast: Kies gist: - + Tertiary Lageren - + Bottle Bottelen