mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-06 03:00:43 +00:00
Fix to Machine::AddSession() day selection
This commit is contained in:
parent
1a1b6434a5
commit
e4be1f16fc
@ -211,7 +211,7 @@ Machine::Machine(Profile *p,MachineID id)
|
|||||||
Machine::~Machine()
|
Machine::~Machine()
|
||||||
{
|
{
|
||||||
qDebug() << "Destroy Machine";
|
qDebug() << "Destroy Machine";
|
||||||
map<qint64,Day *>::iterator d;
|
map<QDate,Day *>::iterator d;
|
||||||
for (d=day.begin();d!=day.end();d++) {
|
for (d=day.begin();d!=day.end();d++) {
|
||||||
delete d->second;
|
delete d->second;
|
||||||
}
|
}
|
||||||
@ -233,9 +233,14 @@ 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();
|
||||||
|
|
||||||
qint64 date=s->first()/86400000;
|
QDateTime d1,d2=QDateTime::fromMSecsSinceEpoch(s->first());
|
||||||
date--; //=date.addDays(-1);
|
|
||||||
date*=86400000;
|
QDate date=d2.date();
|
||||||
|
date.addDays(-1);
|
||||||
|
|
||||||
|
//qint64 date=s->first()/86400000;
|
||||||
|
//date--; //=date.addDays(-1);
|
||||||
|
//date*=86400000;
|
||||||
|
|
||||||
const int hours_since_last_session=4;
|
const int hours_since_last_session=4;
|
||||||
const int hours_since_midnight=12;
|
const int hours_since_midnight=12;
|
||||||
@ -251,16 +256,15 @@ Day *Machine::AddSession(Session *s,Profile *p)
|
|||||||
// 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) {
|
||||||
previous=true;
|
previous=true;
|
||||||
} else {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!previous) {
|
if (!previous) {
|
||||||
// Calculate Hours since midnight.
|
// Calculate Hours since midnight.
|
||||||
qint64 t=s->first()/86400000;
|
d1=d2;
|
||||||
t*=86400000;
|
d1.setTime(QTime(0,0,0));
|
||||||
//t.setTime(QTime(0,0));
|
float secsto=d1.secsTo(d2);
|
||||||
span=(s->first() - t)/3600000.0;
|
span=secsto/3600.0;
|
||||||
|
|
||||||
// Bedtime was late last night.
|
// Bedtime was late last night.
|
||||||
if (span < hours_since_midnight) {
|
if (span < hours_since_midnight) {
|
||||||
@ -271,7 +275,7 @@ Day *Machine::AddSession(Session *s,Profile *p)
|
|||||||
|
|
||||||
if (!previous) {
|
if (!previous) {
|
||||||
// Revert to sessions original day.
|
// Revert to sessions original day.
|
||||||
date+=86400000;
|
date=date.addDays(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionlist[s->session()]=s;
|
sessionlist[s->session()]=s;
|
||||||
@ -288,9 +292,9 @@ Day *Machine::AddSession(Session *s,Profile *p)
|
|||||||
//qDebug("Adding Profile Day %s",dstr.toAscii().data());
|
//qDebug("Adding Profile Day %s",dstr.toAscii().data());
|
||||||
day[date]=new Day(this);
|
day[date]=new Day(this);
|
||||||
// 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(d.date(),day[date],m_type);
|
p->AddDay(date,day[date],m_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
day[date]->AddSession(s);
|
day[date]->AddSession(s);
|
||||||
@ -407,7 +411,7 @@ bool Machine::SaveSession(Session *sess)
|
|||||||
}
|
}
|
||||||
bool Machine::Save()
|
bool Machine::Save()
|
||||||
{
|
{
|
||||||
map<qint64,Day *>::iterator d;
|
map<QDate,Day *>::iterator d;
|
||||||
vector<Session *>::iterator s;
|
vector<Session *>::iterator s;
|
||||||
int size=0;
|
int size=0;
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
|
@ -43,7 +43,7 @@ public:
|
|||||||
bool SaveSession(Session *sess);
|
bool SaveSession(Session *sess);
|
||||||
bool Purge(int secret);
|
bool Purge(int secret);
|
||||||
|
|
||||||
map<qint64,Day *> day;
|
map<QDate,Day *> day;
|
||||||
map<SessionID,Session *> sessionlist;
|
map<SessionID,Session *> sessionlist;
|
||||||
map<QString,QString> properties;
|
map<QString,QString> properties;
|
||||||
|
|
||||||
@ -69,11 +69,11 @@ public:
|
|||||||
};
|
};
|
||||||
SessionID CreateSessionID() { return highest_sessionid+1; };
|
SessionID CreateSessionID() { return highest_sessionid+1; };
|
||||||
const MachineID & id() { return m_id; };
|
const MachineID & id() { return m_id; };
|
||||||
const qint64 & FirstDay() { return firstday; };
|
const QDate & FirstDay() { return firstday; };
|
||||||
const qint64 & LastDay() { return lastday; };
|
const QDate & LastDay() { return lastday; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
qint64 firstday,lastday;
|
QDate firstday,lastday;
|
||||||
SessionID highest_sessionid;
|
SessionID highest_sessionid;
|
||||||
MachineID m_id;
|
MachineID m_id;
|
||||||
QString m_class;
|
QString m_class;
|
||||||
|
Loading…
Reference in New Issue
Block a user