From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- src/statistics/TimeChartPage.cpp | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/statistics/TimeChartPage.cpp (limited to 'src/statistics/TimeChartPage.cpp') 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 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& 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& dates, + int period) const +{ + QDateTime curDate = QDateTime::currentDateTime(); + int res = 0; + foreach(QDateTime date, dates) + if(qAbs(date.daysTo(curDate)) < period) + res++; + return res; +} -- cgit