Improved average/p90 calculations a bit

This commit is contained in:
Mark Watkins 2011-06-03 05:04:43 +10:00
parent 7ffebb1cb8
commit 67b811d866
6 changed files with 44 additions and 28 deletions

View File

@ -7838,7 +7838,7 @@
"sleeplib/machine.h"
"graphs/graph.h"
1307007107 /home/mark/projects/git/sleepyhead/libs/sleeplib/machine.h
1307038106 /home/mark/projects/git/sleepyhead/libs/sleeplib/machine.h
<wx/string.h>
<wx/variant.h>
<wx/dir.h>
@ -7876,7 +7876,7 @@
<sleeplib/machine.h>
<list>
1307032231 /home/mark/projects/git/sleepyhead/version.h
1307041425 /home/mark/projects/git/sleepyhead/version.h
1306724655 /home/mark/projects/git/sleepyhead/libs/sleeplib/prs1_loader.h
"machine.h"
@ -7893,7 +7893,7 @@
"preferences.h"
"tinyxml/tinyxml.h"
1307020338 source:/home/mark/projects/git/sleepyhead/SleepyHeadMain.cpp
1307041425 source:/home/mark/projects/git/sleepyhead/SleepyHeadMain.cpp
"wx_pch.h"
"version.h"
<wx/app.h>
@ -7927,7 +7927,7 @@
<wx/ffile.h>
<wx/utils.h>
1307007829 source:/home/mark/projects/git/sleepyhead/libs/sleeplib/machine.cpp
1307040615 source:/home/mark/projects/git/sleepyhead/libs/sleeplib/machine.cpp
<tr1/random>
<wx/colour.h>
<wx/log.h>
@ -7961,7 +7961,7 @@
"machine_loader.h"
"tinyxml/tinyxml.h"
1307014047 source:/home/mark/projects/git/sleepyhead/libs/sleeplib/prs1_loader.cpp
1307041187 source:/home/mark/projects/git/sleepyhead/libs/sleeplib/prs1_loader.cpp
<wx/dir.h>
<wx/filename.h>
<wx/ffile.h>

View File

@ -763,10 +763,11 @@ void Daily::RefreshData()
if (mode==MODE_CPAP) {
html=html+wxT("<tr><td><b>")+_("Pressure")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),d->summary_min(CPAP_PressureMin))+wxT("</td></tr>\n");
} else if (mode==MODE_APAP) {
html=html+wxT("<tr><td><b>")+_("Avg&nbsp;Pressure")+wxT("</b></td><td>")+wxString::Format(wxT("%.2fcmH2O"),d->summary_avg(CPAP_PressureAverage))+wxT("</td></tr>\n");
html=html+wxT("<tr><td><b>")+_("90%&nbsp;Pressure")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),d->summary_weighted_avg(CPAP_PressurePercentValue))+wxT("</td></tr>\n");
html=html+wxT("<tr><td><b>")+_("Avg&nbsp;Pressure")+wxT("</b></td><td>")+wxString::Format(wxT("%.2fcmH2O"),d->summary_weighted_avg(CPAP_PressureAverage))+wxT("</td></tr>\n");
html=html+wxT("<tr><td><b>")+_("Min&nbsp;Reached")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),d->summary_min(CPAP_PressureMinAchieved))+wxT("</td></tr>\n");
html=html+wxT("<tr><td><b>")+_("Max&nbsp;Reached")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),d->summary_max(CPAP_PressureMaxAchieved))+wxT("</td></tr>\n");
html=html+wxT("<tr><td><b>")+_("90%&nbsp;Pressure")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),p90)+wxT("</td></tr>\n");
// html=html+wxT("<tr><td><b>")+_("90%&nbsp;Pressure")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),p90)+wxT("</td></tr>\n");
} else if (mode==MODE_BIPAP) {
html=html+wxT("<tr><td><b>")+_("Avg IPAP")+wxT("</b></td><td>")+wxString::Format(wxT("%.2fcmH2O"),d->summary_avg(BIPAP_IAPAverage))+wxT("</td></tr>\n");
html=html+wxT("<tr><td><b>")+_("Avg EPAP")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),d->summary_avg(BIPAP_EAPAverage))+wxT("</td></tr>\n");
@ -778,7 +779,7 @@ void Daily::RefreshData()
html=html+wxT("<tr><td><b>")+_("90%&nbsp;EPAP")+wxT("</b></td><td>")+wxString::Format(wxT("%.1fcmH2O"),eap90)+wxT("</td></tr>\n");
}
html=html+wxT("<tr><td><b>")+_("Avg Leak")+wxT("</b></td><td>")+wxString::Format(wxT("%.2f"),d->summary_avg(CPAP_LeakAverage))+wxT("</td></tr>\n");
html=html+wxT("<tr><td><b>")+_("Avg Leak")+wxT("</b></td><td>")+wxString::Format(wxT("%.2f"),d->summary_weighted_avg(CPAP_LeakAverage))+wxT("</td></tr>\n");
html=html+wxT("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>\n");

View File

