blob: 62ca63bf3f16146adae70bca596a5e63ae956c82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "TimeChartPage.h"
#include "StatisticsParams.h"
#include "../charts/TimeChart.h"
#include "../dictionary/CardPack.h"
TimeChartPage::TimeChartPage(const StatisticsParams* statParams):
BaseStatPage(statParams)
{
}
QWidget* TimeChartPage::createChart()
{
chart = new TimeChart;
chart->setLabels(tr("Date"), tr("Cards"));
return chart;
}
void TimeChartPage::updateDataSet()
{
QList<QDateTime> dates = getDates(statParams->getCardPack());
int period = statParams->getTimePeriod();
if(period == -1)
period = getStudyPeriodLength(dates);
int reviewsNum = getReviewsNum(dates, period);
totalReviewsLabel->setText(tr("Total: %1").arg(reviewsNum));
chart->setDates(dates, period, getDataDirection());
}
int TimeChartPage::getStudyPeriodLength(const QList<QDateTime>& dates) const
{
const int minPeriod = 7;
QDateTime minDate = QDateTime::currentDateTime();
QDateTime maxDate = minDate;
foreach(QDateTime date, dates)
if(date < minDate)
minDate = date;
else if(date > maxDate)
maxDate = date;
int res = minDate.daysTo(maxDate) + 1;
if(res < minPeriod)
res = minPeriod;
return res;
}
int TimeChartPage::getReviewsNum(const QList<QDateTime>& dates,
int period) const
{
QDateTime curDate = QDateTime::currentDateTime();
int res = 0;
foreach(QDateTime date, dates)
if(qAbs(date.daysTo(curDate)) < period)
res++;
return res;
}
|