summaryrefslogtreecommitdiff
path: root/src/study/SpacedRepetitionModel.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/study/SpacedRepetitionModel.h')
-rw-r--r--src/study/SpacedRepetitionModel.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/study/SpacedRepetitionModel.h b/src/study/SpacedRepetitionModel.h
new file mode 100644
index 0000000..d39a1b8
--- /dev/null
+++ b/src/study/SpacedRepetitionModel.h
@@ -0,0 +1,79 @@
+#ifndef SPACEDREPETITIONMODEL_H
+#define SPACEDREPETITIONMODEL_H
+
+#include "IStudyModel.h"
+#include "StudyRecord.h"
+#include "StudySettings.h"
+
+#include <QMultiMap>
+#include <QTime>
+
+class CardPack;
+class IRandomGenerator;
+
+class SpacedRepetitionModel: public IStudyModel
+{
+ Q_OBJECT
+
+public:
+ static const int NewCardsDayLimit = 10;
+
+public:
+ SpacedRepetitionModel(CardPack* aCardPack, IRandomGenerator* random);
+ ~SpacedRepetitionModel();
+
+public:
+ Card* getCurCard() const { return curCard; }
+ QList<int> getAvailableGrades() const;
+ bool isNew() const;
+ void setRecallTime( int aTime ) { curRecallTime = aTime; }
+ int estimatedNewReviewedCardsToday() const;
+ int countTodayRemainingCards() const;
+
+public slots:
+ void scheduleCard(int newGrade);
+
+protected:
+ void pickNextCardAndNotify();
+
+private:
+ StudyRecord createNewStudyRecord(int newGrade);
+ int getNewLevel(const StudyRecord& prevStudy, int newGrade);
+ double getNewEasiness(const StudyRecord& prevStudy, int newGrade);
+ double getChangeableEasiness(const StudyRecord& prevStudy, int newGrade) const;
+ double limitEasiness(double eas) const;
+ double getNextInterval(const StudyRecord& prevStudy,
+ const StudyRecord& newStudy);
+ double getNextRepeatingInterval(const StudyRecord& prevStudy,
+ const StudyRecord& newStudy);
+ double getIncreasedInterval(double prevInterval, double newEasiness);
+ double getNextRepeatingIntervalForShortLearning(
+ const StudyRecord& prevStudy, const StudyRecord& newStudy);
+ double getNextRepeatingIntervalForLongLearning(
+ const StudyRecord& prevStudy, const StudyRecord& newStudy);
+ void saveStudyRecord(const StudyRecord& newStudy);
+ void pickNextCard();
+ bool pickNewCard();
+ QString getRandomStr(const QStringList& list) const;
+ bool reachedNewCardsDayLimit() const;
+ bool mustPickScheduledCard();
+ bool tooManyScheduledCards() const;
+ bool mustRandomPickScheduledCard() const;
+ bool pickActiveCard();
+ bool pickPriorityActiveCard();
+ bool pickLearningCard();
+ void saveStudy();
+
+private slots:
+ void updateStudyState();
+
+private:
+ Card* curCard; ///< The card selected for repetition
+ Card* prevCard; ///< Previous reviewed card. Found in the study history.
+ int curRecallTime; ///< Recall time of the current card, ms
+ QTime answerTime; ///< Full answer time of the current card: recall + evaluation, ms
+ StudySettings* settings;
+ IRandomGenerator* random;
+};
+
+#endif