Compare commits

...

2 commits

Author SHA1 Message Date
Nicolas Mailloux
d5f23ac88a FlashExam: bugfixes 2024-12-16 15:41:58 -05:00
Nicolas Mailloux
dcfaa5d1eb FlashExam: new 'brain brute-force' mode 2024-12-16 15:19:12 -05:00
3 changed files with 161 additions and 55 deletions

View file

@ -34,6 +34,7 @@ flashExam::flashExam(QWidget *parent)
ui->saveCardsNotKnownToFileCheckBox->setDisabled(true);
ui->randomizeCheckBox->click();
ui->randomizeCheckBox->setDisabled(true);
ui->brainBruteForceCardsThresholdSpinBox->setDisabled(true);
graphicsScene = new QGraphicsScene(this);
setupCardsList();
@ -69,6 +70,7 @@ void flashExam::on_startBtn_clicked()
listName = ui->listWidget->currentItem()->text();
QString cardsList = "/mnt/onboard/onboard/.flashexam/" + listName;
QString answersList = "/mnt/onboard/onboard/.flashexam/" + listName + ".answers";
brainBruteForceCardsThreshold = ui->brainBruteForceCardsThresholdSpinBox->value();
if(QFile::exists(answersList)) {
log("Setting up cards list '" + listName + "'", className);
initCardsList(cardsList, answersList);
@ -87,9 +89,11 @@ void flashExam::initCardsList(QString cardsList, QString answersList) {
randomize = ui->randomizeCheckBox->isChecked();
nonRedundantRandomization = ui->nonRedundantRandomizationCheckBox->isChecked();
saveCardsNotKnownToFile = ui->saveCardsNotKnownToFileCheckBox->isChecked();
brainBruteForceMode = ui->brainBruteForceCheckBox->isChecked();
cardsAlreadyShown.clear();
cardsNotKnown.clear();
ui->nonRedundantRandomizationCheckBox->setChecked(false);
ui->brainBruteForceCheckBox->setChecked(false);
cardsTotal = cardsStringList.count() + 1;
displayCard(false);
ui->stackedWidget->setCurrentIndex(1);
@ -133,23 +137,43 @@ void flashExam::on_nextBtn_clicked()
}
void flashExam::displayCard(bool existingCardNumber) {
if(nonRedundantRandomization) {
float cardsTotalFloat = cardsTotal * 1.0;
float cardsAlreadyShownNumber = cardsAlreadyShown.count() * 1.0;
float cardsNotKnownNumber = cardsNotKnown.count() * 1.0;
ui->cardNumberLabel->setText(QString::number(cardsAlreadyShownNumber / cardsTotalFloat * 100, 'f', 1) + "% done, " + QString::number(cardsNotKnownNumber / cardsTotalFloat * 100, 'f', 1) + "% forgotten");
}
else {
ui->cardNumberLabel->hide();
}
if(!existingCardNumber) {
if(randomize) {
if(brainBruteForceLock && cardsNotKnown.isEmpty()) {
brainBruteForceLock = false;
}
if(nonRedundantRandomization) {
float cardsTotalFloat = cardsTotal * 1.0;
float cardsAlreadyShownNumber = cardsAlreadyShown.count() * 1.0;
float cardsNotKnownNumber = cardsNotKnown.count() * 1.0;
if(!brainBruteForceLock) {
if(brainBruteForceMode) {
ui->cardNumberLabel->setText(QString::number(cardsAlreadyShownNumber / cardsTotalFloat * 100, 'f', 1) + "% done");
}
else {
ui->cardNumberLabel->setText(QString::number(cardsAlreadyShownNumber / cardsTotalFloat * 100, 'f', 1) + "% done, " + QString::number(cardsNotKnownNumber / cardsTotalFloat * 100, 'f', 1) + "% forgotten");
}
}
}
if(brainBruteForceMode && cardsNotKnown.count() >= brainBruteForceCardsThreshold) {
brainBruteForceLock = true;
ui->cardNumberLabel->setText("Brain brute-force mode");
ui->cardNumberLabel->show();
}
while(true) {
currentCardNumber = QRandomGenerator::global()->bounded(cardsTotal - 1);
if(brainBruteForceLock) {
currentCardNumber = cardsNotKnown.at(cardsNotKnown.count() - 1);
cardsNotKnown.removeLast();
log("Brain brute-force mode: displaying card " + QString::number(currentCardNumber), className);
}
else {
currentCardNumber = QRandomGenerator::global()->bounded(cardsTotal - 1);
}
if(nonRedundantRandomization) {
if(!cardsAlreadyShown.contains(currentCardNumber)) {
cardsAlreadyShown.append(currentCardNumber);
if(brainBruteForceLock || !cardsAlreadyShown.contains(currentCardNumber)) {
if(!brainBruteForceLock) {
cardsAlreadyShown.append(currentCardNumber);
}
break;
}
else {
@ -218,9 +242,11 @@ void flashExam::on_randomizeCheckBox_toggled(bool checked)
{
if(checked) {
ui->nonRedundantRandomizationCheckBox->setDisabled(false);
ui->brainBruteForceCheckBox->setDisabled(false);
}
else {
ui->nonRedundantRandomizationCheckBox->setDisabled(true);
ui->brainBruteForceCheckBox->setDisabled(true);
}
}
@ -234,7 +260,9 @@ void flashExam::on_didNotKnowBtn_clicked()
void flashExam::on_nonRedundantRandomizationCheckBox_toggled(bool checked)
{
if(checked) {
ui->saveCardsNotKnownToFileCheckBox->setDisabled(false);
if(!ui->brainBruteForceCheckBox->isChecked()) {
ui->saveCardsNotKnownToFileCheckBox->setDisabled(false);
}
}
else {
ui->saveCardsNotKnownToFileCheckBox->setDisabled(true);
@ -242,3 +270,21 @@ void flashExam::on_nonRedundantRandomizationCheckBox_toggled(bool checked)
}
}
void flashExam::on_brainBruteForceCheckBox_toggled(bool checked)
{
if(checked) {
if(ui->nonRedundantRandomizationCheckBox->isChecked()) {
ui->saveCardsNotKnownToFileCheckBox->setDisabled(true);
ui->saveCardsNotKnownToFileCheckBox->setChecked(false);
}
ui->brainBruteForceCardsThresholdSpinBox->setDisabled(false);
}
else {
if(ui->nonRedundantRandomizationCheckBox->isChecked()) {
ui->saveCardsNotKnownToFileCheckBox->setDisabled(false);
}
ui->brainBruteForceCardsThresholdSpinBox->setDisabled(true);
}
}

View file

@ -25,6 +25,9 @@ private:
bool randomize;
bool nonRedundantRandomization;
bool saveCardsNotKnownToFile;
bool brainBruteForceMode;
bool brainBruteForceLock = false;
int brainBruteForceCardsThreshold;
QList<int> cardsAlreadyShown;
QList<int> cardsNotKnown;
bool answerShown = false;
@ -47,6 +50,7 @@ private slots:
void on_randomizeCheckBox_toggled(bool checked);
void on_didNotKnowBtn_clicked();
void on_nonRedundantRandomizationCheckBox_toggled(bool checked);
void on_brainBruteForceCheckBox_toggled(bool checked);
};
#endif // FLASHEXAM_H

View file

@ -35,6 +35,31 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Shadow::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="nonRedundantRandomizationCheckBox">
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>Non-redundant randomized mode</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin">
@ -102,7 +127,10 @@
</item>
</layout>
</item>
<item row="7" column="0">
<item row="3" column="0">
<widget class="QListWidget" name="listWidget"/>
</item>
<item row="9" column="0">
<widget class="Line" name="line_2">
<property name="frameShadow">
<enum>QFrame::Shadow::Plain</enum>
@ -112,28 +140,27 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="Line" name="line">
<property name="frameShadow">
<enum>QFrame::Shadow::Plain</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="nonRedundantRandomizationCheckBox">
<item row="6" column="0">
<widget class="QCheckBox" name="saveCardsNotKnownToFileCheckBox">
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>Non-redundant randomized mode</string>
<string>Save forgotten cards list to file</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QPushButton" name="startBtn">
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
@ -150,31 +177,60 @@
</widget>
</item>
<item row="8" column="0">
<widget class="QPushButton" name="startBtn">
<property name="font">
<font>
<bold>true</bold>
</font>
<layout class="QGridLayout" name="gridLayout_8">
<property name="bottomMargin">
<number>0</number>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QListWidget" name="listWidget"/>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="saveCardsNotKnownToFileCheckBox">
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>Save forgotten cards list to file</string>
</property>
</widget>
<item row="0" column="2">
<widget class="QSpinBox" name="brainBruteForceCardsThresholdSpinBox">
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="brainBruteForceCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>Brain brute-force mode</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>Every</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<family>U001</family>
</font>
</property>
<property name="text">
<string>forgotten cards</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>