QHash's aren't ordered.. Use QMap's instead while loading sessions

This commit is contained in:
Mark Watkins 2011-08-01 18:22:37 +10:00
parent a2ea26a9a0
commit 495e791976
3 changed files with 32 additions and 17 deletions

View File

@ -240,7 +240,7 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile)
SessionID session; SessionID session;
long ext; long ext;
typedef QVector<QString> StringList; typedef QVector<QString> StringList;
QHash<SessionID,StringList> sessfiles; QMap<SessionID,StringList> sessfiles;
int size=paths.size(); int size=paths.size();
int cnt=0; int cnt=0;
bool ok; bool ok;
@ -281,7 +281,7 @@ int PRS1Loader::OpenMachine(Machine *m,QString path,Profile *profile)
return 0; return 0;
cnt=0; cnt=0;
for (QHash<SessionID,StringList>::iterator s=sessfiles.begin(); s!=sessfiles.end(); s++) { for (QMap<SessionID,StringList>::iterator s=sessfiles.begin(); s!=sessfiles.end(); s++) {
session=s.key(); session=s.key();
cnt++; cnt++;
if (qprogress) qprogress->setValue(33.0+(float(cnt)/float(size)*33.0)); if (qprogress) qprogress->setValue(33.0+(float(cnt)/float(size)*33.0));

View File

@ -266,7 +266,7 @@ int ResmedLoader::Open(QString & path,Profile *profile)
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Name); dir.setSorting(QDir::Name);
QFileInfoList flist=dir.entryInfoList(); QFileInfoList flist=dir.entryInfoList();
QHash<SessionID,QVector<QString> > sessfiles; QMap<SessionID,QVector<QString> > sessfiles;
QString ext,rest,datestr,s,codestr; QString ext,rest,datestr,s,codestr;
SessionID sessionid; SessionID sessionid;
@ -285,8 +285,10 @@ int ResmedLoader::Open(QString & path,Profile *profile)
sessionid=date.toTime_t(); sessionid=date.toTime_t();
// Resmed bugs up on the session filenames.. 1 second either way // Resmed bugs up on the session filenames.. 1 second either way
if (sessfiles.find(sessionid)==sessfiles.end()) { if (sessfiles.find(sessionid)==sessfiles.end()) {
if (sessfiles.find(sessionid+1)!=sessfiles.end()) sessionid++; if (sessfiles.find(sessionid+2)!=sessfiles.end()) sessionid+=2;
if (sessfiles.find(sessionid-1)!=sessfiles.end()) sessionid--; else if (sessfiles.find(sessionid+1)!=sessfiles.end()) sessionid++;
else if (sessfiles.find(sessionid-1)!=sessfiles.end()) sessionid--;
else if (sessfiles.find(sessionid-2)!=sessfiles.end()) sessionid-=2;
} }
sessfiles[sessionid].push_back(fi.canonicalFilePath()); sessfiles[sessionid].push_back(fi.canonicalFilePath());
@ -301,7 +303,7 @@ int ResmedLoader::Open(QString & path,Profile *profile)
Session *sess; Session *sess;
int cnt=0; int cnt=0;
size=sessfiles.size(); size=sessfiles.size();
for (QHash<SessionID,QVector<QString> >::iterator si=sessfiles.begin();si!=sessfiles.end();si++) { for (QMap<SessionID,QVector<QString> >::iterator si=sessfiles.begin();si!=sessfiles.end();si++) {
sessionid=si.key(); sessionid=si.key();
//qDebug() << "Parsing Session " << sessionid; //qDebug() << "Parsing Session " << sessionid;
bool done=false; bool done=false;

View File

@ -346,12 +346,18 @@ Day *Machine::AddSession(Session *s,Profile *p)
if (s->session()>highest_sessionid) if (s->session()>highest_sessionid)
highest_sessionid=s->session(); highest_sessionid=s->session();
QDateTime d1,d2=QDateTime::fromMSecsSinceEpoch(s->first()); QDateTime d1,d2=QDateTime::fromMSecsSinceEpoch(s->first());
QDate date=d2.date(); QDate date=d2.date();
//QTime time=d2.time(); QTime time=d2.time();
if (pref.Exists("NoonDataSplit") && pref["NoonDateSplit"].toBool()) { if (s->session()==1311991200) {
int q=03;
}
QMap<QDate,Day *>::iterator dit;
if (pref.Exists("NoonDateSplit") && pref["NoonDateSplit"].toBool()) {
int hour=d2.time().hour(); int hour=d2.time().hour();
if (hour<12) if (hour<12)
date=date.addDays(-1); date=date.addDays(-1);
@ -364,11 +370,12 @@ Day *Machine::AddSession(Session *s,Profile *p)
bool previous=false; bool previous=false;
// Find what day session belongs to. // Find what day session belongs to.
if (day.find(date)!=day.end()) { dit=day.find(date);
if (dit!=day.end()) {
// Previous day record exists... // Previous day record exists...
// Calculate time since end of previous days last session // Calculate time since end of previous days last session
span=(s->first() - day[date]->last())/3600000.0; span=(s->first() - (*dit)->last())/3600000.0;
// less than n hours since last session yesterday? // less than n hours since last session yesterday?
if (span < hours_since_last_session) { if (span < hours_since_last_session) {
@ -405,18 +412,24 @@ Day *Machine::AddSession(Session *s,Profile *p)
firstsession=false; firstsession=false;
} }
if (day.find(date)==day.end()) {
Day *dd=NULL;
dit=day.find(date);
if (dit==day.end()) {
//QString dstr=date.toString("yyyyMMdd"); //QString dstr=date.toString("yyyyMMdd");
//qDebug("Adding Profile Day %s",dstr.toAscii().data()); //qDebug("Adding Profile Day %s",dstr.toAscii().data());
day[date]=new Day(this); dd=new Day(this);
day[date]=dd;
// Add this Day record to profile // Add this Day record to profile
//QDateTime d=QDateTime::fromMSecsSinceEpoch(date); //QDateTime d=QDateTime::fromMSecsSinceEpoch(date);
//qDebug() << "New day: " << d.toString("yyyy-MM-dd HH:mm:ss"); //qDebug() << "New day: " << d.toString("yyyy-MM-dd HH:mm:ss");
p->AddDay(date,day[date],m_type); p->AddDay(date,dd,m_type);
} else {
dd=*dit;
} }
day[date]->AddSession(s); dd->AddSession(s);
return day[date]; return dd;
} }
// This functions purpose is murder and mayhem... It deletes all of a machines data. // This functions purpose is murder and mayhem... It deletes all of a machines data.
@ -481,8 +494,8 @@ bool Machine::Load()
QFileInfoList list=dir.entryInfoList(); QFileInfoList list=dir.entryInfoList();
typedef QVector<QString> StringList; typedef QVector<QString> StringList;
QHash<SessionID,StringList> sessfiles; QMap<SessionID,StringList> sessfiles;
QHash<SessionID,StringList>::iterator s; QMap<SessionID,StringList>::iterator s;
QString fullpath,ext_s,sesstr; QString fullpath,ext_s,sesstr;
int ext; int ext;