Added fermenter and iSpindel graphs.

Sat, 18 Jun 2022 20:39:59 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 18 Jun 2022 20:39:59 +0200
changeset 296
2f4e250cfed9
parent 295
4b2ac345b982
child 297
c8f0ecc8a1cc

Added fermenter and iSpindel graphs.

src/EditProduct.cpp file | annotate | diff | comparison | revisions
src/EditProductTab1.cpp file | annotate | diff | comparison | revisions
src/EditProductTab10.cpp file | annotate | diff | comparison | revisions
src/EditProductTab9.cpp file | annotate | diff | comparison | revisions
src/MainWindow.h file | annotate | diff | comparison | revisions
--- a/src/EditProduct.cpp	Sat Jun 18 19:15:22 2022 +0200
+++ b/src/EditProduct.cpp	Sat Jun 18 20:39:59 2022 +0200
@@ -113,6 +113,45 @@
     if (id >= 0) {
 	if (! DB_product::load(product, this, id))
 	    return;
+	/*
+	 * Check status of logfiles.
+	 */
+	if (product->stage > PROD_STAGE_BREW) {
+	    if (! product->log_brew) {
+		query.prepare("SELECT datetime FROM log_brews WHERE code=:code");
+		query.bindValue(":code", product->code);
+		query.exec();
+		if (query.first()) {
+		    qDebug() << "should update log_brews";
+		}
+	    }
+	    if (! product->log_fermentation) {
+		query.prepare("SELECT datetime FROM log_fermenter WHERE code=:code");
+		query.bindValue(":code", product->code);
+		query.exec();
+		if (query.first()) {
+		    qDebug() << "should update log_fermenter";
+		}
+	    }
+	    if (! product->log_ispindel) {
+		query.prepare("SELECT datetime FROM log_ispindel WHERE code=:code");
+                query.bindValue(":code", product->code);
+                query.exec();
+                if (query.first()) {
+                    qDebug() << "should update log_ispindel";
+                }
+	    }
+	}
+	if (product->stage > PROD_STAGE_PACKAGE) {
+	    if (! product->log_co2pressure) {
+		query.prepare("SELECT datetime FROM log_co2pressure WHERE code=:code");
+                query.bindValue(":code", product->code);
+                query.exec();
+                if (query.first()) {
+                    qDebug() << "should update log_co2pressure";
+                }
+	    }
+	}
 
     } else {
 	/* New product, set some defaults */
--- a/src/EditProductTab1.cpp	Sat Jun 18 19:15:22 2022 +0200
+++ b/src/EditProductTab1.cpp	Sat Jun 18 20:39:59 2022 +0200
@@ -456,6 +456,20 @@
 
     /* Tab 10, fermentation */
     ui->tabWidget->setTabEnabled(9, stage > PROD_STAGE_WAIT);
+    if (product->log_fermentation) {
+	ui->ferm_log1Label->show();
+	ui->ferm_log1Button->show();
+    } else {
+	ui->ferm_log1Label->hide();
+        ui->ferm_log1Button->hide();
+    }
+    if (product->log_ispindel) {
+	ui->ferm_log2Label->show();
+        ui->ferm_log2Button->show();
+    } else {
+	ui->ferm_log2Label->hide();
+        ui->ferm_log2Button->hide();
+    }
     ui->prim_enddateEdit->setReadOnly(true);
     ui->prim_enddateEdit->setButtonSymbols(QAbstractSpinBox::NoButtons);
     ui->prim_enddateButton->hide();
--- a/src/EditProductTab10.cpp	Sat Jun 18 19:15:22 2022 +0200
+++ b/src/EditProductTab10.cpp	Sat Jun 18 20:39:59 2022 +0200
@@ -265,11 +265,199 @@
 
 void EditProduct::ferm_log1_button()
 {
+    QSqlQuery query;
+    double timestamp;
+
+    QDialog* dialog = new QDialog(this);
+    dialog->resize(1024, 600);
+    dialog->setWindowTitle(tr("Fermenter log"));
+    dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+
+    QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
+    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
+    buttonBox->setGeometry(QRect(40, 565, 944, 36));
+    buttonBox->setLayoutDirection(Qt::LeftToRight);
+    buttonBox->setOrientation(Qt::Horizontal);
+    buttonBox->setStandardButtons(QDialogButtonBox::Ok);
+    buttonBox->setCenterButtons(true);
+
+    QSplineSeries *pv_air = new QSplineSeries();
+    QSplineSeries *pv_beer = new QSplineSeries();
+    QSplineSeries *pv_chiller = new QSplineSeries();
+    QSplineSeries *pwr_cool = new QSplineSeries();
+    QSplineSeries *pwr_heat = new QSplineSeries();
+
+    query.prepare("SELECT * FROM log_fermenter WHERE code=:code ORDER BY datetime");
+    query.bindValue(":code", product->code);
+    query.exec();
+    while (query.next()) {
+	timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
+	pv_air->append(timestamp, query.value("temp_air").toDouble());
+	pv_beer->append(timestamp, query.value("temp_beer").toDouble());
+	if (query.value("temp_chiller").toDouble() > 0)
+	    pv_chiller->append(timestamp, query.value("temp_chiller").toDouble());
+	pwr_cool->append(timestamp, query.value("cooler_power").toDouble());
+        pwr_heat->append(timestamp, query.value("heater_power").toDouble());
+    }
+
+    pv_air->setName(tr("Air"));
+    pv_air->setColor(QColorConstants::Svg::lightgreen);
+    pv_beer->setName(tr("Beer"));
+    QPen pen(QColorConstants::Svg::navy);
+    pen.setWidth(3);
+    pv_beer->setPen(pen);
+    pv_chiller->setName(tr("Chiller"));
+    pv_chiller->setColor(QColorConstants::Svg::lightsalmon);
+    pv_chiller->setOpacity(0.75);
+
+    pwr_cool->setName("Cool %");
+    pwr_cool->setOpacity(0.25);
+    pwr_cool->setColor(QColorConstants::Blue);
+    pwr_heat->setName("Heat %");
+    pwr_heat->setOpacity(0.25);
+    pwr_heat->setColor(QColorConstants::Red);
+
+    QChart *chart = new QChart();
+    chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name));
+    chart->addSeries(pwr_cool);
+    chart->addSeries(pwr_heat);
+    chart->addSeries(pv_chiller);
+    chart->addSeries(pv_air);
+    chart->addSeries(pv_beer);
+
+    QDateTimeAxis *axisX = new QDateTimeAxis;
+    axisX->setTickCount(10);
+    axisX->setFormat("dd MMM");
+    axisX->setTitleText("Date");
+    axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisX, Qt::AlignBottom);
+    pv_air->attachAxis(axisX);
+    pv_beer->attachAxis(axisX);
+    pv_chiller->attachAxis(axisX);
+
+    QValueAxis *axisY = new QValueAxis;
+    axisY->setTickCount(11);
+    axisY->setMinorTickCount(1);
+    axisY->setLabelFormat("%i");
+    axisY->setTitleText("Temp");
+    axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisY, Qt::AlignLeft);
+    pv_air->attachAxis(axisY);
+    pv_beer->attachAxis(axisY);
+    pv_chiller->attachAxis(axisY);
+
+    QValueAxis *axisYR = new QValueAxis;
+    axisYR->setRange(0, 100);
+    axisYR->setTickCount(11);
+    axisYR->setLabelFormat("%i");
+    axisYR->setTitleText("Power %");
+    axisYR->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisYR, Qt::AlignRight);
+    pwr_cool->attachAxis(axisYR);
+    pwr_heat->attachAxis(axisYR);
+
+    QChartView *chartView = new QChartView(chart);
+    chartView->setRenderHint(QPainter::Antialiasing);
+    dialog->setLayout(new QVBoxLayout);
+    dialog->layout()->addWidget(chartView);
+    dialog->layout()->addWidget(buttonBox);
+
+    connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
+    dialog->setModal(true);
+    dialog->exec();
 }
 
 
 void EditProduct::ferm_log2_button()
 {
+    QSqlQuery query;
+    double timestamp;
+
+    QDialog* dialog = new QDialog(this);
+    dialog->resize(1024, 600);
+    dialog->setWindowTitle(tr("iSpindel log"));
+    dialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);
+
+    QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog);
+    buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
+    buttonBox->setGeometry(QRect(40, 565, 944, 36));
+    buttonBox->setLayoutDirection(Qt::LeftToRight);
+    buttonBox->setOrientation(Qt::Horizontal);
+    buttonBox->setStandardButtons(QDialogButtonBox::Ok);
+    buttonBox->setCenterButtons(true);
+
+    QSplineSeries *temperature = new QSplineSeries();
+    QSplineSeries *density = new QSplineSeries();
+    QSplineSeries *battery = new QSplineSeries();
+
+    query.prepare("SELECT * FROM log_ispindel WHERE code=:code ORDER BY datetime");
+    query.bindValue(":code", product->code);
+    query.exec();
+    while (query.next()) {
+        timestamp = query.value("datetime").toDateTime().toSecsSinceEpoch() * 1000;
+        temperature->append(timestamp, query.value("temperature").toDouble());
+        density->append(timestamp, query.value("sg").toDouble());
+        battery ->append(timestamp, query.value("battery").toDouble());
+    }
+
+    temperature->setName(tr("Temperature"));
+    temperature->setColor(QColorConstants::Svg::red);
+    density->setName(tr("SG"));
+    QPen pen(QColorConstants::Svg::navy);
+    pen.setWidth(3);
+    density->setPen(pen);
+    battery->setName(tr("Battery"));
+    battery->setColor(QColorConstants::Svg::lightgreen);
+
+    QChart *chart = new QChart();
+    chart->setTitle(QString("%1 \"%2\"").arg(product->code).arg(product->name));
+    chart->addSeries(battery);
+    chart->addSeries(temperature);
+    chart->addSeries(density);
+
+    QDateTimeAxis *axisX = new QDateTimeAxis;
+    axisX->setTickCount(10);
+    axisX->setFormat("dd MMM");
+    axisX->setTitleText("Date");
+    axisX->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisX, Qt::AlignBottom);
+    battery->attachAxis(axisX);
+    temperature->attachAxis(axisX);
+    density->attachAxis(axisX);
+
+    QValueAxis *axisYT = new QValueAxis;
+    axisYT->setTickCount(10);
+    axisYT->setLabelFormat("%.1f");
+    axisYT->setTitleText("Temp");
+    axisYT->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisYT, Qt::AlignRight);
+    temperature->attachAxis(axisYT);
+
+    QValueAxis *axisYD = new QValueAxis;
+    axisYD->setTickCount(10);
+    axisYD->setLabelFormat("%.4f");
+    axisYD->setTitleText("SG");
+    axisYD->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisYD, Qt::AlignLeft);
+    density->attachAxis(axisYD);
+
+    QValueAxis *axisYB = new QValueAxis;
+    axisYB->setTickCount(10);
+    axisYB->setLabelFormat("%.2f");
+    axisYB->setTitleText("Battery");
+    axisYB->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
+    chart->addAxis(axisYB, Qt::AlignRight);
+    battery->attachAxis(axisYB);
+
+    QChartView *chartView = new QChartView(chart);
+    chartView->setRenderHint(QPainter::Antialiasing);
+    dialog->setLayout(new QVBoxLayout);
+    dialog->layout()->addWidget(chartView);
+    dialog->layout()->addWidget(buttonBox);
+
+    connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
+    dialog->setModal(true);
+    dialog->exec();
 }
 
 
--- a/src/EditProductTab9.cpp	Sat Jun 18 19:15:22 2022 +0200
+++ b/src/EditProductTab9.cpp	Sat Jun 18 20:39:59 2022 +0200
@@ -522,7 +522,7 @@
     axisY->setTickCount(12);
     axisY->setMinorTickCount(1);
     axisY->setLabelFormat("%i");
-    axisY->setTitleText("Temp/Power");
+    axisY->setTitleText(tr("Temperature or Power %"));
     axisY->setLabelsFont(QFont("Helvetica", 8, QFont::Normal));
     chart->addAxis(axisY, Qt::AlignLeft);
 
--- a/src/MainWindow.h	Sat Jun 18 19:15:22 2022 +0200
+++ b/src/MainWindow.h	Sat Jun 18 20:39:59 2022 +0200
@@ -63,7 +63,10 @@
 #include <QValueAxis>
 #include <QDateTimeAxis>
 #include <QLineSeries>
+#include <QSplineSeries>
 #include <QChartView>
+#include <QAreaSeries>
+
 
 using namespace QtCharts;
 

mercurial