From 2a8d2822ffcce9912c7559f4fd608dbf8c058115 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Tue, 19 Aug 2014 20:26:44 +1000 Subject: [PATCH] By Pressure experiments (temporary overlay) --- sleepyhead/Graphs/MinutesAtPressure.cpp | 131 +++++++++++++++++- sleepyhead/Graphs/MinutesAtPressure.h | 3 + .../loader_plugins/cms50f37_loader.cpp | 10 +- sleepyhead/daily.cpp | 8 +- sleepyhead/mainwindow.cpp | 8 +- 5 files changed, 144 insertions(+), 16 deletions(-) diff --git a/sleepyhead/Graphs/MinutesAtPressure.cpp b/sleepyhead/Graphs/MinutesAtPressure.cpp index 77f692de..5b88ec10 100644 --- a/sleepyhead/Graphs/MinutesAtPressure.cpp +++ b/sleepyhead/Graphs/MinutesAtPressure.cpp @@ -267,6 +267,94 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r row++; } + + + float maxmins = float(maxtime) / 60.0; + float ymult = height / maxmins; + + + row = 0; + + xpos = left ;//+ pix / 2; + + float y1, y2; + it = times.begin(); + float bottom = top+height; + if (it != times_end) { + float minutes = float(it.value()) / 60.0; + y1 = minutes * ymult; + + painter.setPen(QPen(QColor(Qt::gray), 2)); + it++; + for (; it != times_end; ++it) { + float minutes = float(it.value()) / 60.0; + y2 = minutes * ymult; + + painter.drawLine(xpos, bottom-y1, xpos+pix, bottom-y2); + y1 = y2; + xpos += pix; + } + + + float maxev = 0; + for (int i=0; i< numchans; ++i) { + ChannelID code = chans.at(i); + if (code == CPAP_AHI) continue; + + + schema::Channel & chan = schema::channel[code]; + if (!chan.enabled()) + continue; + schema::ChanType type = chan.type(); + if (type == schema::SPAN) + continue; + eit = events.find(code); + QMap::iterator eit_end = eit.value().end(); + for (it = times.begin(), vit = eit.value().begin(); vit != eit_end; ++vit, ++it) { + //float minutes = float(it.value()) / 60.0; + float value = vit.value(); + maxev = qMax(value, maxev); + } + } + float emult = height / float(maxev); + if (maxev < 0.00001) emult = 0; + + + for (int i=0; i< numchans; ++i) { + ChannelID code = chans.at(i); + if (code == CPAP_AHI) continue; + + + schema::Channel & chan = schema::channel[code]; + if (!chan.enabled()) + continue; + schema::ChanType type = chan.type(); + if (type == schema::SPAN) + continue; + painter.setPen(QPen(QColor(chan.defaultColor()), 2)); + eit = events.find(code); + xpos = left;//+pix/2; + + y1 = 0; + QMap::iterator eit_end = eit.value().end(); + for (it = times.begin(), vit = eit.value().begin(); vit != eit_end; ++vit, ++it) { + //float minutes = float(it.value()) / 60.0; + float value = vit.value(); + + y2 = value * emult; + //painter.drawPoint(xpos, bottom-y1); + + painter.drawLine(xpos, bottom-y1, xpos+pix, bottom-y2); + + xpos += pix; + y1 = y2; + + } + } + } + QString txt=QString("%1 %2").arg(maxmins).arg(float(maxevents * 60.0) / maxmins); + graph.renderText(txt, rect.left(), rect.top()-10); + timelock.unlock(); if (m_recalculating) { @@ -374,7 +462,7 @@ void RecalcMAP::run() first = false; } - if ((lastdata != data) || (time > maxx)) { + if (lastdata != data) { qint64 d1 = qMax(minx, lasttime); qint64 d2 = qMin(maxx, time); @@ -396,13 +484,37 @@ void RecalcMAP::run() lasttime = time; lastdata = data; } - if (time > maxx) break; + if (time > maxx) { + + break; + } skip: if (m_quit) { m_done = true; return; } } + if (lasttime < maxx) { + qint64 d1 = qMax(lasttime, minx); + qint64 d2 = qMin(maxx, EL->last()); + + int duration = (d2 - d1) / 1000L; + EventStoreType key = floor(lastdata * gain); + if (key <= 30) { + times[key] += duration; + for (int c = 0; c < chans.size(); ++c) { + ChannelID code = chans.at(c); + schema::Channel & chan = schema::channel[code]; + if (chan.type() == schema::SPAN) { + events[code][key] += sess->rangeSum(code, d1, d2); + } else { + events[code][key] += sess->rangeCount(code, d1, d2); + } + } + } + + } + } } @@ -424,10 +536,22 @@ skip: } chans.push_front(CPAP_AHI); + int maxevents = 0, val; + for (int i = map->m_minpressure; i <= map->m_maxpressure; i++) { - events[CPAP_AHI].insert(i,events[CPAP_Obstructive][i] + events[CPAP_Hypopnea][i] + events[CPAP_Apnea][i] + events[CPAP_ClearAirway][i]); + val = events[CPAP_Obstructive][i] + events[CPAP_Hypopnea][i] + events[CPAP_Apnea][i] + events[CPAP_ClearAirway][i]; + events[CPAP_AHI].insert(i, val); + // maxevents = qMax(val, maxevents); } + for (int i = map->m_minpressure; i <= map->m_maxpressure; i++) { + for (int j=0 ; j < chans.size(); ++j) { + code = chans.at(j); + if ((code == CPAP_AHI) || (schema::channel[code].type() == schema::SPAN)) continue; + val = events[code][i]; + maxevents = qMax(val, maxevents); + } + } QHash >::iterator eit; // for (int i=0; i< trash.size(); ++i) { @@ -444,6 +568,7 @@ skip: map->times = times; map->events = events; map->maxtime = maxtime; + map->maxevents = maxevents; map->chans = chans; map->m_presChannel = prescode; timelock.unlock(); diff --git a/sleepyhead/Graphs/MinutesAtPressure.h b/sleepyhead/Graphs/MinutesAtPressure.h index dcb86b91..aee340e2 100644 --- a/sleepyhead/Graphs/MinutesAtPressure.h +++ b/sleepyhead/Graphs/MinutesAtPressure.h @@ -66,10 +66,13 @@ protected: QList chans; QHash > events; int maxtime; + int maxevents; ChannelID m_presChannel; EventStoreType m_minpressure; EventStoreType m_maxpressure; + EventDataType max_mins; + QMap ahis; }; diff --git a/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp b/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp index 80fcb6d6..a8e2c48a 100644 --- a/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/cms50f37_loader.cpp @@ -327,7 +327,7 @@ void CMS50F37Loader::processBytes(QByteArray bytes) len = lengths[res & 0x1f]; - if (size < len) + if (len > size) break; if (len == 0) { @@ -432,7 +432,7 @@ void CMS50F37Loader::processBytes(QByteArray bytes) have_perfindex = (res == 0x9); -// m_startTime = QDateTime(imp_date, imp_time); + oxirec = new QVector; oxirec->reserve(30000); @@ -476,14 +476,14 @@ void CMS50F37Loader::processBytes(QByteArray bytes) QStringList str; for (int i=0; i < len; ++i) { - str.append(QString::number((unsigned char)buffer.at(idx + i)^0x80,16)); + str.append(QString::number((unsigned char)buffer.at(idx + i),16)); } if (!started_import) { // startTimer.singleShot(2000, this, SLOT(requestData())); - qDebug() << "Read:" << str.join(","); + qDebug() << "Read:" << len << size << str.join(","); } else { - qDebug() << "Import:" << str.join(","); + qDebug() << "Import:" << len << size << str.join(","); } idx += len; diff --git a/sleepyhead/daily.cpp b/sleepyhead/daily.cpp index 8061207f..3693bb7a 100644 --- a/sleepyhead/daily.cpp +++ b/sleepyhead/daily.cpp @@ -155,10 +155,10 @@ Daily::Daily(QWidget *parent,gGraphView * shared) const QString STR_GRAPH_DailySummary = "DailySummary"; const QString STR_GRAPH_TAP = "TimeAtPressure"; - gGraph * SG; - graphlist[STR_GRAPH_DailySummary] = SG = new gGraph(STR_GRAPH_DailySummary, GraphView, QObject::tr("Summary"), QObject::tr("Summary of this daily information"), default_height); - SG->AddLayer(new gLabelArea(nullptr),LayerLeft,gYAxis::Margin); - SG->AddLayer(AddCPAP(new gDailySummary())); +// gGraph * SG; +// graphlist[STR_GRAPH_DailySummary] = SG = new gGraph(STR_GRAPH_DailySummary, GraphView, QObject::tr("Summary"), QObject::tr("Summary of this daily information"), default_height); +// SG->AddLayer(new gLabelArea(nullptr),LayerLeft,gYAxis::Margin); +// SG->AddLayer(AddCPAP(new gDailySummary())); graphlist[STR_GRAPH_SleepFlags] = SF = new gGraph(STR_GRAPH_SleepFlags, GraphView, STR_TR_EventFlags, STR_TR_EventFlags, default_height); SF->setPinned(true); diff --git a/sleepyhead/mainwindow.cpp b/sleepyhead/mainwindow.cpp index 768568b9..cb2aab97 100644 --- a/sleepyhead/mainwindow.cpp +++ b/sleepyhead/mainwindow.cpp @@ -1322,7 +1322,7 @@ void MainWindow::on_action_About_triggered() QString("
%1
").arg(gitrev) + tr("Graphics Engine: %1").arg(getGraphicsEngine())+ "
" + - tr("Data Folder Location: %1").arg(QDir::toNativeSeparators(GetAppRoot()) + + (tr("Data Folder Location: %2").arg(GetAppRoot()).arg(QDir::toNativeSeparators(GetAppRoot())) + "
"+tr("Copyright") + " ©2011-2014 Mark Watkins (jedimark)
\n" + tr("This software is released under the GNU Public License v3.0
") + "
" @@ -1346,10 +1346,10 @@ void MainWindow::on_action_About_triggered() // Credits section "

" +tr("Kudos & Credits") + "

" + tr("Bugfixes, Patches and Platform Help:") + " " + - tr("James Marshall, Rich Freeman, John Masters, Keary Griffin, Patricia Shanahan, Alec Clews, manders99, Sean Stangl and Roy Stone.") + tr("James Marshall, Rich Freeman, John Masters, Keary Griffin, Patricia Shanahan, Alec Clews, manders99, Sean Stangl, Roy Stone, François Revol, Michael Masterson.") + "

" - "

" + tr("Translators:") + " " + tr("Arie Klerk (Dutch), Steffen Reitz (German), and others I've still to add here.") + + "

" + tr("Translators:") + " " + tr("Arie Klerk (Dutch), Steffen Reitz and Marc Stephan (German), Chen Hao (Chinese), Lars-Erik Söderström (Swedish), Damien Vigneron (French), António Jorge Costa (Portuguese), Judith Guzmán (Spanish) and others I've still to add here.") + "

" "

" + tr("3rd Party Libaries:") + " " + @@ -1357,7 +1357,7 @@ void MainWindow::on_action_About_triggered() + " " + tr("In the updater code, SleepyHead uses QuaZip by Sergey A. Tachenov, which is a C++ wrapper over Gilles Vollant's ZIP/UNZIP package.") + "
" - "

" + tr("Special thanks to Pugsy from CPAPTalk for her help with documentation and tutorials, as well as everyone who helped out by testing and sharing their CPAP data.") + "

" + tr("Special thanks to Pugsy and Robysue from CPAPTalk for their help with documentation and tutorials, as well as everyone who helped out by testing and sharing their CPAP data.") + "

" // Donations