src/ChartiSpindel.cpp

changeset 498
c6f957fa7442
parent 494
49ac23d25f61
child 501
a01ae5ff0e96
equal deleted inserted replaced
497:cbd7644d99ca 498:c6f957fa7442
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 #include "ChartiSpindel.h" 17 #include "ChartiSpindel.h"
18 #include "callout.h" 18 #include "callout.h"
19 #include "MainWindow.h" 19 #include "MainWindow.h"
20 #include "Utils.h"
20 21
21 22
22 ChartiSpindel::ChartiSpindel(QString code, QString name, QWidget *parent) : QDialog(parent) 23 ChartiSpindel::ChartiSpindel(QString code, QString name, QWidget *parent) : QDialog(parent)
23 { 24 {
24 QSqlQuery query; 25 QSqlQuery query;
25 double timestamp; 26 double timestamp;
26 double sg_min = 1.2, sg_max = 0.8, sg; 27 double sg_min = 1.2, sg_max = 0.8, mg, sg;
27 double temp_min = 100, temp_max = 0, temp; 28 double temp_min = 100, temp_max = 0, temp;
28 double batt_min = 4.5, batt_max = 3.0, batt; 29 double batt_min = 4.5, batt_max = 3.0, batt;
29 30
30 qDebug() << "ChartiSpindel:" << code << name; 31 qDebug() << "ChartiSpindel:" << code << name;
31 32
55 query.bindValue(":code", code); 56 query.bindValue(":code", code);
56 query.exec(); 57 query.exec();
57 while (query.next()) { 58 while (query.next()) {
58 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000; 59 timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
59 60
60 sg = query.value("sg").toDouble(); 61 mg = query.value("sg").toDouble();
61 if ((ceil(sg * 100) / 100) > sg_max)
62 sg_max = ceil(sg * 100) / 100;
63 if ((floor(sg * 100) / 100) < sg_min)
64 sg_min = floor(sg * 100) / 100;
65
66 temp = query.value("temperature").toDouble(); 62 temp = query.value("temperature").toDouble();
67 if (ceil(temp) > temp_max) 63 if (ceil(temp) > temp_max)
68 temp_max = ceil(temp); 64 temp_max = ceil(temp);
69 if (floor(temp) < temp_min) 65 if (floor(temp) < temp_min)
70 temp_min = floor(temp); 66 temp_min = floor(temp);
67
68 /*
69 * Correct the SG plotline for temperature.
70 */
71 sg = Utils::HydroCorrection(mg, temp, 20.0);
72 if ((ceil(sg * 100) / 100) > sg_max)
73 sg_max = ceil(sg * 100) / 100;
74 if ((floor(sg * 100) / 100) < sg_min)
75 sg_min = floor(sg * 100) / 100;
71 76
72 batt = round(query.value("battery").toDouble() * 500) / 500; 77 batt = round(query.value("battery").toDouble() * 500) / 500;
73 if ((ceil(batt * 10) / 10) > batt_max) 78 if ((ceil(batt * 10) / 10) > batt_max)
74 batt_max = ceil(batt * 10) / 10; 79 batt_max = ceil(batt * 10) / 10;
75 if ((floor(batt * 10) / 10) < batt_min) 80 if ((floor(batt * 10) / 10) < batt_min)

mercurial