diff --git a/sleepyhead/Graphs/gLineChart.cpp b/sleepyhead/Graphs/gLineChart.cpp index 34b2a688..3bddf23a 100644 --- a/sleepyhead/Graphs/gLineChart.cpp +++ b/sleepyhead/Graphs/gLineChart.cpp @@ -701,202 +701,3 @@ void gLineChart::paint(QPainter &painter, gGraph &w, int left, int top, int widt painter.setClipping(false); painter.setRenderHint(QPainter::Antialiasing, false); } - - -AHIChart::AHIChart(QColor col) - : Layer(NoChannel), m_color(col) -{ - m_miny = m_maxy = 0; -} - -AHIChart::~AHIChart() -{ -} - -void AHIChart::paint(QPainter &painter, gGraph &w, int left, int top, int width, int height) -{ - if (!m_visible) { - return; - } - - if (!m_day) { - return; - } - - // Draw bounding box - painter.setPen(QColor(Qt::black)); - painter.drawLine(left, top, left, top + height); - painter.drawLine(left, top + height, left + width, top + height); - painter.drawLine(left + width, top + height, left + width, top); - painter.drawLine(left + width, top, left, top); - width--; - height -= 2; - - EventDataType miny, maxy; - double minx, maxx; - - maxx = w.max_x, minx = w.min_x; - - // hmmm.. subtract_offset.. - - if (w.zoomY() == 0 && PROFILE.appearance->allowYAxisScaling()) { - miny = w.physMinY(); - maxy = w.physMaxY(); - } else { - miny = w.min_y, maxy = w.max_y; - } - - w.roundY(miny, maxy); - - double xx = maxx - minx; - double xmult = double(width) / xx; - - EventDataType yy = maxy - miny; - EventDataType ymult = EventDataType(height - 3) / yy; // time to pixel conversion multiplier - - bool first = true; - double px, py; - double lastpx, lastpy; - double top1 = top + height; - bool done = false; - - painter.setPen(QPen(m_color,p_profile->appearance->lineThickness())); - painter.setClipRect(left, top, width, height); - painter.setClipping(true); - - for (int i = 0; i < m_time.size(); i++) { - qint64 ti = m_time[i]; - EventDataType v = m_data[i]; - - if (ti < minx) { continue; } - - if (ti > maxx) { done = true; } - - if (first) { - if (i > 0) { - ti = m_time[i - 1]; - v = m_data[i - 1]; - i--; - } - - px = left + (double(ti - minx) * xmult); - py = top1 - (double(v - miny) * ymult); - first = false; - } else { - px = left + (double(ti - minx) * xmult); - py = top1 - (double(v - miny) * ymult); - painter.drawLine(px, py, lastpx, lastpy); - } - - lastpx = px; - lastpy = py; - - if (done) { break; } - } - painter.setClipping(false); -} - -void AHIChart::SetDay(Day *d) -{ - m_day = d; - m_data.clear(); - m_time.clear(); - m_maxy = 0; - m_miny = 0; - - if (!d) { return; } - - m_miny = 9999; - QList::iterator s; - qint64 first = d->first(); - qint64 last = d->last(); - qint64 f; - - qint64 winsize = 30000; // 30 second windows - - for (qint64 ti = first; ti < last; ti += winsize) { - f = ti - 3600000L; - //if (fclockDrift()) * 1000L), drift = 0; - - bool fnd = false; - - for (s = d->begin(); s != d->end(); s++) { - if (!(*s)->enabled()) { continue; } - - Session *sess = *s; - - if ((ti < sess->first()) || (f > sess->last())) { continue; } - - drift = (sess->machine()->GetType() == MT_CPAP) ? clockdrift : 0; - - // Drop off suddenly outside of sessions - //if (ti>sess->last()) continue; - - fnd = true; - - if (sess->eventlist.contains(CPAP_Obstructive)) { - el[0] = sess->eventlist[CPAP_Obstructive][0]; - } else { el[0] = nullptr; } - - if (sess->eventlist.contains(CPAP_Apnea)) { - el[1] = sess->eventlist[CPAP_Apnea][0]; - } else { el[1] = nullptr; } - - if (sess->eventlist.contains(CPAP_Hypopnea)) { - el[2] = sess->eventlist[CPAP_Hypopnea][0]; - } else { el[2] = nullptr; } - - if (sess->eventlist.contains(CPAP_ClearAirway)) { - el[3] = sess->eventlist[CPAP_ClearAirway][0]; - } else { el[3] = nullptr; } - - if (sess->eventlist.contains(CPAP_NRI)) { - el[4] = sess->eventlist[CPAP_NRI][0]; - } else { el[4] = nullptr; } - - int znt = 5; - - if (PROFILE.general->calculateRDI()) { - if (sess->eventlist.contains(CPAP_RERA)) {// What about ExP?? - el[5] = sess->eventlist[CPAP_RERA][0]; - znt++; - } else { el[5] = nullptr; } - } - - qint64 t; - - for (int i = 0; i < znt; i++) { - if (!el[i]) { continue; } - - for (quint32 j = 0; j < el[i]->count(); j++) { - t = el[i]->time(j) + drift; - - if ((t >= f) && (t < ti)) { - cnt++; - } - } - } - } - - if (!fnd) { cnt = 0; } - - double g = double(ti - f) / 3600000.0; - - if (g > 0) { ahi = cnt / g; } - - if (ahi < m_miny) { m_miny = ahi; } - - if (ahi > m_maxy) { m_maxy = ahi; } - - m_time.append(ti); - m_data.append(ahi); - } - - m_minx = first; - m_maxx = last; -} diff --git a/sleepyhead/Graphs/gLineChart.h b/sleepyhead/Graphs/gLineChart.h index 9033f3ea..d952da73 100644 --- a/sleepyhead/Graphs/gLineChart.h +++ b/sleepyhead/Graphs/gLineChart.h @@ -18,44 +18,6 @@ #include "SleepLib/event.h" #include "SleepLib/day.h" -/*! \class AHIChart - \brief Another graph calculating the AHI/hour, this one looks at all the sessions for a day. Currently Unused. - */ -class AHIChart: public Layer -{ - public: - //! \brief Constructs an AHIChart object, with QColor col for the line plots. - AHIChart(QColor col = QColor("black")); - ~AHIChart(); - - //! \brief Draws the precalculated data to the Vertex buffers - virtual void paint(QPainter &painter, gGraph &w, int left, int top, int width, int height); - - //! \brief AHI/hr Calculations are done for this day here. - //! This also uses the sliding window method - virtual void SetDay(Day *d); - - //! \brief Returns the minimum AHI/hr value caculated - virtual EventDataType Miny() { return m_miny; } - - //! \brief Returns the maximum AHI/hr value caculated - virtual EventDataType Maxy() { return m_maxy; } - - //! \brief Returns true if no data was available - virtual bool isEmpty() { return m_data.size() == 0; } - - protected: - //! \brief Contains the plot data (Y-axis) generated for this day - QVector m_data; - - //! \brief Contains the time codes (X-axis) generated for this day - QVector m_time; - - EventDataType m_miny; - EventDataType m_maxy; - QColor m_color; -}; - /*! \class gLineChart \brief Draws a 2D linechart from all Session data in a day. EVL_Waveforms typed EventLists are accelerated. */