Commit cc5bf85f authored by Giacomo Strangolino's avatar Giacomo Strangolino
Browse files

work in progress: implemented correlation and time

parent 58e74052
......@@ -3,7 +3,7 @@ isEmpty(CUMBIA_ROOT) {
}
include($${CUMBIA_ROOT}/include/quapps/quapps.pri)
# CONFIG += debug | release
CONFIG += debug
DEFINES -= QT_NO_DEBUG_OUTPUT
......
......@@ -14,7 +14,7 @@ QStandardItem* CheckableComboBoxModel::addItem(const QString &i, bool checkable)
QStandardItem* item = new QStandardItem(i);
if(checkable) {
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setData(Qt::Unchecked, Qt::CheckStateRole);
item->setData(Qt::Checked, Qt::CheckStateRole);
}
setItem(rowCount() -1, 0, item);
return item;
......
......@@ -130,6 +130,7 @@ void I0mapmon::onWlenSelectionChanged(const QString& , bool ) {
void I0mapmon::m_setup_x_list() {
ui->qucbx->insertItem(0, "time");
ui->qucbx->setItemData(0, "time", Qt::UserRole + 1);
// "PM2a Ni Photocurrent (a.u.)" /pos/diagnostics/photo_current_pos.01 None GetArea3
// "PM2a Ca Photocurrent (a.u.)" pos/diagnostics/photo_current_pos.01 None GetArea2
......@@ -155,13 +156,14 @@ void I0mapmon::m_setup_x_list() {
QList<int> I0mapmon::m_selected_wlens() const {
QList<int> idxs;
for(int i = 0; i < m_cb_model->rowCount(); i++)
if(m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()) idxs << i;
for(int i = 0; i < m_cb_model->rowCount(); i++) // i - 1: item 0: "time"
if(m_cb_model->item(i)->data(Qt::CheckStateRole).toBool()) idxs << i - 1;
return idxs;
}
void I0mapmon::m_plot_reconf() {
const QString& srcx = ui->qucbx->itemData(ui->qucbx->currentIndex(), Qt::UserRole + 1).toString();
const QString& devy = ui->quionSamples->source().section('/', 0, 2);
const QString devy = ui->quionSamples->source().remove("/" + ui->quionSamples->source().section('/',- 1));
printf("\e[1;32mI0mapmon.m_plot_reconf x \"%s\" y \"%s\"\e[0m\n", qstoc(srcx), qstoc(devy));
ui->plot->setSources(srcx, devy + '/' + ui->qucby->currentText(), m_selected_wlens(), ui->quionSamples->findChild<QuLabel *>()->text().toInt());
}
......@@ -49,7 +49,7 @@ private:
// methods
void m_setup_x_list();
constexpr QList<int> m_selected_wlens() const;
QList<int> m_selected_wlens() const;
};
#endif // I0mapmon_H
......@@ -2,6 +2,9 @@
#include <cumbiapool.h>
#include <cucontrolsfactorypool.h>
#include <quplotcurve.h>
#include <qutimescaledraw.h>
#include <qwt_symbol.h>
#include <qwt_date_scale_engine.h>
#include <cupluginloader.h>
#include <qumultireaderplugininterface.h>
......@@ -17,6 +20,7 @@ I0MMonPlot::I0MMonPlot(QWidget *parent, CumbiaPool *cup, const CuControlsFactory
: QuPlotBase(parent) {
m_ctrl_fpool = fpoo;
m_cu_poo = cup;
m_numsamples = 1;
CuPluginLoader plo;
QObject *plugin_qob;
m_multiread_plu_i = plo.get<QuMultiReaderPluginInterface>("libcumbia-multiread-plugin.so", &plugin_qob);
......@@ -31,7 +35,6 @@ I0MMonPlot::I0MMonPlot(QWidget *parent, CumbiaPool *cup, const CuControlsFactory
connect(m_multiread_plu_i->get_qobject(), SIGNAL(onSeqReadComplete(const QList<CuData> &)),
this, SLOT(onDataReady(const QList<CuData> &)));
}
}
bool I0MMonPlot::pluginLoaded() const {
......@@ -39,19 +42,155 @@ bool I0MMonPlot::pluginLoaded() const {
}
void I0MMonPlot::onDataReady(const QList<CuData> &dl) {
foreach(const CuData& d, dl)
printf("- %s\n", datos(d));
qDebug() << __PRETTY_FUNCTION__ << "data szi" << dl.size();
double x;
if(dl.size() == 2) { // correlate
QVector<double> yv, xv;
const CuData& xd = dl[0];
const CuData& yd = dl[1];
printf("\e[1;35mx %s , y %s\e[0m\n", vtoc2(xd, "value"), vtoc2(yd, "value"));
if(xd.has("data_format_str", "vector")) {
// average
double sum = 0.0;
const std::vector<double> &v = xd["value"].toDoubleVector();
for(size_t i = 0; i < v.size(); i++)
sum += v[i];
x = sum / m_numsamples;
}
else
x = xd["value"].toDouble();
// y
const std::vector<double> &yt = yd["value"].toDoubleVector();
for(int i = 0; i < m_lambda_idxs.size(); i++) {
if(m_lambda_idxs[i] < static_cast<int>(yt.size()) ) {
yv.push_back(yt[m_lambda_idxs[i]]);
xv.push_back(x);
}
}
QuPlotCurve * c = curve(m_curvenames.first());
if(c) {
if(c->style() != QwtPlotCurve::Dots) {
c->setStyle(QwtPlotCurve::Dots);
QPen p = c->pen();
p.setWidthF(2.0f);
c->setPen(p);
}
#if CUMBIA_QTCONTROLS_VERSION > 0x010202
c->setMaxDataSizeForSymbol(0); // disable first points symbol
#endif
if(!c->symbol() || c->symbol()->style() != QwtSymbol::XCross)
c->setSymbol(new QwtSymbol(QwtSymbol::XCross, c->brush(), c->pen(), QSize(10, 10)));
printf("\e[1;32mI0MMonPlot::onDataReady: curve: %s { ", qstoc(c->title().text()));
for(int i = 0; i < xv.size(); i++)
printf("(%.2f, %.2f), ", xv[i], yv[i]);
printf(" }\e[0m\n");
m_set_bounds(xv, yv, c->dataSize());
appendData(m_curvenames.first(), xv.data(), yv.data(), xv.size());
}
}
else if(dl.size() == 1) { // trend
const CuData &da = dl[0];
const std::vector<double> &yv = da["value"].toDoubleVector();
CuVariant ts = da["timestamp_ms"];
ts.getType() == CuVariant::LongInt ? x = static_cast<qint64>(ts.toLongInt()) : x = ts.toDouble();
printf("\e[0;33mdata %s -- timestamp %f\e[0m\n", datos(da), x);
for(int i = 0; i < m_lambda_idxs.size(); i++) {
const QString curveName = QString("lambda %1").arg(m_lambda_idxs[i]);
if(m_lambda_idxs[i] < static_cast<int>(yv.size()) ) {
qDebug() << __PRETTY_FUNCTION__ << "APPENDING" << QDateTime::fromMSecsSinceEpoch(x) << yv[m_lambda_idxs[i]];
appendData(curveName, x, yv[m_lambda_idxs[i]]);
}
}
refresh();
}
}
void I0MMonPlot::setSources(const QString &x, const QString &y, QList<int> lambda_idxs, int nsamples)
void I0MMonPlot::setSources(const QString &x, const QString &y, const QList<int> &lambda_idxs, int nsamples)
{
qDebug() << __PRETTY_FUNCTION__ << x << y << lambda_idxs;
QuPlotBase::clearPlot();
m_multiread_plu_i->unsetSources();
m_numsamples = nsamples;
m_lambda_idxs = lambda_idxs;
if(x == "time") {
m_set_x_trend_scale();
foreach(int l, lambda_idxs) {
addCurve(QString("lambda %1").arg(l));
m_curvenames = QStringList() << QString("lambda %1").arg(l);
}
if(m_multiread_plu_i)
m_multiread_plu_i->insertSource(y, 0);
}
else {
m_reset_scales();
addCurve(y);
m_curvenames = QStringList() << y;
if(m_multiread_plu_i ) {
m_multiread_plu_i->insertSource(x, 0);
m_multiread_plu_i->insertSource(y, 1);
}
}
}
QuPlotCurve *c = new QuPlotCurve(y);
if(m_multiread_plu_i ) {
m_multiread_plu_i->insertSource(x, 0);
m_multiread_plu_i->insertSource(y, 1);
void I0MMonPlot::m_set_bounds(const QVector<double> &xv, const QVector<double> &yv, int curve_datasiz)
{
// scales
const auto [xm, xM] = std::minmax_element(begin(xv), end(xv));
const auto [ym, yM] = std::minmax_element(begin(yv), end(yv));
double xlb, xub, ylb, yub;
xlb = (curve_datasiz == 0) ? (*xm) : xLowerBound();
xub = (curve_datasiz == 0) ? (*xM) : xUpperBound();
ylb = (curve_datasiz == 0) ? (*ym) : yLowerBound();
yub = (curve_datasiz == 0) ? (*yM) : yUpperBound();
if(*xm == *xM) {
if(xlb >= *xm)
xlb = (*xm - 0.5);
if(xub <= *xM)
xub = (*xM + 0.5);
} else {
if(xlb > *xm)
xlb = (*xm - 0.05 * (*xM - *xm));
if(xub < *xM)
xub = (*xM + 0.05 * (*xM - *xm));
}
if(*yM == *ym) {
if(ylb >= *ym)
ylb = (*ym - 0.5);
if(yub <= *yM)
yub = (*yM + 0.5);
} else {
if(ylb > *ym)
ylb = (*ym - 0.05 * (*yM - *ym));
if(yub < *yM)
yub = (*yM + 0.05 * (*yM - *ym));
}
if(xlb != xLowerBound())
setXLowerBound(xlb);
if(xub != xUpperBound())
setXUpperBound(xub);
if(ylb != yLowerBound())
setYLowerBound(ylb);
if(yub != yUpperBound())
setYUpperBound(yub);
}
void I0MMonPlot::m_reset_scales() {
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine());
setXAxisAutoscaleEnabled(false);
setYAxisAutoscaleEnabled(false);
setXLowerBound(-0.5); setXUpperBound(0.5);
setYLowerBound(-0.5); setYUpperBound(0.5);
}
void I0MMonPlot::m_set_x_trend_scale() {
setXAxisAutoscaleEnabled(true);
QuTimeScaleDraw *tsd = new QuTimeScaleDraw();
tsd->setDateEnabled(false);
setAxisScaleDraw(QwtPlot::xBottom, tsd);
setAxisLabelRotation(QwtPlot::xBottom, -50.0);
setAxisScaleEngine(QwtPlot::xBottom, new QwtDateScaleEngine(Qt::LocalTime));
setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
}
......@@ -21,14 +21,21 @@ signals:
public slots:
void onDataReady(const QList<CuData> & dl);
void setSources(const QString& x, const QString& y, QList<int> lambda_idxs, int nsamples);
void setSources(const QString& x, const QString& y, const QList<int>& lambda_idxs, int nsamples);
private:
void m_set_bounds(const QVector<double> &xv, const QVector<double> &yv, int curve_datasiz);
void m_reset_scales();
void m_set_x_trend_scale();
CumbiaPool *m_cu_poo;
CuControlsFactoryPool m_ctrl_fpool;
QuMultiReaderPluginInterface *m_multiread_plu_i;
int m_numsamples;
QList<int> m_lambda_idxs;
QStringList m_curvenames;
};
#endif // I0MMONPLOT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment