Wed, 16 Mar 2022 21:26:31 +0100
Added profile fermentation tables and editor.
20
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /** |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Utils.cpp is part of bmsapp. |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * bmsapp is free software: you can redistribute it and/or modify |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * it under the terms of the GNU General Public License as published by |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * the Free Software Foundation, either version 3 of the License, or |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * (at your option) any later version. |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * bmsapp is distributed in the hope that it will be useful, |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * GNU General Public License for more details. |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * You should have received a copy of the GNU General Public License |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | */ |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | #include "Utils.h" |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | |
42
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
19 | #include <QDebug> |
20
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | #include <math.h> |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | double Utils::lintner_to_kolbach(double lintner) |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | { |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | double wk = (3.5 * lintner) - 16; |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | if (wk < 0) |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | return 0.0; |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | return wk; |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | } |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | double Utils::kolbach_to_lintner(double kolbach) |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | { |
29
76846c99f827
Added inventory water editor and table. In Yeasts table make sure the fields without a tickmark are empty. Removed Utils::Round function, not reliable.
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
34 | return round(((kolbach + 16) / 3.5) * 1000.0) / 1000.0; |
20
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | } |
fcbbddcc22c1
Completed the Fermentables editor.
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | |
42
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
37 | |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
38 | double Utils::ebc_to_srm(double ebc) |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
39 | { |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
40 | double srm = -1.32303E-12 * pow(ebc, 4) - 0.00000000291515 * pow(ebc, 3) + 0.00000818515 * pow(ebc, 2) + 0.372038 * ebc + 0.596351; |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
41 | if (ebc < 0 || srm < 0) |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
42 | qDebug() << "ebc_to_srm(" << ebc << ") =" << srm; |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
43 | return srm; |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
44 | } |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
45 | |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
46 | |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
47 | double Utils::srm_to_ebc(double srm) |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
48 | { |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
49 | // Formule van Adrie Otten. brouwhulp. |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
50 | double ebc = round( 0.000000000176506 * pow(srm, 4) + 0.000000154529 * pow(srm, 3) - 0.000159428 * pow(srm, 2) + 2.68837 * srm - 1.6004 ); |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
51 | if ((ebc < 0) || (srm < 0)) |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
52 | qDebug() << "srm_to_ebc(" << srm << ") =" << ebc; |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
53 | return ebc; |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
54 | } |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
55 | |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
56 | |
88e827ea7172
Fixed recommend mash checkmark in fermentable editor. Added fermentables XML export.
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
57 | |
57
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
58 | QString Utils::hours_to_string(int hours) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
59 | { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
60 | int dd, hh, ww; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
61 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
62 | if (hours == 1) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
63 | return QObject::tr("1 hour"); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
64 | if (hours < 24) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
65 | return QString("%1 ").arg(hours) + QString(QObject::tr("hours")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
66 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
67 | dd = hours / 24; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
68 | hh = hours % 24; |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
69 | if (dd == 1) { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
70 | if (hh == 0) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
71 | return QString(QObject::tr("1 day")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
72 | else if (hh == 1) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
73 | return QString(QObject::tr("1 day, ")) + QString("%1 ").arg(hh) + QString(QObject::tr("hour")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
74 | else |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
75 | return QString(QObject::tr("1 day, ")) + QString("%1 ").arg(hh) + QString(QObject::tr("hours")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
76 | } else { |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
77 | if (hh == 0) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
78 | return QString("%1 ").arg(dd) + QString(QObject::tr("days")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
79 | else if (hh == 1) |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
80 | return QString("%1 ").arg(dd) + QString(QObject::tr("days, ")) + QString("%1 ").arg(hh) + QString(QObject::tr("hour")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
81 | else |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
82 | return QString("%1 ").arg(dd) + QString(QObject::tr("days, ")) + QString("%1 ").arg(hh) + QString(QObject::tr("hours")); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
83 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
84 | return QString("hours_to_string error"); |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
85 | } |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
86 | |
75d11cc05ce4
Added profile fermentation tables and editor.
Michiel Broek <mbroek@mbse.eu>
parents:
42
diff
changeset
|
87 |