Fixed bug with FlagsLine Span, minor speed improvement in Day weighted percentile calculation.

This commit is contained in:
Mark Watkins 2012-01-05 22:12:42 +10:00
parent 96ff7471d9
commit 935850faa6
5 changed files with 51 additions and 32 deletions

View File

@ -156,13 +156,15 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
int np=el.count(); int np=el.count();
for (idx=0; idx < np; idx++) { for (idx=0; idx < np; idx++) {
X=start + *tptr++; X=start + *tptr;
L=*dptr++ * 1000; L=*dptr * 1000;
if (X >= minx) if (X >= minx)
break; break;
X2=X-L; X2=X-L;
if (X2 >= minx) if (X2 >= minx)
break; break;
dptr++;
tptr++;
} }
np-=idx; np-=idx;
@ -211,12 +213,13 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
if (X > maxx) if (X > maxx)
break; break;
L=*dptr++ * 1000; L=*dptr++ * 1000L;
X2=X-L; X2=X-L;
x1=(X - minx) * xmult + left; x1=double(X - minx) * xmult + left;
x2=(X2-minx)*xmult+left; x2=double(X2 - minx) * xmult + left;
quads->unsafe_add(x2,bartop,x1,bartop, x1,bottom,x2,bottom);
quads->add(x2,bartop,x1,bartop, x1,bottom,x2,bottom);
//if (quads->full()) { verts_exceeded=true; break; } //if (quads->full()) { verts_exceeded=true; break; }
} }

View File

@ -165,10 +165,11 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile)
QVector<Session *>::iterator s; QVector<Session *>::iterator s;
QMap<EventDataType, int> wmap; QHash<EventStoreType, int> wmap;
int SN=0; int SN=0;
EventDataType lastgain=0, gain=0;
// First Calculate count of all events // First Calculate count of all events
for (s=sessions.begin();s!=sessions.end();s++) { for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue; if (!(*s)->enabled()) continue;
@ -177,27 +178,42 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile)
QHash<ChannelID,QHash<EventStoreType, EventStoreType> > ::iterator ei=sess.m_valuesummary.find(code); QHash<ChannelID,QHash<EventStoreType, EventStoreType> > ::iterator ei=sess.m_valuesummary.find(code);
if (ei==sess.m_valuesummary.end()) continue; if (ei==sess.m_valuesummary.end()) continue;
EventDataType gain=sess.m_gain[code]; gain=sess.m_gain[code];
EventDataType weight,value;
// Here's assuming gains don't change accross a days sessions
// Can't assume this in any multi day calculations..
if (lastgain>0) {
if (gain!=lastgain) {
qDebug() << "Gains differ across sessions :(";
}
}
lastgain=gain;
int weight,value;
QHash<EventStoreType,int>::iterator wit;
for (QHash<EventStoreType, EventStoreType>::iterator i=ei.value().begin();i!=ei.value().end();i++) { for (QHash<EventStoreType, EventStoreType>::iterator i=ei.value().begin();i!=ei.value().end();i++) {
weight=i.value(); weight=i.value();
value=EventDataType(i.key())*gain; value=i.key();
SN+=weight; SN+=weight;
if (wmap.contains(value)) {
// Cheating here.. On first access, it initializes to zero
wmap[value]+=weight; wmap[value]+=weight;
} else { // wit=wmap.find(value);
wmap[value]=weight; // if (wit==wmap.end()) {
} // wmap[value]=weight;
// } else {
// wit.value()+=weight;
// }
} }
} }
QVector<ValueCount> valcnt; QVector<ValueCount> valcnt;
// Build sorted list of value/counts // Build sorted list of value/counts
for (QMap<EventDataType, int>::iterator n=wmap.begin();n!=wmap.end();n++) { for (QHash<EventStoreType, int>::iterator n=wmap.begin();n!=wmap.end();n++) {
ValueCount vc; ValueCount vc;
vc.value=n.key(); vc.value=EventDataType(n.key()) * gain;
vc.count=n.value(); vc.count=n.value();
vc.p=0; vc.p=0;
valcnt.push_back(vc); valcnt.push_back(vc);
@ -213,7 +229,7 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile)
int sum1=0,sum2=0; int sum1=0,sum2=0;
int w1,w2=0; int w1,w2=0;
EventDataType v1,v2; EventDataType v1=0,v2;
int N=valcnt.size(); int N=valcnt.size();
int k=0; int k=0;
@ -249,11 +265,9 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile)
return v; return v;
// p1.....p.............p2 // p1.....p.............p2
// 37 55 70 // 37 55 70
} }
EventDataType Day::p90(ChannelID code) EventDataType Day::p90(ChannelID code)

View File

