File dialog fixes, Weighted average fix

This commit is contained in:
Mark Watkins 2011-12-13 22:49:48 +10:00
parent 10c282a1f5
commit 6cb33f3293
4 changed files with 38 additions and 13 deletions

View File

@ -134,7 +134,7 @@ void SummaryChart::SetDay(Day * nullday)
day->settingExists(code) ||
day->hasData(code,type);
if (code==CPAP_RespRate) {
if (code==CPAP_AHI) {
int i=5;
}
if (hascode) {

View File

@ -437,6 +437,10 @@ EventDataType calcAHI(Session *session,qint64 start, qint64 end)
int calcAHIGraph(Session *session)
{
const qint64 window_size=3600000L;
const qint64 window_step=30000; // 30 second windows
if (session->machine()->GetType()!=MT_CPAP) return 0;
if (session->eventlist.contains(CPAP_AHI)) return 0; // abort if already there
@ -445,8 +449,6 @@ int calcAHIGraph(Session *session)
!session->channelExists(CPAP_Apnea) &&
!session->channelExists(CPAP_ClearAirway)) return 0;
const qint64 winsize=30000; // 30 second windows
qint64 first=session->first(),
last=session->last(),
f;
@ -457,17 +459,23 @@ int calcAHIGraph(Session *session)
EventDataType ahi;
qint64 ti;
for (ti=first;ti<last;ti+=winsize) {
f=ti-3600000L;
double avg=0;
int cnt=0;
for (ti=first;ti<last;ti+=window_step) {
f=ti-window_size;
ahi=calcAHI(session,f,ti);
if (ti>=last) {
AHI->AddEvent(last,ahi);
avg+=ahi;
cnt++;
break;
}
AHI->AddEvent(ti,ahi);
ti+=winsize;
ti+=window_step;
}
AHI->AddEvent(last,0);
if (!cnt) avg=0; else avg/=double(cnt);
session->setAvg(CPAP_AHI,avg);
return AHI->count();
}

View File

@ -463,6 +463,9 @@ void Session::UpdateSummaries()
QHash<ChannelID,QVector<EventList *> >::iterator c;
for (c=eventlist.begin();c!=eventlist.end();c++) {
id=c.key();
if (id==CPAP_AHI) {
int i=5;
}
if (schema::channel[id].type()==schema::DATA) {
//sum(id); // avg calculates this and cnt.
min(id);
@ -860,6 +863,7 @@ EventDataType Session::percentile(ChannelID id,EventDataType percent)
EventDataType Session::wavg(ChannelID id)
{
QHash<EventStoreType,quint32> vtime;
QHash<ChannelID,EventDataType>::iterator i=m_wavg.find(id);
if (i!=m_wavg.end())
return i.value();
@ -876,9 +880,9 @@ EventDataType Session::wavg(ChannelID id)
qint64 lasttime=0,time,td;
EventStoreType val,lastval=0;
QHash<EventStoreType,quint32> vtime;
EventDataType gain=evec[0]->gain();
EventStoreType minval;
for (int i=0;i<size;i++) {
if (!evec[i]->count()) continue;
@ -895,13 +899,16 @@ EventDataType Session::wavg(ChannelID id)
lasttime=time;
lastval=val;
}*/
if (id==CPAP_AHI) {
int i=5;
}
time=evec[i]->time(0)/1000L;
val=evec[i]->raw(0);
minval=val=evec[i]->raw(0);
for (quint32 j=1;j<evec[i]->count();j++) {
lastval=val;
lasttime=time;
val=evec[i]->raw(j);
if (val<minval) minval=val;
time=evec[i]->time(j)/1000L;
td=(time-lasttime);
if (vtime.contains(lastval)) {
@ -909,7 +916,7 @@ EventDataType Session::wavg(ChannelID id)
} else vtime[lastval]=td;
}
if (lasttime>0) {
td=last()-time;
td=(last()/1000L)-time;
if (vtime.contains(val)) {
vtime[val]+=td;
} else vtime[val]=td;
@ -920,10 +927,13 @@ EventDataType Session::wavg(ChannelID id)
if (id==CPAP_Snore) {
int i=5;
}
if (minval<0) minval=-minval;
minval++;
// if (minval<0) minval+=(0-minval)+1; else minval=1;
qint64 s0=0,s1=0,s2=0,s3=0; // 32bit may all be thats needed here..
for (QHash<EventStoreType,quint32>::iterator i=vtime.begin(); i!=vtime.end(); i++) {
s0=i.value();
s3=i.key()+1;
s3=i.key()+minval;
s1+=s3*s0;
s2+=s0;
}
@ -931,7 +941,7 @@ EventDataType Session::wavg(ChannelID id)
return m_wavg[id]=0;
}
double j=double(s1)/double(s2);
j-=1;
j-=minval;
EventDataType v=j*gain;
if (v>32768*gain) {
v=0;

View File

@ -269,8 +269,14 @@ void MainWindow::on_action_Import_Data_triggered()
if (asknew) {
QFileDialog w;
w.setFileMode(QFileDialog::DirectoryOnly);
w.setFileMode(QFileDialog::Directory);
w.setOption(QFileDialog::ShowDirsOnly, true);
#if defined(Q_WS_MAC) && (QT_VERSION_CHECK(4,8,0) > QT_VERSION)
// Fix for tetragon, 10.6 barfs up Qt's custom dialog
w.setOption(QFileDialog::DontUseNativeDialog,true);
#else
w.setOption(QFileDialog::DontUseNativeDialog,false);
QListView *l = w.findChild<QListView*>("listView");
if (l) {
@ -280,6 +286,7 @@ void MainWindow::on_action_Import_Data_triggered()
if (t) {
t->setSelectionMode(QAbstractItemView::MultiSelection);
}
#endif
if (w.exec()!=QDialog::Accepted) {
return;
}