diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-02-25 14:24:09 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-02-25 14:24:09 -0800 |
commit | 67a1e3f3e0d18cd78c1e88471fbf664560f6bebb (patch) | |
tree | e07144c0c06d245b15120ae3224ee5f502164d65 /qt-ui/profile/diveprofileitem.cpp | |
parent | 21ed18816acab65e754144239f5f320cdf8c9c21 (diff) | |
download | subsurface-67a1e3f3e0d18cd78c1e88471fbf664560f6bebb.tar.gz |
New profile: try to pick better HR samples for which to print number
This simply tries to pick at least local minima / maxima.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile/diveprofileitem.cpp')
-rw-r--r-- | qt-ui/profile/diveprofileitem.cpp | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/qt-ui/profile/diveprofileitem.cpp b/qt-ui/profile/diveprofileitem.cpp index cd71f9bc1..fe47e7b5f 100644 --- a/qt-ui/profile/diveprofileitem.cpp +++ b/qt-ui/profile/diveprofileitem.cpp @@ -228,6 +228,11 @@ DiveHeartrateItem::DiveHeartrateItem() void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { int last = -300, last_printed_hr = 0, sec = 0; + struct { + int sec; + int hr; + } hist[3] = {0}; + // We don't have enougth data to calculate things, quit. if (!shouldCalculateStuff(topLeft, bottomRight)) return; @@ -243,18 +248,30 @@ void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QMode sec = dataModel->index(i, hDataColumn).data().toInt(); QPointF point( hAxis->posAtValue(sec), vAxis->posAtValue(hr)); poly.append(point); - - /* don't print a HR - * if it's been less than 5min and less than a 20 beats change OR - * if it's been less than 2min OR if the change from the - * last print is less than 10 beats */ - if (((sec < last + 300) && (abs(hr - last_printed_hr) < 20)) || + if (hr == hist[2].hr) + // same as last one, no point in looking at printing + continue; + hist[0] = hist[1]; + hist[1] = hist[2]; + hist[2].sec = sec; + hist[2].hr = hr; + // don't print a HR + // if it's not a local min / max + // if it's been less than 5min and less than a 20 beats change OR + // if it's been less than 2min OR if the change from the + // last print is less than 10 beats + // to test min / max requires three points, so we now look at the + // previous one + sec = hist[1].sec; + hr = hist[1].hr; + if ((hist[0].hr < hr && hr < hist[2].hr) || + (hist[0].hr > hr && hr > hist[2].hr) || + ((sec < last + 300) && (abs(hr - last_printed_hr) < 20)) || (sec < last + 120) || (abs(hr - last_printed_hr) < 10)) continue; last = sec; - if (hr > 0) - createTextItem(sec, hr); + createTextItem(sec, hr); last_printed_hr = hr; } setPolygon(poly); |