Add support for hop extract values with XML import

Wed, 03 Aug 2022 11:09:07 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 03 Aug 2022 11:09:07 +0200
changeset 389
a98d45793808
parent 388
5eea69925634
child 390
2a69be28a925

Add support for hop extract values with XML import

src/ImportXML.cpp file | annotate | diff | comparison | revisions
--- a/src/ImportXML.cpp	Tue Aug 02 20:19:55 2022 +0200
+++ b/src/ImportXML.cpp	Wed Aug 03 11:09:07 2022 +0200
@@ -507,6 +507,8 @@
                     total++;
 		    Hops *h = new Hops();
 		    h->notes = h->origin = h->substitutes = "";
+		    h->bu_factor = 1.0;
+		    h->utilisation = my_ut_pellet;
 
                     while (xml->readNext()) {
                         if (xml->atEnd())
@@ -515,7 +517,7 @@
 			    query.prepare("INSERT INTO inventory_hops SET name=:name, alpha=:alpha, beta=:beta, "
 				"humulene=:humulene, caryophyllene=:cary, cohumulone=:cohumulone, myrcene=:myrcene, "
 				"hsi=:hsi, type=:type, form=:form, notes=:notes, origin=:origin, substitutes=:substitutes, "
-				"total_oil=:oil, uuid = :uuid");
+				"total_oil=:oil, utilisation=:utilisation, bu_factor=:bu_factor, uuid = :uuid");
 			    query.bindValue(":name", h->name);
 			    query.bindValue(":alpha", QString("%1").arg(h->alpha, 2, 'f', 1, '0'));
 			    query.bindValue(":beta", QString("%1").arg(h->beta, 2, 'f', 1, '0'));
@@ -530,6 +532,8 @@
 			    query.bindValue(":origin", h->origin);
 			    query.bindValue(":substitutes", h->substitutes);
 			    query.bindValue(":oil", QString("%1").arg(h->total_oil, 2, 'f', 1, '0'));
+			    query.bindValue(":utilisation", QString("%1").arg(h->utilisation, 2, 'f', 1, '0'));
+			    query.bindValue(":bu_factor", QString("%1").arg(h->bu_factor, 2, 'f', 1, '0'));
 			    query.bindValue(":uuid", QUuid::createUuid().toString().mid(1, 36));
 			    query.exec();
                             if (query.lastError().isValid()) {
@@ -550,40 +554,47 @@
                             h->origin = xml->readElementText();
 			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "NOTES")) {
                             h->notes = xml->readElementText();
-			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FORM")) {
-			    QString temp = xml->readElementText();
-			    if (temp == "Plug")
-				h->form = 1;
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) &&
+					((xml->name() == "FORM") || (xml->name() == "BMS_FORM"))) {
+                            QString temp = xml->readElementText();
+                            if (temp == "Plug")
+                                h->form = HOP_FORMS_PLUG;
                             else if (temp == "Leaf")
-				h->form = 2;
+                                h->form = HOP_FORMS_LEAF;
                             else if (temp == "Leaf wet")
-				h->form = 3;
+                                h->form = HOP_FORMS_LEAF_WET;
                             else if (temp == "Cryo")
-				h->form = 4;
-			    else
-				h->form = 0;
+                                h->form = HOP_FORMS_CRYO;
+			    else if (temp == "CO2 extract")
+				h->form = HOP_FORMS_CO2EXTRACT;
+			    else if (temp == "Iso extract")
+				h->form = HOP_FORMS_ISOEXTRACT;
+                            else
+                                h->form = HOP_FORMS_PELLET;
 			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ALPHA")) {
 			    h->alpha = xml->readElementText().toDouble();
 			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) {
                             QString temp = xml->readElementText();
 			    if (temp == "Aroma")
-				h->type = 1;
+				h->type = HOP_TYPE_AROMA;
 			    else if (temp == "Both")
-				h->type = 2;
+				h->type = HOP_TYPE_BOTH;
 			    else
-				h->type = 0;
+				h->type = HOP_TYPE_BITTERING;
 			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) {
 			    QString temp = xml->readElementText();
 			    if (temp == "First wort")
-				h->useat = 1;
+				h->useat = HOP_USEAT_FWH;
 			    else if (temp == "Boil")
-				h->useat = 2;
+				h->useat = HOP_USEAT_BOIL;
                             else if (temp == "Aroma")
-				h->useat = 3;
+				h->useat = HOP_USEAT_AROMA;
                             else if (temp == "Whirlpool")
-				h->useat = 4;
+				h->useat = HOP_USEAT_WHIRLPOOL;
                             else if (temp == "Dry hop")
-				h->useat = 5;
+				h->useat = HOP_USEAT_DRY_HOP;
+			    else if (temp == "Bottling")
+				h->useat = HOP_USEAT_BOTTLING;
 			    else
 				h->useat = 0;
 			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BETA")) {
@@ -603,6 +614,10 @@
                             h->myrcene = xml->readElementText().toDouble();
 			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_OIL")) {
                             h->total_oil = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UTILISATION")) {
+                            h->utilisation = xml->readElementText().toDouble();
+			} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UT_FACTOR")) {
+                            h->bu_factor = xml->readElementText().toDouble();
                         } else {
                             if (xml->tokenType() == QXmlStreamReader::StartElement)
                                 qDebug() << "2  " << xml->tokenType() << xml->name();
@@ -1150,6 +1165,8 @@
                                      * Process hop
                                      */
 				    Hops *newh = new Hops();
+				    newh->utilisation = my_ut_pellet;
+				    newh->bu_factor = 1.0;
                                     while (xml->readNext()) {
                                         if (xml->atEnd())
                                             break;
@@ -1168,42 +1185,49 @@
                                             newh->time = xml->readElementText().toDouble();
 					} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "AMOUNT")) {
                                             newh->amount = xml->readElementText().toDouble();
-                        		} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "FORM")) {
+                        		} else if ((xml->tokenType() == QXmlStreamReader::StartElement) &&
+							((xml->name() == "FORM") || (xml->name() == "BMS_FORM"))) {
                         		    QString temp = xml->readElementText();
                         		    if (temp == "Plug")
-                        		        newh->form = 1;
+                        		        newh->form = HOP_FORMS_PLUG;
                         		    else if (temp == "Leaf")
-                        		        newh->form = 2;
+                        		        newh->form = HOP_FORMS_LEAF;
                         		    else if (temp == "Leaf wet")
-                        		        newh->form = 3;
+                        		        newh->form = HOP_FORMS_LEAF_WET;
                         		    else if (temp == "Cryo")
-                        		        newh->form = 4;
+                        		        newh->form = HOP_FORMS_CRYO;
+					    else if (temp == "CO2 extract")
+						newh->form = HOP_FORMS_CO2EXTRACT;
+					    else if (temp == "Iso extract")
+						newh->form = HOP_FORMS_ISOEXTRACT;
                         		    else
-                        		        newh->form = 0;
+                        		        newh->form = HOP_FORMS_PELLET;
                         		} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "ALPHA")) {
                         		    newh->alpha = xml->readElementText().toDouble();
 					} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TYPE")) {
                         		    QString temp = xml->readElementText();
                         		    if (temp == "Aroma")
