63
92
mDayStatistics.clear();
93
mWeekStatistics.clear();
64
94
mMonthStatistics.clear();
65
95
mYearStatistics.clear();
97
if ( mInterface->getSettings().customBilling )
101
void InterfaceStatistics::loadStatsGroup( const KCalendarSystem * cal, const QDomElement& parentItem,
102
enum GroupType group, QList<StatisticEntry *>& statistics )
109
groupName = group_days;
112
groupName = group_weeks;
115
groupName = group_months;
119
groupName = group_years;
123
QDomNode n = parentItem.namedItem( groupName );
126
QDomNode node = n.firstChild();
127
while ( !node.isNull() )
129
QDomElement element = node.toElement();
130
if ( !element.isNull() )
132
StatisticEntry* entry = new StatisticEntry();
133
entry->rxBytes = element.attribute( attrib_rx ).toULongLong();
134
entry->txBytes = element.attribute( attrib_tx ).toULongLong();
136
// The following attributes are particular to each statistic category
141
cal->setDate( entry->date,
142
element.attribute( attrib_year ).toInt(),
143
element.attribute( attrib_month ).toInt(),
144
element.attribute( attrib_day ).toInt() );
149
cal->setDate( entry->date,
150
element.attribute( attrib_year ).toInt(),
151
element.attribute( attrib_month ).toInt(),
152
element.attribute( attrib_day ).toInt() );
154
// If calendar has changed then this will be recalculated elsewhere
155
entry->span = element.attribute( attrib_span ).toInt();
158
if ( element.hasAttribute( attrib_day ) )
159
day = element.attribute( attrib_day ).toInt();
161
cal->setDate( entry->date,
162
element.attribute( attrib_year ).toInt(),
163
element.attribute( attrib_month ).toInt(),
166
entry->span = element.attribute( attrib_span ).toInt();
167
// Old format had no span, so daysInMonth using gregorian
168
if ( entry->span == 0 )
169
entry->span = entry->date.daysInMonth();
170
if ( cal->day( entry->date ) != 1 ||
171
entry->span != cal->daysInMonth( entry->date ) )
175
cal->setDate( entry->date,
176
element.attribute( attrib_year ).toInt(),
180
entry->span = element.attribute( attrib_span ).toInt();
181
// Old format had no span, so daysInYear using gregorian
182
if ( entry->span == 0 )
183
entry->span = entry->date.daysInYear();
186
if ( entry->date.isValid() )
187
statistics.append( entry );
191
node = node.nextSibling();
193
qSort( statistics.begin(), statistics.end(), statisticsLessThan );
68
197
void InterfaceStatistics::loadStatistics()
70
QDomDocument doc( "statistics" );
199
QDomDocument doc( doc_name );
71
200
KUrl dir( mInterface->getGeneralData().statisticsDir );
72
201
if ( !dir.isLocalFile() )
74
QFile file( dir.path() + "/statistics_" + mInterface->getName() );
203
QFile file( dir.path() + statistics_prefix + mInterface->getName() );
76
205
if ( !file.open( QIODevice::ReadOnly ) )
85
214
mDayStatistics.clear();
215
mWeekStatistics.clear();
86
216
mMonthStatistics.clear();
87
217
mYearStatistics.clear();
89
219
QDomElement root = doc.documentElement();
90
QDomNode n = root.namedItem( "days" );
93
QDomNode dayNode = n.firstChild();
94
while ( !dayNode.isNull() )
96
QDomElement day = dayNode.toElement();
99
StatisticEntry* entry = new StatisticEntry();
100
entry->day = day.attribute( "day" ).toInt();
101
entry->month = day.attribute( "month" ).toInt();
102
entry->year = day.attribute( "year" ).toInt();
103
entry->rxBytes = (quint64) day.attribute( "rxBytes" ).toDouble();
104
entry->txBytes = (quint64) day.attribute( "txBytes" ).toDouble();
105
mDayStatistics.append( entry );
107
dayNode = dayNode.nextSibling();
109
qSort( mDayStatistics.begin(), mDayStatistics.end(), statisticsLessThan );
112
n = root.namedItem( "months" );
115
QDomNode monthNode = n.firstChild();
116
while ( !monthNode.isNull() )
118
QDomElement month = monthNode.toElement();
119
if ( !month.isNull() )
121
StatisticEntry* entry = new StatisticEntry();
123
entry->month = month.attribute( "month" ).toInt();
124
entry->year = month.attribute( "year" ).toInt();
125
entry->rxBytes = (quint64) month.attribute( "rxBytes" ).toDouble();
126
entry->txBytes = (quint64) month.attribute( "txBytes" ).toDouble();
127
mMonthStatistics.append( entry );
129
monthNode = monthNode.nextSibling();
131
qSort( mMonthStatistics.begin(), mMonthStatistics.end(), statisticsLessThan );
134
n = root.namedItem( "years" );
137
QDomNode yearNode = n.firstChild();
138
while ( !yearNode.isNull() )
140
QDomElement year = yearNode.toElement();
141
if ( !year.isNull() )
143
StatisticEntry* entry = new StatisticEntry();
146
entry->year = year.attribute( "year" ).toInt();
147
entry->rxBytes = (quint64) year.attribute( "rxBytes" ).toDouble();
148
entry->txBytes = (quint64) year.attribute( "txBytes" ).toDouble();
149
mYearStatistics.append( entry );
151
yearNode = yearNode.nextSibling();
153
qSort( mYearStatistics.begin(), mYearStatistics.end(), statisticsLessThan );
221
// If unknown or empty calendar it will default to gregorian
222
KCalendarSystem *inCal = KCalendarSystem::create( root.attribute( attrib_calendar ) );
223
loadStatsGroup( inCal, root, Day, mDayStatistics );
224
loadStatsGroup( inCal, root, Week, mWeekStatistics );
225
loadStatsGroup( inCal, root, Month, mMonthStatistics );
226
loadStatsGroup( inCal, root, Year, mYearStatistics );
228
// Discrepency: rebuild week and year based on calendar type in settings
229
if ( root.attribute( attrib_calendar ).isEmpty() ||
230
inCal->calendarType() != mCalendar->calendarType() )
232
// Let's do a backup before a significant rebuild
233
file.copy( dir.path() + statistics_prefix + mInterface->getName() +
234
QString( "_%1.bak" ).arg( QDateTime::currentDateTime().toString( "yyyy-MM-dd-hhmmss" ) ) );
235
rebuildStats( mDayStatistics.first()->date, Week );
237
if ( inCal->calendarType() != mCalendar->calendarType() )
239
rebuildStats( mDayStatistics.first()->date, Year );
241
if ( mAllMonths == false && mInterface->getSettings().customBilling == false )
243
rebuildStats( mMonthStatistics.first()->date, Month );
247
void InterfaceStatistics::buildStatsGroup( QDomDocument& doc, enum GroupType group,
248
const QList<StatisticEntry *>& statistics )
255
groupName = group_days;
256
elementName = elem_day;
259
groupName = group_weeks;
260
elementName = elem_week;
263
groupName = group_months;
264
elementName = elem_month;
267
groupName = group_years;
268
elementName = elem_year;
270
QDomElement elements = doc.createElement( groupName );
271
foreach( StatisticEntry *entry, statistics )
273
QDomElement element = doc.createElement( elementName );
274
element.setAttribute( attrib_day, mCalendar->day( entry->date ) );
275
element.setAttribute( attrib_month, mCalendar->month( entry->date ) );
276
element.setAttribute( attrib_year, mCalendar->year( entry->date ) );
278
element.setAttribute( attrib_span, entry->span );
279
element.setAttribute( attrib_rx, entry->rxBytes );
280
element.setAttribute( attrib_tx, entry->txBytes );
281
elements.appendChild( element );
283
QDomElement statElement = doc.elementsByTagName( doc_name ).at( 0 ).toElement();
284
statElement.appendChild( elements );
158
287
void InterfaceStatistics::saveStatistics()
160
QDomDocument doc( "statistics" );
161
QDomElement root = doc.createElement( "statistics" );
162
doc.appendChild( root );
164
QDomElement days = doc.createElement( "days" );
165
foreach( StatisticEntry *entry, mDayStatistics )
167
QDomElement day = doc.createElement( "day" );
168
day.setAttribute( "day", entry->day );
169
day.setAttribute( "month", entry->month );
170
day.setAttribute( "year", entry->year );
171
day.setAttribute( "rxBytes", (double) entry->rxBytes );
172
day.setAttribute( "txBytes", (double) entry->txBytes );
173
days.appendChild( day );
175
root.appendChild( days );
177
QDomElement months = doc.createElement( "months" );
178
foreach ( StatisticEntry *entry, mMonthStatistics )
180
QDomElement month = doc.createElement( "month" );
181
month.setAttribute( "month", entry->month );
182
month.setAttribute( "year", entry->year );
183
month.setAttribute( "rxBytes", (double) entry->rxBytes );
184
month.setAttribute( "txBytes", (double) entry->txBytes );
185
months.appendChild( month );
187
root.appendChild( months );
189
QDomElement years = doc.createElement( "years" );
190
foreach ( StatisticEntry *entry, mYearStatistics )
192
QDomElement year = doc.createElement( "year" );
193
year.setAttribute( "year", entry->year );
194
year.setAttribute( "rxBytes", (double) entry->rxBytes );
195
year.setAttribute( "txBytes", (double) entry->txBytes );
196
years.appendChild( year );
198
root.appendChild( years );
289
QDomDocument doc( doc_name );
290
QDomElement docElement = doc.createElement( doc_name );
291
docElement.setAttribute( attrib_calendar, mCalendar->calendarType() );
292
docElement.setAttribute( attrib_version, "1.1" );
293
doc.appendChild( docElement );
295
buildStatsGroup( doc, Day, mDayStatistics );
296
buildStatsGroup( doc, Week, mWeekStatistics );
297
buildStatsGroup( doc, Month, mMonthStatistics );
298
buildStatsGroup( doc, Year, mYearStatistics );
200
300
KUrl dir( mInterface->getGeneralData().statisticsDir );
201
301
if ( !dir.isLocalFile() )
203
QFile file( dir.path() + "/statistics_" + mInterface->getName() );
303
QFile file( dir.path() + statistics_prefix + mInterface->getName() );
204
304
if ( !file.open( QIODevice::WriteOnly ) )
212
312
void InterfaceStatistics::configChanged()
214
314
// restart the timer with the new value
215
mSaveTimer->setInterval( mInterface->getGeneralData().saveInterval * 1000 );
218
const StatisticEntry* InterfaceStatistics::getCurrentDay() const
223
const StatisticEntry* InterfaceStatistics::getCurrentMonth() const
225
return mCurrentMonth;
228
const StatisticEntry* InterfaceStatistics::getCurrentYear() const
233
const QList<StatisticEntry *>& InterfaceStatistics::getDayStatistics() const
235
return mDayStatistics;
238
const QList<StatisticEntry *>& InterfaceStatistics::getMonthStatistics() const
240
return mMonthStatistics;
243
const QList<StatisticEntry *>& InterfaceStatistics::getYearStatistics() const
245
return mYearStatistics;
316
if ( mInterface->getGeneralData().saveInterval > 0 )
317
mSaveTimer->setInterval( mInterface->getGeneralData().saveInterval * 1000 );
319
mWarningDone = false;
320
// force a new ref day for billing periods
321
mBillingStart = mInterface->getSettings().billingStart;
322
if ( mAllMonths == false && mInterface->getSettings().customBilling == false )
323
mBillingStart = mMonthStatistics.first()->date.addDays( 1 - mCalendar->day( mMonthStatistics.first()->date ) );
324
rebuildStats( mBillingStart, Month );
327
foreach ( StatisticEntry *entry, mMonthStatistics )
329
if ( mCalendar->day( entry->date ) != 1 ||
330
entry->span != mCalendar->daysInMonth( entry->date ) )
333
emit monthStatisticsChanged( true );
248
336
void InterfaceStatistics::addIncomingData( unsigned long data )
250
341
checkCurrentEntry();
252
343
mCurrentDay->rxBytes += data;
344
mCurrentWeek->rxBytes += data;
253
345
mCurrentMonth->rxBytes += data;
254
346
mCurrentYear->rxBytes += data;
348
// Only warn once per interface per session
349
if ( !mWarningDone && mInterface->getSettings().warnThreshold > 0.0 )
351
quint64 thresholdBytes = mInterface->getSettings().warnThreshold * 1073741824;
352
if ( mInterface->getSettings().warnTotalTraffic )
354
if ( mCurrentMonth->rxBytes + mCurrentMonth->txBytes >= thresholdBytes )
357
emit warnMonthlyTraffic( mCurrentMonth->rxBytes + mCurrentMonth->txBytes );
360
else if ( mCurrentMonth->rxBytes >= thresholdBytes )
363
emit warnMonthlyTraffic( mCurrentMonth->rxBytes );
256
366
emit currentEntryChanged();
259
369
void InterfaceStatistics::addOutgoingData( unsigned long data )
261
374
checkCurrentEntry();
263
376
mCurrentDay->txBytes += data;
377
mCurrentWeek->txBytes += data;
264
378
mCurrentMonth->txBytes += data;
265
379
mCurrentYear->txBytes += data;
267
381
emit currentEntryChanged();
270
void InterfaceStatistics::clearDayStatistics()
384
void InterfaceStatistics::clearStatistics()
386
QDate currentDate = QDate::currentDate();
272
388
mDayStatistics.clear();
276
void InterfaceStatistics::clearMonthStatistics()
389
mWeekStatistics.clear();
278
390
mMonthStatistics.clear();
279
updateCurrentMonth();
282
void InterfaceStatistics::clearYearStatistics()
284
391
mYearStatistics.clear();
392
updateCurrentDay( currentDate );
393
updateCurrentWeek( currentDate );
394
updateCurrentMonth( currentDate );
395
updateCurrentYear( currentDate );
288
398
void InterfaceStatistics::checkCurrentEntry()
290
if ( mCurrentDay->day != QDate::currentDate().day() ||
291
mCurrentDay->month != QDate::currentDate().month() ||
292
mCurrentDay->year != QDate::currentDate().year() )
400
QDate currentDate = QDate::currentDate();
402
if ( mCurrentDay->date != currentDate )
294
// current day has changed
297
if ( mCurrentMonth->month != QDate::currentDate().month() ||
298
mCurrentMonth->year != QDate::currentDate().year() )
300
// current month has also changed
301
updateCurrentMonth();
304
if ( mCurrentYear->year != QDate::currentDate().year() )
306
// current year has also changed
404
updateCurrentDay( currentDate );
406
if ( mCalendar->weekNumber( mCurrentWeek->date ) != mCalendar->weekNumber( currentDate ) ||
407
mCurrentWeek->date.addDays( mCalendar->daysInWeek( mCurrentWeek->date ) ) <= currentDate )
408
updateCurrentWeek( currentDate );
410
if ( mCurrentMonth->date.addDays( mCurrentMonth->span ) <= currentDate )
411
updateCurrentMonth( currentDate );
413
if ( mCalendar->year( mCurrentYear->date ) != mCalendar->year( currentDate ) )
414
updateCurrentYear( currentDate );
312
418
void InterfaceStatistics::initStatistics()
315
updateCurrentMonth();
420
QDate currentDate = QDate::currentDate();
422
updateCurrentDay( currentDate );
423
updateCurrentWeek( currentDate );
424
updateCurrentMonth( currentDate );
425
updateCurrentYear( currentDate );
318
427
emit currentEntryChanged();
321
void InterfaceStatistics::updateCurrentDay()
430
void InterfaceStatistics::updateCurrentDay( const QDate ¤tDate )
323
432
foreach ( mCurrentDay, mDayStatistics )
325
if ( mCurrentDay->day == QDate::currentDate().day() &&
326
mCurrentDay->month == QDate::currentDate().month() &&
327
mCurrentDay->year == QDate::currentDate().year() )
329
// found current day in list
434
if ( mCurrentDay->date == currentDate )
334
// the current day is not in the list
335
438
mCurrentDay = new StatisticEntry();
336
mCurrentDay->day = QDate::currentDate().day();
337
mCurrentDay->month = QDate::currentDate().month();
338
mCurrentDay->year = QDate::currentDate().year();
339
mCurrentDay->rxBytes = 0;
340
mCurrentDay->txBytes = 0;
341
mDayStatistics.append( mCurrentDay ); // TODO: insert at correct position
439
mCurrentDay->date = currentDate;
440
mDayStatistics.append( mCurrentDay );
342
441
emit dayStatisticsChanged();
345
void InterfaceStatistics::updateCurrentMonth()
347
foreach ( mCurrentMonth, mMonthStatistics )
349
if ( mCurrentMonth->month == QDate::currentDate().month() &&
350
mCurrentMonth->year == QDate::currentDate().year() )
352
// found current month in list
357
// the current month is not in the list
358
mCurrentMonth = new StatisticEntry();
359
mCurrentMonth->day = 0;
360
mCurrentMonth->month = QDate::currentDate().month();
361
mCurrentMonth->year = QDate::currentDate().year();
362
mCurrentMonth->rxBytes = 0;
363
mCurrentMonth->txBytes = 0;
364
mMonthStatistics.append( mCurrentMonth ); // TODO: insert at correct position
365
emit monthStatisticsChanged();
368
void InterfaceStatistics::updateCurrentYear()
370
foreach ( mCurrentYear, mYearStatistics )
372
if ( mCurrentYear->year == QDate::currentDate().year() )
374
// found current year in list
379
// the current year is not in the list
380
mCurrentYear = new StatisticEntry();
381
mCurrentYear->day = 0;
382
mCurrentYear->month = 0;
383
mCurrentYear->year = QDate::currentDate().year();
384
mCurrentYear->rxBytes = 0;
385
mCurrentYear->txBytes = 0;
386
mYearStatistics.append( mCurrentYear ); // TODO: insert at correct position
444
StatisticEntry * InterfaceStatistics::genNewWeek( const QDate &date )
446
StatisticEntry *week = new StatisticEntry();
447
int dow = mCalendar->dayOfWeek( date );
448
// ISO8601: week always starts on a Monday
449
week->date = date.addDays( 1 - dow );
450
week->span = mCalendar->daysInWeek( week->date );
454
QDate InterfaceStatistics::getNextMonthStart( const QDate &startDate )
456
QDate nextMonthStart( startDate );
457
int length = mInterface->getSettings().billingMonths;
458
for ( int i = 0; i < length; i++ )
461
mCalendar->setDate( refDay, mCalendar->year( nextMonthStart ), mCalendar->month( nextMonthStart ), 1 );
462
refDay = refDay.addDays( mCalendar->daysInMonth( refDay ) );
464
nextMonthStart = nextMonthStart.addDays( mCalendar->daysInMonth( nextMonthStart ) );
466
// Ensure we don't get weird spans like jan31->mar2
467
// Instead, days will drift to a value that all months can handle.
468
// Test for problematic dates in config module!
469
if ( mCalendar->day( mBillingStart ) > 1 )
471
while ( mCalendar->month( nextMonthStart ) != mCalendar->month( refDay ) )
472
nextMonthStart = nextMonthStart.addDays( -1 );
475
return nextMonthStart;
478
bool InterfaceStatistics::checkValidSpan( const StatisticEntry& entry )
480
if ( !mDayStatistics.count() )
483
QDate endDate = entry.date.addDays( entry.span );
484
for ( int i = mDayStatistics.size() - 1; i >= 0; --i )
486
// No others will be valid after this; stop early
487
if ( mDayStatistics.at( i )->date < entry.date )
489
if ( mDayStatistics.at( i )->date < endDate &&
490
mDayStatistics.at( i )->date >= entry.date )
496
StatisticEntry * InterfaceStatistics::genNewMonth( const QDate &date, QDate endDate )
498
StatisticEntry *month = new StatisticEntry();
500
// Partial month. Very little to do.
501
if ( endDate.isValid() )
504
month->span = date.daysTo( endDate );
505
if ( checkValidSpan( *month ) )
511
// partial month contains no daily stats, so advance start date
512
// and get a new period below
513
mBillingStart = date.addDays( month->span );
517
// Given a calendar day and a billing period start date, find a
518
// billing period that the day belongs in.
519
QDate nextMonthStart = mBillingStart;
522
month->date = nextMonthStart;
523
nextMonthStart = getNextMonthStart( month->date );
524
month->span = month->date.daysTo( nextMonthStart );
525
} while ( nextMonthStart <= date || !checkValidSpan( *month ) );
527
mBillingStart = month->date;
532
StatisticEntry * InterfaceStatistics::genNewYear( const QDate &date )
534
StatisticEntry *year = new StatisticEntry();
535
int doy = mCalendar->dayOfYear( date );
536
year->date = date.addDays( 1 - doy );
537
year->span = mCalendar->daysInYear( year->date );
541
void InterfaceStatistics::updateCurrentWeek( const QDate ¤tDate )
543
if ( mWeekStatistics.count() )
545
mCurrentWeek = mWeekStatistics.last();
546
if ( mCurrentWeek->date.addDays( mCurrentWeek->span ) > currentDate )
550
mCurrentWeek = genNewWeek( currentDate );
552
mWeekStatistics.append( mCurrentWeek );
553
emit weekStatisticsChanged();
556
void InterfaceStatistics::updateCurrentMonth( const QDate ¤tDate )
558
if ( mMonthStatistics.count() )
560
mCurrentMonth = mMonthStatistics.last();
561
if ( mCurrentMonth->date.addDays( mCurrentMonth->span ) > currentDate )
565
mCurrentMonth = genNewMonth( currentDate );
566
mMonthStatistics.append( mCurrentMonth );
568
emit monthStatisticsChanged( false );
571
void InterfaceStatistics::saveBillingStart()
573
mInterface->getSettings().billingStart = mBillingStart;
574
KConfig *config = KGlobal::config().data();
575
KConfigGroup interfaceGroup( config, confg_interface + mInterface->getName() );
576
interfaceGroup.writeEntry( conf_billingStart, mBillingStart );
580
void InterfaceStatistics::updateCurrentYear( const QDate ¤tDate )
582
if ( mYearStatistics.count() )
584
mCurrentYear = mYearStatistics.last();
585
if ( mCurrentYear->date.addDays( mCurrentYear->span ) > currentDate )
589
mCurrentYear = genNewYear( currentDate );
590
mYearStatistics.append( mCurrentYear );
387
591
emit yearStatisticsChanged();
594
QDate InterfaceStatistics::setRebuildDate( QList<StatisticEntry *>& statistics,
595
const QDate &recalcDate,
596
enum GroupType group )
598
QDate returnDate = recalcDate;
600
// Keep removing entries and rolling back returnDate while
601
// entry's start date + span > returnDate
602
for ( int i = statistics.size() - 1; i >= 0; --i )
604
if ( statistics.at( i )->date.addDays( statistics.at( i )->span ) > mDayStatistics.first()->date &&
605
( statistics.at( i )->date.addDays( statistics.at( i )->span ) > returnDate ||
606
statistics.at( i )->span < 1 )
609
if ( returnDate > statistics.at( i )->date )
610
returnDate = statistics.at( i )->date;
611
statistics.removeAt( i );
617
// now take care of instances when we're going earlier than the first recorded stats.
621
returnDate = returnDate.addDays( 1 - mCalendar->dayOfWeek( returnDate ) );
622
while ( returnDate > recalcDate )
623
returnDate = returnDate.addDays( -mCalendar->daysInWeek( returnDate ) );
625
else if ( group == Year )
627
returnDate = returnDate.addDays( 1 - mCalendar->dayOfYear( returnDate ) );
628
while ( returnDate > recalcDate )
629
returnDate = returnDate.addDays( mCalendar->daysInYear( returnDate ) );
635
void InterfaceStatistics::rebuildStats( const QDate &date, int groups )
637
QDate recalcDate( date );
638
bool partial = false;
639
StatisticEntry* weekEntry = 0;
640
StatisticEntry* monthEntry = 0;
641
StatisticEntry* yearEntry = 0;
648
s.append( recalcDate );
652
weekStart = setRebuildDate( mWeekStatistics, recalcDate, Week );
653
s.append( weekStart );
655
if ( groups & Month )
657
monthStart = setRebuildDate( mMonthStatistics, recalcDate, Month );
659
mBillingStart = monthStart;
660
if ( recalcDate > monthStart )
662
s.append( monthStart );
666
yearStart = setRebuildDate( mYearStatistics, recalcDate, Year );
667
s.append( yearStart );
670
// Now find how far back we'll need to go
672
walkbackDate = s.first();
674
// Big loop, but this way we iterate through mDayStatistics once
675
// no matter how many categories we're rebuilding
676
foreach( StatisticEntry* day, mDayStatistics )
678
if ( day->date < walkbackDate )
681
if ( groups & Week && day->date >= weekStart )
683
if ( !weekEntry || mCalendar->weekNumber( weekEntry->date ) != mCalendar->weekNumber( day->date ) ||
684
weekEntry->date.addDays( mCalendar->daysInWeek( weekEntry->date ) ) <= day->date )
687
mWeekStatistics.append( weekEntry );
688
weekEntry = genNewWeek( day->date );
690
weekEntry->rxBytes += day->rxBytes;
691
weekEntry->txBytes += day->txBytes;
694
if ( groups & Month && day->date >= monthStart )
696
if ( !monthEntry || day->date >= monthEntry->date.addDays( monthEntry->span ) )
699
mMonthStatistics.append( monthEntry );
702
monthEntry = genNewMonth( monthStart, recalcDate );
703
// Partial month created; next period will begin on recalcDate
704
mBillingStart = recalcDate;
708
monthEntry = genNewMonth( day->date );
710
monthEntry->rxBytes += day->rxBytes;
711
monthEntry->txBytes += day->txBytes;
713
if ( groups & Year && day->date >= yearStart )
715
if ( !yearEntry || mCalendar->year( yearEntry->date ) != mCalendar->year( day->date ) )
718
mYearStatistics.append( yearEntry );
719
yearEntry = genNewYear( day->date );
721
yearEntry->rxBytes += day->rxBytes;
722
yearEntry->txBytes += day->txBytes;
726
mCurrentWeek = appendStats( mWeekStatistics, weekEntry );
727
mCurrentMonth = appendStats( mMonthStatistics, monthEntry );
728
mCurrentYear = appendStats( mYearStatistics, yearEntry );
731
StatisticEntry * InterfaceStatistics::appendStats( QList<StatisticEntry *>& statistics, StatisticEntry *entry )
734
statistics.append( entry );
735
return statistics.last();