Refactor gPressureChart::populate().

This commit is contained in:
sawinglogz 2020-04-27 16:46:25 -04:00
parent c5768a64fe
commit 33eacab53f
2 changed files with 59 additions and 45 deletions

View File

@ -98,107 +98,115 @@ QString gPressureChart::channelRange(ChannelID code, const QString & label)
} }
void gPressureChart::addSlice(float value, ChannelID code, SummaryType type)
{
SummaryCalcItem* calc = getCalc(code, type);
float height = value - m_height;
QString label;
switch (type) {
case ST_SETMIN:
case ST_SETMAX:
label = schema::channel[code].label();
break;
case ST_MID:
label = m_day->calcMiddleLabel(code);
break;
case ST_90P:
label = m_day->calcPercentileLabel(code);
break;
default:
qWarning() << "Unsupported summary type in gPressureChart";
break;
}
m_slices->append(SummaryChartSlice(calc, value, height, label, calc->color));
m_height += height;
}
void gPressureChart::populate(Day * day, int idx) void gPressureChart::populate(Day * day, int idx)
{ {
float tmp;
CPAPMode mode = (CPAPMode)(int)qRound(day->settings_wavg(CPAP_Mode)); CPAPMode mode = (CPAPMode)(int)qRound(day->settings_wavg(CPAP_Mode));
QVector<SummaryChartSlice> & slices = cache[idx]; m_day = day;
SummaryCalcItem* calc; m_slices = &cache[idx];
m_height = 0;
if (mode == MODE_CPAP) { if (mode == MODE_CPAP) {
calc = getCalc(CPAP_Pressure);
float pr = day->settings_max(CPAP_Pressure); float pr = day->settings_max(CPAP_Pressure);
slices.append(SummaryChartSlice(calc, pr, pr, schema::channel[CPAP_Pressure].label(), calc->color)); addSlice(pr, CPAP_Pressure);
} else if (mode == MODE_APAP) { } else if (mode == MODE_APAP) {
float min = day->settings_min(CPAP_PressureMin); float min = day->settings_min(CPAP_PressureMin);
float max = day->settings_max(CPAP_PressureMax); float max = day->settings_max(CPAP_PressureMax);
tmp = min; addSlice(min, CPAP_PressureMin, ST_SETMIN);
slices.append(SummaryChartSlice(getCalc(CPAP_PressureMin, ST_SETMIN), min, min, schema::channel[CPAP_PressureMin].label(), getCalc(CPAP_PressureMin, ST_SETMIN)->color));
if (!day->summaryOnly()) { if (!day->summaryOnly()) {
float med = day->calcMiddle(CPAP_Pressure); float med = day->calcMiddle(CPAP_Pressure);
slices.append(SummaryChartSlice(getCalc(CPAP_Pressure, ST_MID), med, med - tmp, day->calcMiddleLabel(CPAP_Pressure), getCalc(CPAP_Pressure, ST_MID)->color)); addSlice(med, CPAP_Pressure, ST_MID);
tmp += med - tmp;
float p90 = day->calcPercentile(CPAP_Pressure); float p90 = day->calcPercentile(CPAP_Pressure);
slices.append(SummaryChartSlice(getCalc(CPAP_Pressure, ST_90P), p90, p90 - tmp, day->calcPercentileLabel(CPAP_Pressure), getCalc(CPAP_Pressure, ST_90P)->color)); addSlice(p90, CPAP_Pressure, ST_90P);
tmp += p90 - tmp;
} }
slices.append(SummaryChartSlice(getCalc(CPAP_PressureMax, ST_SETMAX), max, max - tmp, schema::channel[CPAP_PressureMax].label(), getCalc(CPAP_PressureMax, ST_SETMAX)->color)); addSlice(max, CPAP_PressureMax, ST_SETMAX);
} else if (mode == MODE_BILEVEL_FIXED) { } else if (mode == MODE_BILEVEL_FIXED) {
float epap = day->settings_max(CPAP_EPAP); float epap = day->settings_max(CPAP_EPAP);
float ipap = day->settings_max(CPAP_IPAP); float ipap = day->settings_max(CPAP_IPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_EPAP), epap, epap, schema::channel[CPAP_EPAP].label(), getCalc(CPAP_EPAP)->color)); addSlice(epap, CPAP_EPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAP), ipap, ipap - epap, schema::channel[CPAP_IPAP].label(), getCalc(CPAP_IPAP)->color)); addSlice(ipap, CPAP_IPAP);
} else if (mode == MODE_BILEVEL_AUTO_FIXED_PS) { } else if (mode == MODE_BILEVEL_AUTO_FIXED_PS) {
float epap = day->settings_max(CPAP_EPAPLo); float epap = day->settings_max(CPAP_EPAPLo);
tmp = epap;
float ipap = day->settings_max(CPAP_IPAPHi); float ipap = day->settings_max(CPAP_IPAPHi);
slices.append(SummaryChartSlice(getCalc(CPAP_EPAPLo), epap, epap, schema::channel[CPAP_EPAPLo].label(), getCalc(CPAP_EPAPLo)->color)); addSlice(epap, CPAP_EPAPLo);
if (!day->summaryOnly()) { if (!day->summaryOnly()) {
float e50 = day->calcMiddle(CPAP_EPAP); float e50 = day->calcMiddle(CPAP_EPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_EPAP, ST_MID), e50, e50 - tmp, day->calcMiddleLabel(CPAP_EPAP), getCalc(CPAP_EPAP, ST_MID)->color)); addSlice(e50, CPAP_EPAP, ST_MID);
tmp += e50 - tmp;
float e90 = day->calcPercentile(CPAP_EPAP); float e90 = day->calcPercentile(CPAP_EPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_EPAP, ST_90P), e90, e90 - tmp, day->calcPercentileLabel(CPAP_EPAP), getCalc(CPAP_EPAP, ST_90P)->color)); addSlice(e90, CPAP_EPAP, ST_90P);
tmp += e90 - tmp;
float i50 = day->calcMiddle(CPAP_IPAP); float i50 = day->calcMiddle(CPAP_IPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAP, ST_MID), i50, i50 - tmp, day->calcMiddleLabel(CPAP_IPAP), getCalc(CPAP_IPAP, ST_MID)->color)); addSlice(i50, CPAP_IPAP, ST_MID);
tmp += i50 - tmp;
float i90 = day->calcPercentile(CPAP_IPAP); float i90 = day->calcPercentile(CPAP_IPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAP, ST_90P), i90, i90 - tmp, day->calcPercentileLabel(CPAP_IPAP), getCalc(CPAP_IPAP, ST_90P)->color)); addSlice(i90, CPAP_IPAP, ST_90P);
tmp += i90 - tmp;
} }
slices.append(SummaryChartSlice(getCalc(CPAP_IPAPHi), ipap, ipap - tmp, schema::channel[CPAP_IPAPHi].label(), getCalc(CPAP_IPAPHi)->color)); addSlice(ipap, CPAP_IPAPHi);
} else if ((mode == MODE_BILEVEL_AUTO_VARIABLE_PS) || (mode == MODE_ASV_VARIABLE_EPAP)) { } else if ((mode == MODE_BILEVEL_AUTO_VARIABLE_PS) || (mode == MODE_ASV_VARIABLE_EPAP)) {
float epap = day->settings_max(CPAP_EPAPLo); float epap = day->settings_max(CPAP_EPAPLo);
tmp = epap;
slices.append(SummaryChartSlice(getCalc(CPAP_EPAPLo), epap, epap, schema::channel[CPAP_EPAPLo].label(), getCalc(CPAP_EPAPLo)->color)); addSlice(epap, CPAP_EPAPLo);
if (!day->summaryOnly()) { if (!day->summaryOnly()) {
float e50 = day->calcMiddle(CPAP_EPAP); float e50 = day->calcMiddle(CPAP_EPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_EPAP, ST_MID), e50, e50 - tmp, day->calcMiddleLabel(CPAP_EPAP), getCalc(CPAP_EPAP, ST_MID)->color)); addSlice(e50, CPAP_EPAP, ST_MID);
tmp += e50 - tmp;
float e90 = day->calcPercentile(CPAP_EPAP); float e90 = day->calcPercentile(CPAP_EPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_EPAP, ST_90P), e90, e90 - tmp, day->calcPercentileLabel(CPAP_EPAP), getCalc(CPAP_EPAP, ST_90P)->color)); addSlice(e90, CPAP_EPAP, ST_90P);
tmp += e90 - tmp;
float i50 = day->calcMiddle(CPAP_IPAP); float i50 = day->calcMiddle(CPAP_IPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAP, ST_MID), i50, i50 - tmp, day->calcMiddleLabel(CPAP_IPAP), getCalc(CPAP_IPAP, ST_MID)->color)); addSlice(i50, CPAP_IPAP, ST_MID);
tmp += i50 - tmp;
float i90 = day->calcPercentile(CPAP_IPAP); float i90 = day->calcPercentile(CPAP_IPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAP, ST_90P), i90, i90 - tmp, day->calcPercentileLabel(CPAP_IPAP), getCalc(CPAP_IPAP, ST_90P)->color)); addSlice(i90, CPAP_IPAP, ST_90P);
tmp += i90 - tmp;
} }
float ipap = day->settings_max(CPAP_IPAPHi); float ipap = day->settings_max(CPAP_IPAPHi);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAPHi), ipap, ipap - tmp, schema::channel[CPAP_IPAPHi].label(), getCalc(CPAP_IPAPHi)->color)); addSlice(ipap, CPAP_IPAPHi);
} else if (mode == MODE_ASV) { } else if (mode == MODE_ASV) {
float epap = day->settings_max(CPAP_EPAP); float epap = day->settings_max(CPAP_EPAP);
tmp = epap;
slices.append(SummaryChartSlice(getCalc(CPAP_EPAP), epap, epap, schema::channel[CPAP_EPAP].label(), getCalc(CPAP_EPAP)->color)); addSlice(epap, CPAP_EPAP);
if (!day->summaryOnly()) { if (!day->summaryOnly()) {
float i50 = day->calcMiddle(CPAP_IPAP); float i50 = day->calcMiddle(CPAP_IPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAP, ST_MID), i50, i50 - tmp, day->calcMiddleLabel(CPAP_IPAP), getCalc(CPAP_IPAP, ST_MID)->color)); addSlice(i50, CPAP_IPAP, ST_MID);
tmp += i50 - tmp;
float i90 = day->calcPercentile(CPAP_IPAP); float i90 = day->calcPercentile(CPAP_IPAP);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAP, ST_90P), i90, i90 - tmp, day->calcPercentileLabel(CPAP_IPAP), getCalc(CPAP_IPAP, ST_90P)->color)); addSlice(i90, CPAP_IPAP, ST_90P);
tmp += i90 - tmp;
} }
float ipap = day->settings_max(CPAP_IPAPHi); float ipap = day->settings_max(CPAP_IPAPHi);
slices.append(SummaryChartSlice(getCalc(CPAP_IPAPHi), ipap, ipap - tmp, schema::channel[CPAP_IPAPHi].label(), getCalc(CPAP_IPAPHi)->color)); addSlice(ipap, CPAP_IPAPHi);
} }
} }

View File

@ -48,8 +48,14 @@ public:
protected: protected:
SummaryCalcItem* getCalc(ChannelID code, SummaryType type = ST_SETMAX); SummaryCalcItem* getCalc(ChannelID code, SummaryType type = ST_SETMAX);
QString channelRange(ChannelID code, const QString & label); QString channelRange(ChannelID code, const QString & label);
void addSlice(float value, ChannelID code, SummaryType type = ST_SETMAX);
QHash<ChannelID,QHash<SummaryType,int>> m_calcs; QHash<ChannelID,QHash<SummaryType,int>> m_calcs;
// State passed between populate() and addSlice():
Day* m_day;
QVector<SummaryChartSlice>* m_slices;
float m_height;
}; };
#endif // GPRESSURECHART_H #endif // GPRESSURECHART_H