-                        		        newh->type = 1;
+                        		        newh->type = HOP_TYPE_AROMA;
                         		    else if (temp == "Both")
-                        		        newh->type = 2;
+                        		        newh->type = HOP_TYPE_BOTH;
                         		    else
-                        		        newh->type = 0;
+                        		        newh->type = HOP_TYPE_BITTERING;
                         		} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "USE")) {
                         		    QString temp = xml->readElementText();
                         		    if (temp == "First wort")
-                        		        newh->useat = 1;
+                        		        newh->useat = HOP_USEAT_FWH;
                         		    else if (temp == "Boil")
-                        		        newh->useat = 2;
+                        		        newh->useat = HOP_USEAT_BOIL;
                         		    else if (temp == "Aroma")
-                        		        newh->useat = 3;
+                        		        newh->useat = HOP_USEAT_AROMA;
                         		    else if (temp == "Whirlpool")
-                        		        newh->useat = 4;
+                        		        newh->useat = HOP_USEAT_WHIRLPOOL;
                         		    else if (temp == "Dry hop")
-                        		        newh->useat = 5;
+                        		        newh->useat = HOP_USEAT_DRY_HOP;
+					    else if (temp == "Bottling")
+						newh->useat = HOP_USEAT_BOTTLING;
                         		    else
-                        		        newh->useat = 0;
+                        		        newh->useat = HOP_USEAT_MASH;
 					} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BETA")) {
                         		    newh->beta = xml->readElementText().toDouble();
                         		} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "HSI")) {
@@ -1221,6 +1245,10 @@
                         		    newh->myrcene = xml->readElementText().toDouble();
                         		} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "TOTAL_OIL")) {
                         		    newh->total_oil = xml->readElementText().toDouble();
+					} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UTILISATION")) {
+                                            newh->utilisation = xml->readElementText().toDouble();
+					} else if ((xml->tokenType() == QXmlStreamReader::StartElement) && (xml->name() == "BMS_UT_FACTOR")) {
+                                            newh->bu_factor = xml->readElementText().toDouble();
 					}
                                     }
                                 }

mercurial