2011-09-02 05:13:07 +00:00
|
|
|
/*
|
2011-06-26 08:30:44 +00:00
|
|
|
SleepLib Day Class Implementation
|
|
|
|
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
|
|
|
|
License: GPL
|
2011-09-02 05:13:07 +00:00
|
|
|
*/
|
2011-06-26 08:30:44 +00:00
|
|
|
|
|
|
|
#include "day.h"
|
2011-11-28 04:05:09 +00:00
|
|
|
#include "profiles.h"
|
2012-01-05 04:37:22 +00:00
|
|
|
#include <cmath>
|
2012-01-01 15:47:21 +00:00
|
|
|
#include <algorithm>
|
2011-06-26 08:30:44 +00:00
|
|
|
|
|
|
|
Day::Day(Machine *m)
|
|
|
|
:machine(m)
|
|
|
|
{
|
|
|
|
d_firstsession=true;
|
|
|
|
}
|
|
|
|
Day::~Day()
|
|
|
|
{
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
|
|
|
delete (*s);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
MachineType Day::machine_type()
|
|
|
|
{
|
|
|
|
return machine->GetType();
|
2011-11-21 10:20:11 +00:00
|
|
|
}
|
2011-12-27 13:21:10 +00:00
|
|
|
Session *Day::find(SessionID sessid) {
|
|
|
|
for (int i=0;i<size();i++) {
|
|
|
|
if (sessions[i]->session()==sessid)
|
|
|
|
return sessions[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-26 08:30:44 +00:00
|
|
|
|
|
|
|
void Day::AddSession(Session *s)
|
|
|
|
{
|
|
|
|
if (!s) {
|
|
|
|
qWarning("Day::AddSession called with NULL session object");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (d_firstsession) {
|
|
|
|
d_firstsession=false;
|
|
|
|
d_first=s->first();
|
|
|
|
d_last=s->last();
|
|
|
|
} else {
|
|
|
|
if (d_first > s->first()) d_first = s->first();
|
|
|
|
if (d_last < s->last()) d_last = s->last();
|
|
|
|
}
|
|
|
|
sessions.push_back(s);
|
|
|
|
}
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::settings_sum(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
|
|
|
EventDataType val=0;
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-07-31 20:24:43 +00:00
|
|
|
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
|
|
|
|
if (i!=sess.settings.end()) {
|
|
|
|
val+=i.value().toDouble();
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::settings_max(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
|
|
|
EventDataType val=0,tmp;
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-07-31 20:24:43 +00:00
|
|
|
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
|
|
|
|
if (i!=sess.settings.end()) {
|
|
|
|
tmp=i.value().toDouble();
|
2011-06-26 08:30:44 +00:00
|
|
|
if (tmp>val) val=tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::settings_min(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
|
|
|
EventDataType val=0,tmp;
|
|
|
|
bool fir=true;
|
|
|
|
// Cache this?
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-07-31 20:24:43 +00:00
|
|
|
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
|
|
|
|
if (i!=sess.settings.end()) {
|
|
|
|
tmp=i.value().toDouble();
|
2011-06-26 08:30:44 +00:00
|
|
|
if (fir) {
|
|
|
|
val=tmp;
|
|
|
|
fir=false;
|
|
|
|
} else {
|
|
|
|
if (val<tmp) val=tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::settings_avg(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType val=0;
|
2011-06-26 08:30:44 +00:00
|
|
|
|
|
|
|
int cnt=0;
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-07-31 20:24:43 +00:00
|
|
|
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
|
|
|
|
if (i!=sess.settings.end()) {
|
|
|
|
val+=i.value().toDouble();
|
2011-06-26 08:30:44 +00:00
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
2011-07-31 20:24:43 +00:00
|
|
|
val/=EventDataType(cnt);
|
2011-06-26 08:30:44 +00:00
|
|
|
return val;
|
|
|
|
}
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::settings_wavg(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
2011-12-26 18:26:06 +00:00
|
|
|
double s0=0,s1=0,s2=0,tmp;
|
2011-07-31 20:24:43 +00:00
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-09-10 06:29:58 +00:00
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
QHash<ChannelID,QVariant>::iterator i=sess.settings.find(code);
|
|
|
|
if (i!=sess.settings.end()) {
|
2011-06-26 08:30:44 +00:00
|
|
|
s0=sess.hours();
|
2011-12-26 18:26:06 +00:00
|
|
|
tmp=i.value().toDouble();
|
|
|
|
s1+=tmp*s0;
|
2011-06-26 08:30:44 +00:00
|
|
|
s2+=s0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s2==0) return 0;
|
2011-12-26 18:26:06 +00:00
|
|
|
tmp=(s1/s2);
|
|
|
|
return tmp;
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
2012-01-01 15:47:21 +00:00
|
|
|
|
|
|
|
|
2011-12-11 09:45:28 +00:00
|
|
|
EventDataType Day::percentile(ChannelID code,EventDataType percentile)
|
|
|
|
{
|
2012-01-05 04:37:22 +00:00
|
|
|
// QHash<ChannelID, QHash<EventDataType, EventDataType> >::iterator pi;
|
|
|
|
// pi=perc_cache.find(code);
|
|
|
|
// if (pi!=perc_cache.end()) {
|
|
|
|
// QHash<EventDataType, EventDataType> & hsh=pi.value();
|
|
|
|
// QHash<EventDataType, EventDataType>::iterator hi=hsh.find(
|
|
|
|
// if (hi!=pi.value().end()) {
|
|
|
|
// return hi.value();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Cache this calculation?
|
2011-12-11 09:45:28 +00:00
|
|
|
|
|
|
|
QVector<Session *>::iterator s;
|
|
|
|
|
2012-01-05 12:12:42 +00:00
|
|
|
QHash<EventStoreType, int> wmap;
|
2012-01-05 04:37:22 +00:00
|
|
|
|
|
|
|
int SN=0;
|
|
|
|
|
2012-01-05 12:12:42 +00:00
|
|
|
EventDataType lastgain=0, gain=0;
|
2012-01-05 04:37:22 +00:00
|
|
|
// First Calculate count of all events
|
2011-12-11 09:45:28 +00:00
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-12-11 09:45:28 +00:00
|
|
|
Session & sess=*(*s);
|
2011-12-24 01:22:41 +00:00
|
|
|
QHash<ChannelID,QHash<EventStoreType, EventStoreType> > ::iterator ei=sess.m_valuesummary.find(code);
|
|
|
|
if (ei==sess.m_valuesummary.end()) continue;
|
2012-01-05 04:37:22 +00:00
|
|
|
|
2012-01-05 12:12:42 +00:00
|
|
|
gain=sess.m_gain[code];
|
|
|
|
|
|
|
|
// Here's assuming gains don't change accross a days sessions
|
|
|
|
// Can't assume this in any multi day calculations..
|
|
|
|
if (lastgain>0) {
|
|
|
|
if (gain!=lastgain) {
|
2012-01-09 08:05:20 +00:00
|
|
|
qDebug() << "Gains differ across sessions: " << gain << lastgain;
|
2012-01-05 12:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lastgain=gain;
|
|
|
|
|
|
|
|
int weight,value;
|
|
|
|
QHash<EventStoreType,int>::iterator wit;
|
2011-12-24 01:22:41 +00:00
|
|
|
for (QHash<EventStoreType, EventStoreType>::iterator i=ei.value().begin();i!=ei.value().end();i++) {
|
2012-01-05 04:37:22 +00:00
|
|
|
weight=i.value();
|
2012-01-05 12:12:42 +00:00
|
|
|
value=i.key();
|
2012-01-05 04:37:22 +00:00
|
|
|
|
|
|
|
SN+=weight;
|
2012-01-05 12:12:42 +00:00
|
|
|
|
|
|
|
// Cheating here.. On first access, it initializes to zero
|
|
|
|
wmap[value]+=weight;
|
|
|
|
// wit=wmap.find(value);
|
|
|
|
// if (wit==wmap.end()) {
|
|
|
|
// wmap[value]=weight;
|
|
|
|
// } else {
|
|
|
|
// wit.value()+=weight;
|
|
|
|
// }
|
2011-12-11 09:45:28 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-01 15:47:21 +00:00
|
|
|
|
2012-01-05 04:37:22 +00:00
|
|
|
QVector<ValueCount> valcnt;
|
|
|
|
|
|
|
|
// Build sorted list of value/counts
|
2012-01-05 12:12:42 +00:00
|
|
|
for (QHash<EventStoreType, int>::iterator n=wmap.begin();n!=wmap.end();n++) {
|
2012-01-05 04:37:22 +00:00
|
|
|
ValueCount vc;
|
2012-01-05 12:12:42 +00:00
|
|
|
vc.value=EventDataType(n.key()) * gain;
|
2012-01-05 04:37:22 +00:00
|
|
|
vc.count=n.value();
|
|
|
|
vc.p=0;
|
|
|
|
valcnt.push_back(vc);
|
|
|
|
}
|
|
|
|
// sort by weight, then value
|
|
|
|
qSort(valcnt);
|
|
|
|
|
|
|
|
//double SN=100.0/double(N); // 100% / overall sum
|
|
|
|
double p=100.0*percentile;
|
|
|
|
|
|
|
|
double nth=double(SN)*percentile; // index of the position in the unweighted set would be
|
|
|
|
double nthi=floor(nth);
|
|
|
|
|
|
|
|
int sum1=0,sum2=0;
|
|
|
|
int w1,w2=0;
|
2012-01-05 12:12:42 +00:00
|
|
|
EventDataType v1=0,v2;
|
2012-01-05 04:37:22 +00:00
|
|
|
|
|
|
|
int N=valcnt.size();
|
|
|
|
int k=0;
|
|
|
|
|
|
|
|
for (k=0;k < N;k++) {
|
|
|
|
v1=valcnt[k].value;
|
|
|
|
w1=valcnt[k].count;
|
|
|
|
sum1+=w1;
|
|
|
|
|
|
|
|
if (sum1 > nthi) {
|
|
|
|
return v1;
|
|
|
|
}
|
|
|
|
if (sum1 == nthi){
|
|
|
|
break; // boundary condition
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (k>=N)
|
|
|
|
return v1;
|
|
|
|
|
|
|
|
v2=valcnt[k+1].value;
|
|
|
|
w2=valcnt[k+1].count;
|
|
|
|
sum2=sum1+w2;
|
|
|
|
// value lies between v1 and v2
|
|
|
|
|
|
|
|
double px=100.0/double(SN); // Percentile represented by one full value
|
|
|
|
|
|
|
|
// calculate percentile ranks
|
|
|
|
double p1=px * (double(sum1)-(double(w1)/2.0));
|
|
|
|
double p2=px * (double(sum2)-(double(w2)/2.0));
|
|
|
|
|
|
|
|
// calculate linear interpolation
|
|
|
|
double v=v1 + ((p-p1)/(p2-p1)) * (v2-v1);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
|
|
|
|
// p1.....p.............p2
|
|
|
|
// 37 55 70
|
|
|
|
|
2011-12-11 09:45:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-24 01:22:41 +00:00
|
|
|
EventDataType Day::p90(ChannelID code)
|
2011-07-31 20:24:43 +00:00
|
|
|
{
|
2011-12-24 01:22:41 +00:00
|
|
|
return percentile(code,0.90);
|
2011-07-31 20:24:43 +00:00
|
|
|
}
|
2011-06-26 08:30:44 +00:00
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::avg(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
|
|
|
double val=0;
|
|
|
|
// Cache this?
|
|
|
|
int cnt=0;
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
|
|
|
|
// Don't assume sessions are in order.
|
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-09-10 06:29:58 +00:00
|
|
|
if (sess.m_avg.contains(code)) {
|
2011-07-27 09:21:53 +00:00
|
|
|
val+=sess.avg(code);
|
2011-06-26 08:30:44 +00:00
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cnt==0) return 0;
|
|
|
|
return EventDataType(val/float(cnt));
|
|
|
|
}
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::sum(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
|
|
|
// Cache this?
|
|
|
|
EventDataType val=0;
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
|
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-09-10 06:29:58 +00:00
|
|
|
if (sess.m_sum.contains(code)) {
|
2011-07-27 09:21:53 +00:00
|
|
|
val+=sess.sum(code);
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
EventDataType Day::wavg(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
|
|
|
double s0=0,s1=0,s2=0;
|
2011-08-07 11:37:56 +00:00
|
|
|
qint64 d;
|
2011-07-31 20:24:43 +00:00
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-12-28 12:03:48 +00:00
|
|
|
|
2011-09-08 18:38:07 +00:00
|
|
|
if (sess.m_wavg.contains(code)) {
|
2011-12-10 12:14:48 +00:00
|
|
|
d=sess.length();//.last(code)-sess.first(code);
|
|
|
|
s0=double(d)/3600000.0;
|
2011-08-07 11:37:56 +00:00
|
|
|
if (s0>0) {
|
|
|
|
s1+=sess.wavg(code)*s0;
|
|
|
|
s2+=s0;
|
|
|
|
}
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-08-07 11:37:56 +00:00
|
|
|
if (s2==0)
|
|
|
|
return 0;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
return (s1/s2);
|
|
|
|
}
|
2011-07-03 02:43:50 +00:00
|
|
|
// Total session time in milliseconds
|
2011-07-02 14:35:50 +00:00
|
|
|
qint64 Day::total_time()
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
2011-07-27 09:21:53 +00:00
|
|
|
qint64 d_totaltime=0;
|
2011-09-12 02:24:58 +00:00
|
|
|
for (QVector<Session *>::iterator s=begin();s!=end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-09-12 02:24:58 +00:00
|
|
|
d_totaltime+=sess.length();
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
|
|
|
return d_totaltime;
|
|
|
|
}
|
2011-12-28 14:03:09 +00:00
|
|
|
bool Day::hasEnabledSessions()
|
|
|
|
{
|
|
|
|
bool b=false;
|
|
|
|
for (QVector<Session *>::iterator s=begin();s!=end();s++) {
|
|
|
|
if ((*s)->enabled()) {
|
|
|
|
b=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2011-12-11 09:45:28 +00:00
|
|
|
/*EventDataType Day::percentile(ChannelID code,double percent)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
|
|
|
double val=0;
|
|
|
|
int cnt=0;
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-06-26 08:30:44 +00:00
|
|
|
Session & sess=*(*s);
|
2011-07-27 09:21:53 +00:00
|
|
|
if (sess.eventlist.find(code)!=sess.eventlist.end()) {
|
|
|
|
val+=sess.percentile(code,percent);
|
2011-06-26 08:30:44 +00:00
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cnt==0) return 0;
|
|
|
|
return EventDataType(val/cnt);
|
|
|
|
|
2011-12-11 09:45:28 +00:00
|
|
|
}*/
|
2011-06-26 08:30:44 +00:00
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
qint64 Day::first(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
2011-07-02 14:35:50 +00:00
|
|
|
qint64 date=0;
|
|
|
|
qint64 tmp;
|
2011-06-26 08:30:44 +00:00
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
2011-07-27 09:21:53 +00:00
|
|
|
tmp=(*s)->first(code);
|
|
|
|
if (!tmp) continue;
|
|
|
|
if (!date) {
|
|
|
|
date=tmp;
|
|
|
|
} else {
|
|
|
|
if (tmp<date) date=tmp;
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
qint64 Day::last(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
2011-07-02 14:35:50 +00:00
|
|
|
qint64 date=0;
|
|
|
|
qint64 tmp;
|
2011-06-26 08:30:44 +00:00
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
2011-07-27 09:21:53 +00:00
|
|
|
tmp=(*s)->last(code);
|
|
|
|
if (!tmp) continue;
|
|
|
|
if (!date) {
|
|
|
|
date=tmp;
|
|
|
|
} else {
|
|
|
|
if (tmp>date) date=tmp;
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return date;
|
|
|
|
}
|
2011-12-17 14:38:15 +00:00
|
|
|
EventDataType Day::Min(ChannelID code)
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
2011-07-27 09:21:53 +00:00
|
|
|
EventDataType min=0;
|
|
|
|
EventDataType tmp;
|
|
|
|
bool first=true;
|
2011-07-31 20:24:43 +00:00
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:36:40 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
2011-12-28 12:03:48 +00:00
|
|
|
|
2011-12-28 12:36:40 +00:00
|
|
|
if (!(*s)->m_min.contains(code))
|
2011-12-28 03:17:20 +00:00
|
|
|
continue;
|
2011-12-17 14:38:15 +00:00
|
|
|
tmp=(*s)->Min(code);
|
2011-07-27 09:21:53 +00:00
|
|
|
if (first) {
|
|
|
|
min=tmp;
|
|
|
|
first=false;
|
|
|
|
} else {
|
|
|
|
if (tmp<min) min=tmp;
|
|
|
|
}
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
2011-07-27 09:21:53 +00:00
|
|
|
return min;
|
|
|
|
}
|
2011-06-26 08:30:44 +00:00
|
|
|
|
2011-12-10 12:14:48 +00:00
|
|
|
bool Day::hasData(ChannelID code, SummaryType type)
|
|
|
|
{
|
|
|
|
bool has=false;
|
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
2011-12-10 12:14:48 +00:00
|
|
|
Session *sess=*s;
|
|
|
|
switch(type) {
|
2012-01-03 07:15:02 +00:00
|
|
|
// case ST_90P:
|
|
|
|
// has=sess->m_90p.contains(code);
|
|
|
|
// break;
|
2011-12-24 06:20:07 +00:00
|
|
|
case ST_PERC:
|
|
|
|
has=sess->m_valuesummary.contains(code);
|
|
|
|
break;
|
2011-12-10 12:14:48 +00:00
|
|
|
case ST_MIN:
|
|
|
|
has=sess->m_min.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_MAX:
|
|
|
|
has=sess->m_max.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_CNT:
|
|
|
|
has=sess->m_cnt.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_AVG:
|
|
|
|
has=sess->m_avg.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_WAVG:
|
|
|
|
has=sess->m_wavg.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_CPH:
|
|
|
|
has=sess->m_cph.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_SPH:
|
|
|
|
has=sess->m_sph.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_FIRST:
|
|
|
|
has=sess->m_firstchan.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_LAST:
|
|
|
|
has=sess->m_lastchan.contains(code);
|
|
|
|
break;
|
|
|
|
case ST_SUM:
|
|
|
|
has=sess->m_sum.contains(code);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has) break;
|
|
|
|
}
|
|
|
|
return has;
|
|
|
|
}
|
|
|
|
|
2011-12-17 14:38:15 +00:00
|
|
|
EventDataType Day::Max(ChannelID code)
|
2011-07-27 09:21:53 +00:00
|
|
|
{
|
|
|
|
EventDataType max=0;
|
|
|
|
EventDataType tmp;
|
|
|
|
bool first=true;
|
2011-07-31 20:24:43 +00:00
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
|
2011-09-10 06:29:58 +00:00
|
|
|
if (!(*s)->m_max.contains(code)) continue;
|
|
|
|
// if ((*s)->eventlist.find(code)==(*s)->eventlist.end()) continue;
|
2011-12-17 14:38:15 +00:00
|
|
|
tmp=(*s)->Max(code);
|
2011-07-27 09:21:53 +00:00
|
|
|
if (first) {
|
|
|
|
max=tmp;
|
|
|
|
first=false;
|
|
|
|
} else {
|
|
|
|
if (tmp>max) max=tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return max;
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
2011-09-10 15:43:40 +00:00
|
|
|
EventDataType Day::cph(ChannelID code)
|
|
|
|
{
|
2012-01-03 04:36:47 +00:00
|
|
|
double sum=0;
|
2011-09-17 12:39:00 +00:00
|
|
|
//EventDataType h=0;
|
2011-09-10 15:43:40 +00:00
|
|
|
for (int i=0;i<sessions.size();i++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!sessions[i]->enabled()) continue;
|
2012-01-03 04:36:47 +00:00
|
|
|
if (!sessions[i]->m_cnt.contains(code)) continue;
|
|
|
|
sum+=sessions[i]->count(code);
|
2011-09-10 16:30:25 +00:00
|
|
|
//h+=sessions[i]->hours();
|
2011-09-10 15:43:40 +00:00
|
|
|
}
|
2011-09-12 05:09:53 +00:00
|
|
|
sum/=hours();
|
2011-09-10 15:43:40 +00:00
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventDataType Day::sph(ChannelID code)
|
|
|
|
{
|
|
|
|
EventDataType sum=0;
|
|
|
|
EventDataType h=0;
|
|
|
|
for (int i=0;i<sessions.size();i++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!sessions[i]->enabled()) continue;
|
2011-09-12 05:14:14 +00:00
|
|
|
if (!sessions[i]->m_sum.contains(code)) continue;
|
|
|
|
sum+=sessions[i]->sum(code)/3600.0;//*sessions[i]->hours();
|
2011-09-10 16:30:25 +00:00
|
|
|
//h+=sessions[i]->hours();
|
2011-09-10 15:43:40 +00:00
|
|
|
}
|
2011-09-10 16:30:25 +00:00
|
|
|
h=hours();
|
2011-09-10 15:43:40 +00:00
|
|
|
sum=(100.0/h)*sum;
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2011-07-31 20:24:43 +00:00
|
|
|
int Day::count(ChannelID code)
|
2011-07-27 09:21:53 +00:00
|
|
|
{
|
|
|
|
int sum=0;
|
2011-07-31 20:24:43 +00:00
|
|
|
for (int i=0;i<sessions.size();i++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!sessions[i]->enabled()) continue;
|
2011-07-27 09:21:53 +00:00
|
|
|
sum+=sessions[i]->count(code);
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
2011-09-18 15:43:14 +00:00
|
|
|
bool Day::settingExists(ChannelID id)
|
|
|
|
{
|
|
|
|
for (int j=0;j<sessions.size();j++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!sessions[j]->enabled()) continue;
|
2011-09-18 15:43:14 +00:00
|
|
|
QHash<ChannelID,QVariant>::iterator i=sessions[j]->settings.find(id);
|
|
|
|
if (i!=sessions[j]->settings.end()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-23 10:52:31 +00:00
|
|
|
bool Day::eventsLoaded()
|
|
|
|
{
|
|
|
|
bool r=false;
|
|
|
|
for (int i=0;i<sessions.size();i++) {
|
|
|
|
if (sessions[i]->eventsLoaded()) {
|
|
|
|
r=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-08-07 11:37:56 +00:00
|
|
|
bool Day::channelExists(ChannelID id)
|
|
|
|
{
|
2011-12-10 12:14:48 +00:00
|
|
|
bool r=false;
|
|
|
|
for (int i=0;i<sessions.size();i++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!sessions[i]->enabled()) continue;
|
|
|
|
|
2011-12-10 12:14:48 +00:00
|
|
|
if (sessions[i]->eventlist.contains(id)) {
|
|
|
|
r=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
// return channelHasData(id);
|
2011-12-03 08:52:24 +00:00
|
|
|
//if (machine->hasChannel(id)) return true;
|
|
|
|
//return false;
|
2011-09-17 12:39:00 +00:00
|
|
|
}
|
|
|
|
bool Day::channelHasData(ChannelID id)
|
|
|
|
{
|
2011-10-30 04:35:55 +00:00
|
|
|
bool r=false;
|
2011-09-17 12:39:00 +00:00
|
|
|
for (int i=0;i<sessions.size();i++) {
|
2011-12-28 12:03:48 +00:00
|
|
|
if (!sessions[i]->enabled()) continue;
|
|
|
|
|
2011-10-30 04:35:55 +00:00
|
|
|
if (sessions[i]->channelExists(id)) {
|
|
|
|
r=true;
|
2011-12-10 12:14:48 +00:00
|
|
|
break;
|
2011-09-17 12:39:00 +00:00
|
|
|
}
|
2011-12-30 23:02:45 +00:00
|
|
|
if (sessions[i]->m_valuesummary.contains(id)) {
|
|
|
|
r=true;
|
|
|
|
break;
|
|
|
|
}
|
2011-09-17 12:39:00 +00:00
|
|
|
}
|
2011-10-30 04:35:55 +00:00
|
|
|
return r;
|
2011-08-07 11:37:56 +00:00
|
|
|
}
|
|
|
|
|
2011-07-27 09:21:53 +00:00
|
|
|
void Day::OpenEvents()
|
2011-06-26 08:30:44 +00:00
|
|
|
{
|
2011-07-31 20:24:43 +00:00
|
|
|
QVector<Session *>::iterator s;
|
2011-06-26 08:30:44 +00:00
|
|
|
|
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
2011-07-27 09:21:53 +00:00
|
|
|
(*s)->OpenEvents();
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
2011-12-23 10:52:31 +00:00
|
|
|
}
|
|
|
|
void Day::CloseEvents()
|
|
|
|
{
|
|
|
|
QVector<Session *>::iterator s;
|
2011-07-27 09:21:53 +00:00
|
|
|
|
2011-12-23 10:52:31 +00:00
|
|
|
for (s=sessions.begin();s!=sessions.end();s++) {
|
|
|
|
(*s)->TrashEvents();
|
|
|
|
}
|
2011-06-26 08:30:44 +00:00
|
|
|
}
|
2011-12-28 12:36:40 +00:00
|
|
|
|
|
|
|
qint64 Day::first()
|
|
|
|
{
|
|
|
|
qint64 date=0;
|
|
|
|
qint64 tmp;
|
|
|
|
|
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
tmp=(*s)->first();
|
|
|
|
if (!tmp) continue;
|
|
|
|
if (!date) {
|
|
|
|
date=tmp;
|
|
|
|
} else {
|
|
|
|
if (tmp<date) date=tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return date;
|
|
|
|
// return d_first;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! \brief Returns the last session time of this day
|
|
|
|
qint64 Day::last()
|
|
|
|
{
|
|
|
|
qint64 date=0;
|
|
|
|
qint64 tmp;
|
|
|
|
|
|
|
|
for (QVector<Session *>::iterator s=sessions.begin();s!=sessions.end();s++) {
|
|
|
|
if (!(*s)->enabled()) continue;
|
|
|
|
tmp=(*s)->last();
|
|
|
|
if (!tmp) continue;
|
|
|
|
if (!date) {
|
|
|
|
date=tmp;
|
|
|
|
} else {
|
|
|
|
if (tmp>date) date=tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return date;
|
|
|
|
// return d_last;
|
|
|
|
}
|