@ -710,8 +710,8 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac
QMap<EventDataType, int> wmap; QMap<EventDataType, int> wmap;
QHash<ChannelID,QHash<EventStoreType, EventStoreType> >::iterator vsi; QHash<ChannelID,QHash<EventStoreType, EventStoreType> >::iterator vsi;
EventDataType val,gain; EventDataType gain;
bool setgain=false; //bool setgain=false;
EventDataType weight,value; EventDataType weight,value;
int SN=0; int SN=0;
@ -768,7 +768,7 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac
int sum1=0,sum2=0; int sum1=0,sum2=0;
int w1,w2=0; int w1,w2=0;
EventDataType v1,v2; EventDataType v1=0,v2=0;
int N=valcnt.size(); int N=valcnt.size();
int k=0; int k=0;

View File

@ -724,7 +724,7 @@ void Daily::Load(QDate date)
//ui->graphVisibilityToggleArea->setVisible(true); //ui->graphVisibilityToggleArea->setVisible(true);
updateGraphCombo(); updateGraphCombo();
int graphsAvailable=GraphView->visibleGraphs(); //int graphsAvailable=GraphView->visibleGraphs();
// if (graphsAvailable>0) { // if (graphsAvailable>0) {
// GraphView->setCubeImage(images["sheep"]); // GraphView->setCubeImage(images["sheep"]);
// GraphView->setEmptyText(tr("Graphs Switched Off")); // GraphView->setEmptyText(tr("Graphs Switched Off"));
@ -1537,7 +1537,7 @@ void Daily::on_bookmarkTable_itemClicked(QTableWidgetItem *item)
bool ok; bool ok;
st=it->data(Qt::UserRole).toLongLong(&ok); st=it->data(Qt::UserRole).toLongLong(&ok);
et=it->data(Qt::UserRole+1).toLongLong(&ok); et=it->data(Qt::UserRole+1).toLongLong(&ok);
qint64 st2,et2,st3,et3; qint64 st2=0,et2=0,st3,et3;
Day * day=PROFILE.GetGoodDay(previous_date,MT_CPAP); Day * day=PROFILE.GetGoodDay(previous_date,MT_CPAP);
if (day) { if (day) {
st2=day->first(); st2=day->first();

View File

@ -272,10 +272,10 @@ void SerialOximeter::compactToEvent(EventList *el)
{ {
if (el->count()<2) return; if (el->count()<2) return;
EventList nel(EVL_Waveform); EventList nel(EVL_Waveform);
EventDataType t,lastt=0; //el->data(0); EventDataType t=0,lastt=0; //el->data(0);
qint64 ti;//=el->time(0); qint64 ti=0;//=el->time(0);
//nel.AddEvent(ti,lastt); //nel.AddEvent(ti,lastt);
bool f; bool f=false;
qint64 lasttime=0; qint64 lasttime=0;
EventDataType min=999,max=0; EventDataType min=999,max=0;
for (quint32 i=0;i<el->count();i++) { for (quint32 i=0;i<el->count();i++) {
@ -1373,7 +1373,7 @@ bool Oximetry::openSPOFile(QString filename)
secondSPO2Update=true; secondSPO2Update=true;
unsigned char o2,pr; unsigned char o2,pr;
quint16 pl; //quint16 pl;
qint64 tt=qint64(date.toTime_t())*1000L; qint64 tt=qint64(date.toTime_t())*1000L;
for (int i=pos;i<size-5;) { for (int i=pos;i<size-5;) {
@ -1382,7 +1382,9 @@ bool Oximetry::openSPOFile(QString filename)
//oximeter->setLastTime(tt); //oximeter->setLastTime(tt);
oximeter->addPulse(tt,pr); oximeter->addPulse(tt,pr);
oximeter->addSpO2(tt,o2); oximeter->addSpO2(tt,o2);
pl=(unsigned char)(data.at(i+1)); //pl=(unsigned char)(data.at(i+1));
//oximeter->addPlethy(tt,pl); //oximeter->addPlethy(tt,pl);
//pl=(unsigned char)(data.at(i+1)); //pl=(unsigned char)(data.at(i+1));
//oximeter->addPlethy(tt,pl); //oximeter->addPlethy(tt,pl);
@ -1453,7 +1455,7 @@ bool Oximetry::openSPORFile(QString filename)
secondSPO2Update=true; secondSPO2Update=true;
unsigned char o2,pr; unsigned char o2,pr;
quint16 pl; //quint16 pl;
qint64 tt=qint64(date.toTime_t())*1000L; qint64 tt=qint64(date.toTime_t())*1000L;
for (int i=pos;i<size-2;) { for (int i=pos;i<size-2;) {
@ -1461,7 +1463,7 @@ bool Oximetry::openSPORFile(QString filename)
pr=(unsigned char)(data.at(i+0)); pr=(unsigned char)(data.at(i+0));
oximeter->addPulse(tt,pr); oximeter->addPulse(tt,pr);
oximeter->addSpO2(tt,o2); oximeter->addSpO2(tt,o2);
pl=(unsigned char)(data.at(i+1)); //pl=(unsigned char)(data.at(i+1));
i+=2; i+=2;
tt+=1000; tt+=1000;
} }