Skip to content

Commit

Permalink
添加tag功能和tag计时训练功能
Browse files Browse the repository at this point in the history
  • Loading branch information
patchy1-admin committed Aug 4, 2024
1 parent 1d63078 commit bbe3af1
Show file tree
Hide file tree
Showing 16 changed files with 568 additions and 58 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# questions
题库型的学习软件,采用FSRS算法,其核心思路与anki类似,以填空题答题速度为依据判断对知识点的掌握程度
题库型的学习软件,采用FSRS算法,核心思路与anki相同。以填空题答题速度为依据判断对知识点的掌握程度。

![questions-sample1](.\questions-sample1.png)

![questions-sample2](.\questions-sample2.png)

本项目FSRS算法实现主要来自该项目:https://github.com/open-spaced-repetition/fsrs4anki

感谢FSRS算法的创造者、实现者们。
78 changes: 70 additions & 8 deletions learningdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ LearningDialog::LearningDialog(QuestionSql *newQuestionSql,QWidget *parent)
, ui(new Ui::LearningDialog)
{
ui->setupUi(this);

//init timer
timer = new QTimer(this);
timer->setInterval(10);
connect(timer,&QTimer::timeout,this,&LearningDialog::timerHandler);

//init total timer
totalTimer = new QTimer(this);
totalTimer->setInterval(10);
connect(totalTimer,&QTimer::timeout,this,&LearningDialog::totalTimerHandler);


font = new QFont("Microsoft YaHei",9);
fm = new QFontMetrics(*font);
time.setHMS(0,0,0);
Expand Down Expand Up @@ -73,13 +82,19 @@ void LearningDialog::clear_question_display()
}
}

void LearningDialog::set_itmes_table(QString filter)
void LearningDialog::set_items_table(QString filter)
{
totalTime = QTime::fromMSecsSinceStartOfDay(0);
tableModel->setFilter(filter);
totalCount = 0;
correctCount = 0;
if(isSpeedLearn)
ui->comboBox->setCurrentIndex(1);
clear_question_display();
}

void LearningDialog::set_question(int id)
{
{
currentId = id;
ui->idLabel->setText(QString("id:%1").arg(currentId));

Expand Down Expand Up @@ -133,6 +148,11 @@ void LearningDialog::set_question(int id)
layout->addItem(verticalSpacer,array.count()+1,0,1,3);

layout->itemAt(0)->widget()->setFocus();

//start totalTimer
if(!totalTimer->isActive())
totalTimer->start();

//start timer
start_timer();
}
Expand All @@ -145,9 +165,12 @@ bool LearningDialog::is_submited()
void LearningDialog::on_pushButton_clicked()
{
stop_timer();

if(tableModel->rowCount() == 0)
{
totalTimer->stop();
return;

}
if(currentId == -1)
return;

Expand Down Expand Up @@ -175,7 +198,6 @@ void LearningDialog::on_pushButton_clicked()
ui->tableView->selectRow(newRow);
set_question(ui->tableView->currentIndex().siblingAtColumn(0).data().toInt());


submited = false;
return;
}
Expand Down Expand Up @@ -232,13 +254,32 @@ void LearningDialog::on_pushButton_clicked()

questionSql->update_question_state(currentId,time);
checkLabel->show();

oldRow = ui->tableView->currentIndex().row();
set_itmes_table(tableModel->filter());

//set accuracy label
totalCount++;
if(!wrong)
correctCount++;
QString acc = QString::number(double(correctCount)/totalCount*100,'f',2);
QString newAccuracyText = QString("正确率(%1\%):%2/%3").arg(acc).arg(correctCount).arg(totalCount);
ui->accuracyLabel->setText(newAccuracyText);

//set new filter
if(isSpeedLearn)
{
if(!wrong)
{
QString condString = QString("%1 AND questions.id != %2").arg(tableModel->filter()).arg(currentId);
tableModel->setFilter(condString);
qDebug() << condString;
}
}

//update old row
tableModel->select();
if(oldRow >= tableModel->rowCount())
oldRow = tableModel->rowCount() - 1;
oldRow = 0;
ui->tableView->selectRow(oldRow);

}

void LearningDialog::timerHandler()
Expand All @@ -250,6 +291,12 @@ void LearningDialog::timerHandler()
}
}

void LearningDialog::totalTimerHandler()
{
totalTime = totalTime.addMSecs(10);
ui->totalTimeLabel->setText(totalTime.toString("hh:mm:ss.zzz").chopped(1));
}

void LearningDialog::start_timer()
{
time.setHMS(0,0,0);
Expand All @@ -266,8 +313,13 @@ void LearningDialog::stop_timer()
void LearningDialog::on_LearningDialog_finished(int result)
{
stop_timer();
totalTimer->stop();
submited = true;
currentId = -1;
if(tableModel->rowCount() != 0)
{
totalTime = QTime::fromString("23:59:59.99");
}
}

QTime LearningDialog::getTime() const
Expand Down Expand Up @@ -303,3 +355,13 @@ void LearningDialog::on_comboBox_currentTextChanged(const QString &arg1)
ui->tableView->clearSelection();
clear_question_display();
}

void LearningDialog::setIsSpeedLearn(bool newIsSpeedLearn)
{
isSpeedLearn = newIsSpeedLearn;
}

QTime LearningDialog::getTotalTime() const
{
return totalTime;
}
19 changes: 17 additions & 2 deletions learningdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,30 @@ class LearningDialog : public QDialog
~LearningDialog();

void set_answer(QJsonArray array);
void start_timer();


void set_category(int categoryId, bool learnALl);
void set_question(int id);

void start_timer();
void stop_timer();

void clear_question_display();

QTime getTime() const;
bool is_submited();

void set_tableHeader();
void set_itmes_table(QString filter);
void set_items_table(QString filter);

QTime getTotalTime() const;

void setIsSpeedLearn(bool newIsSpeedLearn);

private slots:
void on_pushButton_clicked();
void timerHandler();
void totalTimerHandler();

void on_LearningDialog_finished(int result);

Expand All @@ -56,8 +63,16 @@ private slots:

private:
Ui::LearningDialog *ui;

QTimer *timer;
QTime time;

QTimer *totalTimer;
QTime totalTime;
int totalCount;
int correctCount;
bool isSpeedLearn;

bool submited;
QString rating;
QFont *font;
Expand Down
46 changes: 46 additions & 0 deletions learningdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,52 @@ li.checked::marker { content: &quot;\2612&quot;; }
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>总用时:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="totalTimeLabel">
<property name="font">
<font>
<family>文泉驿等宽微米黑</family>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>00:00:00.00</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="accuracyLabel">
<property name="font">
<font>
<family>Microsoft YaHei UI</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>正确率(0%):0/0</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<item>
Expand Down
Loading

0 comments on commit bbe3af1

Please sign in to comment.