Activate Hide sessions switches

This commit is contained in:
Mark Watkins 2011-12-28 22:03:48 +10:00
parent c659706f2d
commit 0faf09a151
10 changed files with 102 additions and 14 deletions

View File

@ -140,6 +140,8 @@ void gFlagsLine::paint(gGraph & w,int left, int top, int width, int height)
qint64 X,Y;
m_flag_color=schema::channel[m_code].defaultColor();
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) {
if (!(*s)->enabled()) continue;
if ((*s)->eventlist.find(m_code)==(*s)->eventlist.end()) continue;
EventList & el=*((*s)->eventlist[m_code][0]);

View File

@ -189,10 +189,12 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height)
codepoints=0;
for (int svi=0;svi<m_day->size();svi++) {
if (!(*m_day)[svi]) {
Session *sess=(*m_day)[svi];
if (!sess) {
qWarning() << "gLineChart::Plot() NULL Session Record.. This should not happen";
continue;
}
if (!sess->enabled()) continue;
schema::Channel ch=schema::channel[code];
bool fndbetter=false;
for (QList<schema::Channel *>::iterator l=ch.m_links.begin();l!=ch.m_links.end();l++) {

View File

@ -61,6 +61,7 @@ void gLineOverlayBar::paint(gGraph & w, int left, int topp, int width, int heigh
}
EventStoreType raw;
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) {
if (!(*s)->enabled()) continue;
cei=(*s)->eventlist.find(m_code);
if (cei==(*s)->eventlist.end()) continue;
if (cei.value().size()==0) continue;
@ -166,6 +167,7 @@ void gLineOverlaySummary::paint(gGraph & w,int left, int top, int width, int hei
// Calculate the session time.
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) {
if (!(*s)->enabled()) continue;
first=(*s)->first();
last=(*s)->last();
if (last < w.min_x) continue;

View File

@ -38,6 +38,8 @@ void gSegmentChart::SetDay(Day *d)
for (int c=0;c<m_codes.size();c++) {
m_values[c]=0;
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end();s++) {
if (!(*s)->enabled()) continue;
int cnt=(*s)->count(m_codes[c]);
m_values[c]+=cnt;
m_total+=cnt;
@ -211,6 +213,8 @@ void gTAPGraph::SetDay(Day *d)
//bool changed;
EventDataType gain=1,offset=0;
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end();s++) {
if (!(*s)->enabled()) continue;
if ((*s)->eventlist.find(m_code)==(*s)->eventlist.end()) continue;
for (int q=0;q<(*s)->eventlist[m_code].size();q++) {
EventList &el=*(*s)->eventlist[m_code][q];

View File

@ -93,10 +93,13 @@ void SummaryChart::SetDay(Day * nullday)
dz2*=86400; // ft = first sessions time, rounded back to midnight..
for (int s=0;s<day->size();s++) {
tmp=(*day)[s]->hours();
Session *sess=(*day)[s];
if (!sess->enabled()) continue;
tmp=sess->hours();
m_values[dn][s]=tmp;
total+=tmp;
zt=qint64((*day)[s]->first())/1000L;
zt=qint64(sess->first())/1000L;
zt+=tz_offset;
tmp2=zt-dn*86400;

View File

@ -54,6 +54,8 @@ EventDataType Day::settings_sum(ChannelID code)
EventDataType val=0;
QVector<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
if (i!=sess.settings.end()) {
@ -69,6 +71,8 @@ EventDataType Day::settings_max(ChannelID code)
QVector<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
if (i!=sess.settings.end()) {
@ -86,6 +90,8 @@ EventDataType Day::settings_min(ChannelID code)
QVector<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
if (i!=sess.settings.end()) {
@ -108,6 +114,8 @@ EventDataType Day::settings_avg(ChannelID code)
int cnt=0;
QVector<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
if (i!=sess.settings.end()) {
@ -122,6 +130,8 @@ EventDataType Day::settings_wavg(ChannelID code)
{
double s0=0,s1=0,s2=0,tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
@ -148,6 +158,8 @@ EventDataType Day::percentile(ChannelID code,EventDataType percentile)
// Don't assume sessions are in order.
QVector<EventDataType> ar;
for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
QHash<ChannelID,QHash<EventStoreType, EventStoreType> > ::iterator ei=sess.m_valuesummary.find(code);
if (ei==sess.m_valuesummary.end()) continue;
@ -195,6 +207,8 @@ EventDataType Day::avg(ChannelID code)
// Don't assume sessions are in order.
for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
if (sess.m_avg.contains(code)) {
val+=sess.avg(code);
@ -212,6 +226,8 @@ EventDataType Day::sum(ChannelID code)
QVector<Session *>::iterator s;
for (s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
if (sess.m_sum.contains(code)) {
val+=sess.sum(code);
@ -225,7 +241,10 @@ EventDataType Day::wavg(ChannelID code)
double s0=0,s1=0,s2=0;
qint64 d;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
if (sess.m_wavg.contains(code)) {
d=sess.length();//.last(code)-sess.first(code);
s0=double(d)/3600000.0;
@ -245,6 +264,8 @@ qint64 Day::total_time()
{
qint64 d_totaltime=0;
for (QVector<Session *>::iterator s=begin();s!=end();s++) {
if (!(*s)->enabled()) continue;
Session & sess=*(*s);
d_totaltime+=sess.length();
}
@ -273,6 +294,7 @@ qint64 Day::first(ChannelID code)
qint64 tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
tmp=(*s)->first(code);
if (!tmp) continue;
if (!date) {
@ -290,6 +312,7 @@ qint64 Day::last(ChannelID code)
qint64 tmp;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
tmp=(*s)->last(code);
if (!tmp) continue;
if (!date) {
@ -306,9 +329,9 @@ EventDataType Day::Min(ChannelID code)
EventDataType tmp;
bool first=true;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->m_min.contains(code))
if ((!(*s)->m_min.contains(code)) || (!(*s)->enabled()))
continue;
//if ((*s)->eventlist.find(code)==(*s)->eventlist.end()) continue;
tmp=(*s)->Min(code);
if (first) {
min=tmp;
@ -324,6 +347,7 @@ bool Day::hasData(ChannelID code, SummaryType type)
{
bool has=false;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
Session *sess=*s;
switch(type) {
case ST_90P:
@ -377,6 +401,8 @@ EventDataType Day::Max(ChannelID code)
EventDataType tmp;
bool first=true;
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
if (!(*s)->enabled()) continue;
if (!(*s)->m_max.contains(code)) continue;
// if ((*s)->eventlist.find(code)==(*s)->eventlist.end()) continue;
tmp=(*s)->Max(code);
@ -394,6 +420,7 @@ EventDataType Day::cph(ChannelID code)
EventDataType sum=0;
//EventDataType h=0;
for (int i=0;i<sessions.size();i++) {
if (!sessions[i]->enabled()) continue;
if (!sessions[i]->m_cph.contains(code)) continue;
sum+=sessions[i]->cph(code)*sessions[i]->hours();
//h+=sessions[i]->hours();
@ -407,6 +434,7 @@ EventDataType Day::sph(ChannelID code)
EventDataType sum=0;
EventDataType h=0;
for (int i=0;i<sessions.size();i++) {
if (!sessions[i]->enabled()) continue;
if (!sessions[i]->m_sum.contains(code)) continue;
sum+=sessions[i]->sum(code)/3600.0;//*sessions[i]->hours();
//h+=sessions[i]->hours();
@ -420,6 +448,7 @@ int Day::count(ChannelID code)
{
int sum=0;
for (int i=0;i<sessions.size();i++) {
if (!sessions[i]->enabled()) continue;
sum+=sessions[i]->count(code);
}
return sum;
@ -427,6 +456,7 @@ int Day::count(ChannelID code)
bool Day::settingExists(ChannelID id)
{
for (int j=0;j<sessions.size();j++) {
if (!sessions[j]->enabled()) continue;
QHash<ChannelID,QVariant>::iterator i=sessions[j]->settings.find(id);
if (i!=sessions[j]->settings.end()) {
return true;
@ -450,6 +480,8 @@ bool Day::channelExists(ChannelID id)
{
bool r=false;
for (int i=0;i<sessions.size();i++) {
if (!sessions[i]->enabled()) continue;
if (sessions[i]->eventlist.contains(id)) {
r=true;
break;
@ -464,6 +496,8 @@ bool Day::channelHasData(ChannelID id)
{
bool r=false;
for (int i=0;i<sessions.size();i++) {
if (!sessions[i]->enabled()) continue;
if (sessions[i]->channelExists(id)) {
r=true;
break;

View File

@ -758,6 +758,8 @@ EventDataType Profile::calcPercentile(ChannelID code, EventDataType percent, Mac
if (day) {
for (int i=0;i<day->size();i++) {
for (QVector<Session *>::iterator s=day->begin();s!=day->end();s++) {
if (!(*s)->enabled()) continue;
Session *sess=*s;
gain=sess->m_gain[code];
if (!gain) gain=1;

View File

@ -35,6 +35,7 @@ Session::Session(Machine * m,SessionID session)
s_changed=false;
s_events_loaded=false;
_first_session=true;
s_enabled=-1;
s_first=s_last=0;
s_eventfile="";
@ -649,6 +650,25 @@ bool Session::SearchEvent(ChannelID code, qint64 time, qint64 dist)
return false;
}
bool Session::enabled()
{
if (s_enabled>=0) {
return s_enabled;
}
if (!settings.contains(SESSION_ENABLED)) {
settings[SESSION_ENABLED]=s_enabled=true;
return true;
}
s_enabled=settings[SESSION_ENABLED].toBool();
return s_enabled;
}
void Session::setEnabled(bool b)
{
settings[SESSION_ENABLED]=s_enabled=b;
SetChanged(true);
}
EventDataType Session::Min(ChannelID id)
{
@ -762,6 +782,7 @@ qint64 Session::last(ChannelID id)
}
bool Session::channelExists(ChannelID id)
{
if (!enabled()) return false;
if (s_events_loaded) {
QHash<ChannelID,QVector<EventList *> >::iterator j=eventlist.find(id);
if (j==eventlist.end()) // eventlist not loaded.

View File

@ -64,6 +64,12 @@ public:
return s_session;
}
//! \brief Returns whether or not session is being used.
bool enabled();
//! \brief Sets whether or not session is being used.
void setEnabled(bool b);
//! \brief Return the start of this sessions time range (in milliseconds since epoch)
qint64 first() {
return s_first;
@ -245,6 +251,7 @@ protected:
bool _first_session;
bool s_events_loaded;
char s_enabled;
QString s_eventfile;
};

View File

@ -350,20 +350,30 @@ void Daily::Link_clicked(const QUrl &url)
QString data=url.toString().section("=",1);
int sid=data.toInt();
Day *day=NULL;
if (code=="togglecpapsession") {
if (code=="togglecpapsession") { // Enable/Disable CPAP session
day=PROFILE.GetDay(previous_date,MT_CPAP);
Session *sess=day->find(sid);
if (!sess)
return;
bool b;
if (sess->settings.contains(SESSION_ENABLED)) b=false;
else b=!sess->settings[SESSION_ENABLED].toBool();
sess->settings[SESSION_ENABLED]=b;
sess->SetChanged(true);
day->machine->Save();
GraphView->ResetBounds();
sess->setEnabled(!sess->enabled());
// reload day
// Messy, this rewrites both summary & events.. TODO: Write just the session summary file
day->machine->Save();
// Reload day
this->LoadDate(previous_date);
return;
} else if (code=="toggleoxisession") { // Enable/Disable Oximetry session
day=PROFILE.GetDay(previous_date,MT_OXIMETER);
Session *sess=day->find(sid);
if (!sess)
return;
sess->setEnabled(!sess->enabled());
// Messy, this rewrites both summary & events.. TODO: Write just the session summary file
day->machine->Save();
// Reload day
this->LoadDate(previous_date);
return;
} else if (code=="cpap") {
day=PROFILE.GetDay(previous_date,MT_CPAP);
@ -438,6 +448,7 @@ void Daily::UpdateEventsTree(QTreeWidget *tree,Day *day)
QHash<ChannelID,int> mccnt;
int total_events=0;
for (QVector<Session *>::iterator s=day->begin();s!=day->end();s++) {
if (!(*s)->enabled()) continue;
QHash<ChannelID,QVector<EventList *> >::iterator m;