@ -13,7 +13,7 @@ extern wxProgressDialog *loader_progress;
map<MachineType,ChannelCode> MachLastCode;
ChannelCode RegisterChannel(MachineType type)
/* ChannelCode RegisterChannel(MachineType type)
{
if (MachLastCode.find(type)==MachLastCode.end()) {
return MachLastCode[type]=0;
@ -21,7 +21,7 @@ ChannelCode RegisterChannel(MachineType type)
return ++(MachLastCode[type]);
};
const int CPLAP_FLONG=RegisterChannel(MT_CPAP);
const int CPAP_WHATEVER=RegisterChannel(MT_CPAP); */
//map<MachineID,Machine *> MachList;
/*map<MachineType,wxString> MachineTypeString= {
@ -438,6 +438,21 @@ EventDataType Day::summary_avg(MachineCode code)
val=tmp/EventDataType(cnt);
return val;
}
EventDataType Day::summary_weighted_avg(MachineCode code)
{
double s0=0,s1=0,s2=0;
for (vector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
Session & sess=*(*s);
if (sess.summary.find(code)!=sess.summary.end()) {
s0=sess.hours();
s1+=sess.summary[code].GetDouble()*s0;
s2+=s0;
}
}
if (s2==0) return 0;
return (s1/s2);
}
EventDataType Day::min(MachineCode code,int field)
{
@ -500,8 +515,8 @@ EventDataType Day::avg(MachineCode code,int field)
cnt++;
}
}
if (cnt==0) cnt=1;
return EventDataType(val/cnt);
if (cnt==0) return 0;
return EventDataType(val/float(cnt));
}
EventDataType Day::sum(MachineCode code,int field)
@ -537,21 +552,20 @@ EventDataType Day::count(MachineCode code)
EventDataType Day::weighted_avg(MachineCode code,int field)
{
double val=0;
// Cache this?
int cnt=0;
// Don't assume sessions are in order.
vector<Session *>::iterator s;
double s0=0,s1=0,s2=0;
for (s=sessions.begin();s!=sessions.end();s++) {
Session & sess=*(*s);
if (sess.events.find(code)!=sess.events.end()) {
val+=sess.weighted_avg_event_field(code,field);
cnt++;
s0=sess.hours();
s1+=sess.weighted_avg_event_field(code,field)*s0;
s2+=s0;
}
}
if (cnt==0) cnt=1;
return EventDataType(val/cnt);
if (s2==0) return 0;
return (s1/s2);
}
wxTimeSpan Day::total_time()
{

View File

@ -112,6 +112,7 @@ public:
// Note, the following convert to doubles without considering the consequences fully.
EventDataType summary_avg(MachineCode code);
EventDataType summary_weighted_avg(MachineCode code);
EventDataType summary_sum(MachineCode code);
EventDataType summary_min(MachineCode code);
EventDataType summary_max(MachineCode code);

View File

@ -312,7 +312,7 @@ int PRS1Loader::OpenMachine(Machine *m,wxString path,Profile *profile)
sess->summary[BIPAP_EAPMax]=sess->max_event_field(CPAP_EAP,0);
} else {
sess->summary[CPAP_PressureMedian]=sess->avg_event_field(CPAP_Pressure,0);
sess->summary[CPAP_PressureAverage]=sess->weighted_avg_event_field(CPAP_Pressure,0);
//sess->summary[CPAP_PressureAverage]=sess->weighted_avg_event_field(CPAP_Pressure,0);
sess->summary[CPAP_PressureMinAchieved]=sess->min_event_field(CPAP_Pressure,0);
sess->summary[CPAP_PressureMaxAchieved]=sess->max_event_field(CPAP_Pressure,0);
if (sess->summary.find(CPAP_PressureMin)==sess->summary.end()) {
@ -445,9 +445,9 @@ bool PRS1Loader::OpenSummary(Session *session,wxString filename)
session->summary[CPAP_PressureMinAchieved]=buffer[0x16]/10.0;
session->summary[CPAP_PressureMaxAchieved]=buffer[0x17]/10.0;
session->summary[CPAP_PressurePercentValue]=buffer[0x18]/10.0;
session->summary[CPAP_PressureAverage]=buffer[0x18]/10.0;
session->summary[CPAP_PressurePercentValue]=buffer[0x19]/10.0;
session->summary[CPAP_PressurePercentName]=90.0;
session->summary[CPAP_PressureAverage]=buffer[0x19]/10.0;
if (max==0) {
session->summary[CPAP_PressureAverage]=session->summary[CPAP_PressureMin];

View File

@ -16,14 +16,14 @@ namespace AutoVersion{
//Standard Version Type
static const long MAJOR = 0;
static const long MINOR = 7;
static const long BUILD = 2842;
static const long REVISION = 10143;
static const long BUILD = 2866;
static const long REVISION = 10289;
//Miscellaneous Version Types
static const long BUILDS_COUNT = 8401;
#define RC_FILEVERSION 0,7,2842,10143
#define RC_FILEVERSION_STRING "0, 7, 2842, 10143\0"
static const char FULLVERSION_STRING[] = "0.7.2842.10143";
static const long BUILDS_COUNT = 8490;
#define RC_FILEVERSION 0,7,2866,10289
#define RC_FILEVERSION_STRING "0, 7, 2866, 10289\0"
static const char FULLVERSION_STRING[] = "0.7.2866.10289";
//These values are to keep track of your versioning state, don't modify them.
static const long BUILD_HISTORY = 62;