# HG changeset patch # User Michiel Broek # Date 1692457083 -7200 # Node ID c6f957fa744268ab759d9fe9d75a35b067668b1d # Parent cbd7644d99cac232eeaf8f64ca129f8c69f9a1c5 In fermentation plot draw the SG line with temperature compensation. diff -r cbd7644d99ca -r c6f957fa7442 src/ChartiSpindel.cpp --- a/src/ChartiSpindel.cpp Fri Jul 07 20:17:21 2023 +0200 +++ b/src/ChartiSpindel.cpp Sat Aug 19 16:58:03 2023 +0200 @@ -17,13 +17,14 @@ #include "ChartiSpindel.h" #include "callout.h" #include "MainWindow.h" +#include "Utils.h" ChartiSpindel::ChartiSpindel(QString code, QString name, QWidget *parent) : QDialog(parent) { QSqlQuery query; double timestamp; - double sg_min = 1.2, sg_max = 0.8, sg; + double sg_min = 1.2, sg_max = 0.8, mg, sg; double temp_min = 100, temp_max = 0, temp; double batt_min = 4.5, batt_max = 3.0, batt; @@ -57,18 +58,22 @@ while (query.next()) { timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; - sg = query.value("sg").toDouble(); - if ((ceil(sg * 100) / 100) > sg_max) - sg_max = ceil(sg * 100) / 100; - if ((floor(sg * 100) / 100) < sg_min) - sg_min = floor(sg * 100) / 100; - + mg = query.value("sg").toDouble(); temp = query.value("temperature").toDouble(); if (ceil(temp) > temp_max) temp_max = ceil(temp); if (floor(temp) < temp_min) temp_min = floor(temp); + /* + * Correct the SG plotline for temperature. + */ + sg = Utils::HydroCorrection(mg, temp, 20.0); + if ((ceil(sg * 100) / 100) > sg_max) + sg_max = ceil(sg * 100) / 100; + if ((floor(sg * 100) / 100) < sg_min) + sg_min = floor(sg * 100) / 100; + batt = round(query.value("battery").toDouble() * 500) / 500; if ((ceil(batt * 10) / 10) > batt_max) batt_max = ceil(batt * 10) / 10; diff -r cbd7644d99ca -r c6f957fa7442 src/Utils.cpp --- a/src/Utils.cpp Fri Jul 07 20:17:21 2023 +0200 +++ b/src/Utils.cpp Sat Aug 19 16:58:03 2023 +0200 @@ -877,3 +877,14 @@ return P; } + +double Utils::HydroCorrection(double mg, double tr, double tc) +{ + double trf = tr * 1.8 + 32; + double tcf = tc * 1.8 + 32; + + return mg * ((1.00130346 - 1.34722124E-4 * trf + 2.04052596E-6 * trf * trf - 2.32820948E-9 * trf * trf * trf) / + (1.00130346 - 1.34722124E-4 * tcf + 2.04052596E-6 * tcf * tcf - 2.32820948E-9 * tcf * tcf * tcf)); +} + + diff -r cbd7644d99ca -r c6f957fa7442 src/Utils.h --- a/src/Utils.h Fri Jul 07 20:17:21 2023 +0200 +++ b/src/Utils.h Sat Aug 19 16:58:03 2023 +0200 @@ -240,6 +240,15 @@ * @return Pressure in Bar. */ double GetPressureBar(double gl, double T); + + /** + * @brief Calculate Hydrometer (and iSpindel) Correction. + * @param mg Measured SG + * @param tr Temperature at reading in C + * @param tc Calibration temperature in C + * @return Corrected SG. + */ + double HydroCorrection(double mg, double tr, double tc); } #endif diff -r cbd7644d99ca -r c6f957fa7442 translations/bmsapp_en.ts --- a/translations/bmsapp_en.ts Fri Jul 07 20:17:21 2023 +0200 +++ b/translations/bmsapp_en.ts Sat Aug 19 16:58:03 2023 +0200 @@ -163,79 +163,79 @@ ChartiSpindel - + BMSapp - iSpindel - + Save - + Temperature - + SG - + Battery - + Date - + Temperature °C - + Battery volt - + Save Image - + Image (*.png) - + Save File - + No image file selected. - + %1 Temperature %2°C - + %1 Density %2 SG - + %1 Battery %2 volt Capacity %3% diff -r cbd7644d99ca -r c6f957fa7442 translations/bmsapp_nl.ts --- a/translations/bmsapp_nl.ts Fri Jul 07 20:17:21 2023 +0200 +++ b/translations/bmsapp_nl.ts Sat Aug 19 16:58:03 2023 +0200 @@ -193,7 +193,7 @@ ChartiSpindel - + BMSapp - iSpindel BMSapp - iSpindel @@ -202,76 +202,76 @@ Temp °C - + Save Bewaar - + Temperature Temperatuur - + SG SG - + Battery Batterij - + Date Datum - + Temperature °C Temperatuur °C - + Battery volt Batterij volt - + Save Image Opslaan plaatje - + Image (*.png) Plaatje (*.png) - + Save File Bestand opslaan - + No image file selected. Geen plaatjes bestand gekozen. - + %1 Temperature %2°C %1 Temperatuur %2°C - + %1 Density %2 SG %1 Dichtheid %2 SG - + %1 Battery %2 volt Capacity %3%