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/study/StudyRecord.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/study/StudyRecord.cpp (limited to 'src/study/StudyRecord.cpp') diff --git a/src/study/StudyRecord.cpp b/src/study/StudyRecord.cpp new file mode 100644 index 0000000..330f572 --- /dev/null +++ b/src/study/StudyRecord.cpp @@ -0,0 +1,129 @@ +#include "StudyRecord.h" + +#include "StudySettings.h" +#include "../utils/TimeProvider.h" + +ostream& operator<<(ostream& os, const StudyRecord& study) +{ + if(study.date <= QDateTime::currentDateTime()) + { + const char* dateStr = study.date.toString(Qt::ISODate).toStdString().c_str(); + os << "(" << dateStr << + ", g" << study.grade << ", e" << study.easiness << ", " << + "i" << study.interval << ")"; + } + else + os << "(New card)"; + return os; +} + +// Create "new" study record +StudyRecord::StudyRecord(): + date(QDateTime()), + level(New), + interval(0), + grade(Unknown), + easiness(StudySettings::inst()->initEasiness), + recallTime(0), + answerTime(0) + { + } + +StudyRecord::StudyRecord(int level, int grade, double easiness, double interval): + date(QDateTime()), + recallTime(0), + answerTime(0) +{ + this->level = level; + this->interval = interval; + this->grade = grade; + this->easiness = easiness; +} + +bool StudyRecord::operator==(const StudyRecord& aOther) const + { + return level == aOther.level && + date == aOther.date && + interval == aOther.interval && + grade == aOther.grade && + easiness == aOther.easiness; + } + +bool StudyRecord::timeTriggered() const +{ + if(date.isNull()) + return false; + QDateTime nextRepetition = date.addSecs( (int)(interval * 60*60*24) ); + return nextRepetition <= TimeProvider::get(); +} + +int StudyRecord::getSecsToNextRepetition() const +{ + if(date.isNull()) + return 0; + QDateTime nextRepetition = date.addSecs( (int)(interval * 60*60*24) ); + return TimeProvider::get().secsTo(nextRepetition); +} + +bool StudyRecord::isOneDayOld() const +{ + return date.secsTo(TimeProvider::get()) / (60*60*24.) >= + StudySettings::inst()->nextDayInterval; +} + +bool StudyRecord::isLearning() const +{ + return (level == ShortLearning || level == LongLearning) && + !isOneDayOld(); +} + +int StudyRecord::getScheduledTodayReviews() const +{ + switch(level) + { + case New: + return 3; + case ShortLearning: + return 2; + case LongLearning: + return 1; + default: + return 0; + } +} + +bool StudyRecord::isReviewedToday() const +{ + QDateTime recShiftedDate = shiftedDate(date); + QDateTime curShiftedDate = shiftedDate(QDateTime::currentDateTime()); + return recShiftedDate.date() == curShiftedDate.date(); +} + +bool StudyRecord::isActivatedToday() const +{ + if(date.isNull()) + return false; + QDateTime nextRepetition = date.addSecs( (int)(interval * 60*60*24) ); + QDateTime shiftedNextRep = shiftedDate(nextRepetition); + QDateTime curShiftedDate = shiftedDate(QDateTime::currentDateTime()); + return shiftedNextRep.date() <= curShiftedDate.date(); +} + +QDateTime StudyRecord::shiftedDate(const QDateTime& aDate) +{ + return aDate.addSecs(-60 * 60 * StudySettings::inst()->dayShift); +} + +void StudyRecord::setRecallTime(double time) +{ + recallTime = time; + if(recallTime > MaxAnswerTime) + recallTime = MaxAnswerTime; +} + +void StudyRecord::setAnswerTime(double time) +{ + answerTime = time; + if(answerTime > MaxAnswerTime) + answerTime = MaxAnswerTime; +} -- cgit