diff options
Diffstat (limited to 'src/statistics/TimeChartPage.cpp')
-rw-r--r-- | src/statistics/TimeChartPage.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/statistics/TimeChartPage.cpp b/src/statistics/TimeChartPage.cpp new file mode 100644 index 0000000..62ca63b --- /dev/null +++ b/src/statistics/TimeChartPage.cpp @@ -0,0 +1,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;
+}
|