mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
functions in camelcase
This commit is contained in:
@@ -8,17 +8,17 @@
|
|||||||
|
|
||||||
|
|
||||||
struct Question {
|
struct Question {
|
||||||
double Cooldown;
|
double cooldown;
|
||||||
std::string QuestionText;
|
std::string questionText;
|
||||||
std::string Section;
|
std::string section;
|
||||||
|
|
||||||
virtual std::string ToString() const = 0;
|
virtual std::string toString() const = 0;
|
||||||
virtual ~Question() = default;
|
virtual ~Question() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Choice {
|
struct Choice {
|
||||||
std::string Answer;
|
std::string answer;
|
||||||
bool IsCorrect;
|
bool isCorrect;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MultiElementType {
|
enum MultiElementType {
|
||||||
@@ -28,10 +28,10 @@ enum MultiElementType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct MultiElementQuestion : public Question {
|
struct MultiElementQuestion : public Question {
|
||||||
std::vector<Choice> Choices;
|
std::vector<Choice> choices;
|
||||||
MultiElementType type;
|
MultiElementType type;
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string toString() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Group {
|
struct Group {
|
||||||
@@ -40,9 +40,9 @@ struct Group {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GroupQuestion : public Question {
|
struct GroupQuestion : public Question {
|
||||||
std::vector<Group> Groups;
|
std::vector<Group> groups;
|
||||||
|
|
||||||
std::string ToString() const override;
|
std::string toString() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParseInfo {
|
struct ParseInfo {
|
||||||
|
|||||||
@@ -133,19 +133,19 @@ std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
|||||||
for (auto question: questions) {
|
for (auto question: questions) {
|
||||||
ss << std::endl;
|
ss << std::endl;
|
||||||
std::string cooldownPart;
|
std::string cooldownPart;
|
||||||
if (question->Cooldown != 0) {
|
if (question->cooldown != 0) {
|
||||||
cooldownPart = std::format(" [{:.2f}]", question->Cooldown);
|
cooldownPart = std::format(" [{:.2f}]", question->cooldown);
|
||||||
}
|
}
|
||||||
ss << wrapText(
|
ss << wrapText(
|
||||||
std::format("-{}{} >\n",
|
std::format("-{}{} >\n",
|
||||||
cooldownPart,
|
cooldownPart,
|
||||||
" " + escapeText(question->QuestionText)),
|
" " + escapeText(question->questionText)),
|
||||||
wrap_width
|
wrap_width
|
||||||
);
|
);
|
||||||
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
||||||
for (auto choice: mw->Choices) {
|
for (auto choice: mw->choices) {
|
||||||
char opener;
|
char opener;
|
||||||
if (choice.IsCorrect) {
|
if (choice.isCorrect) {
|
||||||
opener = '+';
|
opener = '+';
|
||||||
} else {
|
} else {
|
||||||
opener = '-';
|
opener = '-';
|
||||||
@@ -160,12 +160,12 @@ std::string outputMdem(std::vector<Question*> questions, time_t time = 0) {
|
|||||||
"\t{}{} {}\n",
|
"\t{}{} {}\n",
|
||||||
opener,
|
opener,
|
||||||
orderModifier,
|
orderModifier,
|
||||||
escapeText(choice.Answer)
|
escapeText(choice.answer)
|
||||||
)
|
)
|
||||||
, wrap_width);
|
, wrap_width);
|
||||||
}
|
}
|
||||||
} else if (GroupQuestion* gq = dynamic_cast<GroupQuestion*>(question)) {
|
} else if (GroupQuestion* gq = dynamic_cast<GroupQuestion*>(question)) {
|
||||||
for (auto group: gq->Groups) {
|
for (auto group: gq->groups) {
|
||||||
ss << wrapText(
|
ss << wrapText(
|
||||||
std::format(
|
std::format(
|
||||||
"\t- {}:\n",
|
"\t- {}:\n",
|
||||||
@@ -207,23 +207,23 @@ void makePages() {
|
|||||||
|
|
||||||
void setupMdem(Mdem *mdem, Question *question) {
|
void setupMdem(Mdem *mdem, Question *question) {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
if (question->Cooldown > 0) {
|
if (question->cooldown > 0) {
|
||||||
ss << std::format("[{:.2f}] ", question->Cooldown);
|
ss << std::format("[{:.2f}] ", question->cooldown);
|
||||||
}
|
}
|
||||||
ss << question->QuestionText;
|
ss << question->questionText;
|
||||||
mdem->wFrontText.setText(
|
mdem->wFrontText.setText(
|
||||||
QString::fromStdString(ss.str())
|
QString::fromStdString(ss.str())
|
||||||
);
|
);
|
||||||
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
if (MultiElementQuestion* mw = dynamic_cast<MultiElementQuestion*>(question)) {
|
||||||
auto choices = mw->Choices;
|
auto choices = mw->choices;
|
||||||
for (size_t k = 0; k < choices.size(); ++k) {
|
for (size_t k = 0; k < choices.size(); ++k) {
|
||||||
auto answer = choices[k].Answer;
|
auto answer = choices[k].answer;
|
||||||
switch (mw->type) {
|
switch (mw->type) {
|
||||||
case MultiElementType::Order:
|
case MultiElementType::Order:
|
||||||
answer = std::format("{}. {}", k + 1, answer);
|
answer = std::format("{}. {}", k + 1, answer);
|
||||||
break;
|
break;
|
||||||
case MultiElementType::MultiChoice:
|
case MultiElementType::MultiChoice:
|
||||||
if (choices[k].IsCorrect) {
|
if (choices[k].isCorrect) {
|
||||||
answer = std::format("+ {}", answer);
|
answer = std::format("+ {}", answer);
|
||||||
} else {
|
} else {
|
||||||
answer = std::format("- {}", answer);
|
answer = std::format("- {}", answer);
|
||||||
@@ -244,7 +244,7 @@ void setupMdem(Mdem *mdem, Question *question) {
|
|||||||
}
|
}
|
||||||
mdem->labelCount = choices.size();
|
mdem->labelCount = choices.size();
|
||||||
} else if (GroupQuestion* mw = dynamic_cast<GroupQuestion*>(question)) {
|
} else if (GroupQuestion* mw = dynamic_cast<GroupQuestion*>(question)) {
|
||||||
auto groups = mw->Groups;
|
auto groups = mw->groups;
|
||||||
std::vector<std::string> elements;
|
std::vector<std::string> elements;
|
||||||
for (size_t k = 0; k < groups.size(); ++k) {
|
for (size_t k = 0; k < groups.size(); ++k) {
|
||||||
auto answer = groups[k].name;
|
auto answer = groups[k].name;
|
||||||
@@ -267,7 +267,7 @@ void setupMdem(Mdem *mdem, Question *question) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchPage(int pageIdx);
|
void switchPage(int pageIdx);
|
||||||
|
|
||||||
std::string getFilename(std::string path) {
|
std::string getFilename(std::string path) {
|
||||||
static const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
static const std::regex lastPathElementExp = std::regex("(.+\\/)*(.+)");
|
||||||
@@ -363,7 +363,7 @@ Mdem* makeMdem() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
makePages();
|
makePages();
|
||||||
SwitchPage(pagination->currentPage);
|
switchPage(pagination->currentPage);
|
||||||
}
|
}
|
||||||
if (editMdem == mdem) {
|
if (editMdem == mdem) {
|
||||||
editorWindow->hide();
|
editorWindow->hide();
|
||||||
@@ -442,14 +442,14 @@ void CreateMdems(std::vector<Question*>& questions) {
|
|||||||
|
|
||||||
void update(bool isChanged) {
|
void update(bool isChanged) {
|
||||||
if (pagination->currentPage > -1) {
|
if (pagination->currentPage > -1) {
|
||||||
SwitchPage(pagination->currentPage);
|
switchPage(pagination->currentPage);
|
||||||
}
|
}
|
||||||
if (currentMdem.length() > 0) {
|
if (currentMdem.length() > 0) {
|
||||||
updateMdemInfo(getFilename(currentMdem), isChanged);
|
updateMdemInfo(getFilename(currentMdem), isChanged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwitchPage(int pageIdx) {
|
void switchPage(int pageIdx) {
|
||||||
pagination->currentPage = pageIdx;
|
pagination->currentPage = pageIdx;
|
||||||
|
|
||||||
// Hide all pagination buttons
|
// Hide all pagination buttons
|
||||||
@@ -566,7 +566,7 @@ void reloadMdem(std::string path) {
|
|||||||
buffer = buffers[path];
|
buffer = buffers[path];
|
||||||
currentMdemBuffer = buffer;
|
currentMdemBuffer = buffer;
|
||||||
makePages();
|
makePages();
|
||||||
SwitchPage(0);
|
switchPage(0);
|
||||||
updateMdemInfo(getFilename(filename), buffer->isModified);
|
updateMdemInfo(getFilename(filename), buffer->isModified);
|
||||||
currentMdem = path;
|
currentMdem = path;
|
||||||
errorView->box.hide();
|
errorView->box.hide();
|
||||||
@@ -630,7 +630,7 @@ void reloadMdem(std::string path) {
|
|||||||
hMdemScroll->addItem(mdemSpacer);
|
hMdemScroll->addItem(mdemSpacer);
|
||||||
}
|
}
|
||||||
makePages();
|
makePages();
|
||||||
SwitchPage(0);
|
switchPage(0);
|
||||||
updateMdemInfo(filename, false);
|
updateMdemInfo(filename, false);
|
||||||
} else {
|
} else {
|
||||||
std::cout << std::format("Could not open the file: {}", currentPath.toStdString()) << std::endl;
|
std::cout << std::format("Could not open the file: {}", currentPath.toStdString()) << std::endl;
|
||||||
@@ -731,7 +731,7 @@ void setupEditorSave() {
|
|||||||
res.value.questions.end()
|
res.value.questions.end()
|
||||||
);
|
);
|
||||||
makePages();
|
makePages();
|
||||||
SwitchPage(0);
|
switchPage(0);
|
||||||
editorWindow->hide();
|
editorWindow->hide();
|
||||||
updateMdemInfo(getFilename(currentMdem), true);
|
updateMdemInfo(getFilename(currentMdem), true);
|
||||||
}
|
}
|
||||||
@@ -1025,7 +1025,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
pagination->firstButton.hide();
|
pagination->firstButton.hide();
|
||||||
QObject::connect(&pagination->firstButton, &QToolButton::clicked, []() {
|
QObject::connect(&pagination->firstButton, &QToolButton::clicked, []() {
|
||||||
if (pagination->pages.size() > 0) {
|
if (pagination->pages.size() > 0) {
|
||||||
SwitchPage(0);
|
switchPage(0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1034,7 +1034,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
pagination->prevButton.hide();
|
pagination->prevButton.hide();
|
||||||
QObject::connect(&pagination->prevButton, &QToolButton::clicked, []() {
|
QObject::connect(&pagination->prevButton, &QToolButton::clicked, []() {
|
||||||
if (pagination->pages.size() > 0) {
|
if (pagination->pages.size() > 0) {
|
||||||
SwitchPage(pagination->currentPage - 1);
|
switchPage(pagination->currentPage - 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1047,7 +1047,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
auto pageNum = std::stoi(elButton->text().toStdString().c_str());
|
auto pageNum = std::stoi(elButton->text().toStdString().c_str());
|
||||||
auto pageIdx = pageNum - 1;
|
auto pageIdx = pageNum - 1;
|
||||||
if (pageIdx < pagination->pages.size()) {
|
if (pageIdx < pagination->pages.size()) {
|
||||||
SwitchPage(pageIdx);
|
switchPage(pageIdx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
pagination->paginationButtons.push_back(elButton);
|
pagination->paginationButtons.push_back(elButton);
|
||||||
@@ -1058,7 +1058,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
pagination->nextButton.hide();
|
pagination->nextButton.hide();
|
||||||
QObject::connect(&pagination->nextButton, &QToolButton::clicked, []() {
|
QObject::connect(&pagination->nextButton, &QToolButton::clicked, []() {
|
||||||
if (pagination->pages.size() > 0) {
|
if (pagination->pages.size() > 0) {
|
||||||
SwitchPage(pagination->currentPage + 1);
|
switchPage(pagination->currentPage + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1067,7 +1067,7 @@ QMainWindow *initMdemListWindow() {
|
|||||||
pagination->lastButton.hide();
|
pagination->lastButton.hide();
|
||||||
QObject::connect(&pagination->lastButton, &QToolButton::clicked, []() {
|
QObject::connect(&pagination->lastButton, &QToolButton::clicked, []() {
|
||||||
if (pagination->pages.size() > 0) {
|
if (pagination->pages.size() > 0) {
|
||||||
SwitchPage(pagination->pages.size() - 1);
|
switchPage(pagination->pages.size() - 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
hPagination->addStretch(1);
|
hPagination->addStretch(1);
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ void showFeedBackButtons() {
|
|||||||
|
|
||||||
void setupAnswerQuestion(MultiElementQuestion *question) {
|
void setupAnswerQuestion(MultiElementQuestion *question) {
|
||||||
lQuestionText->setText(
|
lQuestionText->setText(
|
||||||
QString::fromStdString(question->QuestionText)
|
QString::fromStdString(question->questionText)
|
||||||
);
|
);
|
||||||
lQuestionText->show();
|
lQuestionText->show();
|
||||||
auto ss = std::stringstream();
|
auto ss = std::stringstream();
|
||||||
@@ -333,11 +333,11 @@ void setupAnswerQuestion(MultiElementQuestion *question) {
|
|||||||
|
|
||||||
void setupOrderQuestion(MultiElementQuestion *question) {
|
void setupOrderQuestion(MultiElementQuestion *question) {
|
||||||
lQuestionText->setText(
|
lQuestionText->setText(
|
||||||
QString::fromStdString(question->QuestionText)
|
QString::fromStdString(question->questionText)
|
||||||
);
|
);
|
||||||
lQuestionText->show();
|
lQuestionText->show();
|
||||||
orderModel->clear();
|
orderModel->clear();
|
||||||
auto shuffledAnswers = question->Choices;
|
auto shuffledAnswers = question->choices;
|
||||||
std::shuffle(shuffledAnswers.begin(), shuffledAnswers.end(), rng);
|
std::shuffle(shuffledAnswers.begin(), shuffledAnswers.end(), rng);
|
||||||
for (auto answerEl: shuffledAnswers) {
|
for (auto answerEl: shuffledAnswers) {
|
||||||
auto *item = acquireItem();
|
auto *item = acquireItem();
|
||||||
@@ -355,7 +355,7 @@ void setupOrderQuestion(MultiElementQuestion *question) {
|
|||||||
for (size_t i = 0; i < orderModel->rowCount(); ++i) {
|
for (size_t i = 0; i < orderModel->rowCount(); ++i) {
|
||||||
auto item = orderModel->item(i, 0);
|
auto item = orderModel->item(i, 0);
|
||||||
auto text = item->text();
|
auto text = item->text();
|
||||||
auto isCorrect = question->Choices[i].Answer.compare(text.toStdString()) == 0;
|
auto isCorrect = question->choices[i].answer.compare(text.toStdString()) == 0;
|
||||||
if (isCorrect) {
|
if (isCorrect) {
|
||||||
item->setData(CORRECT, Qt::UserRole + 1);
|
item->setData(CORRECT, Qt::UserRole + 1);
|
||||||
} else {
|
} else {
|
||||||
@@ -375,7 +375,7 @@ void setupOrderQuestion(MultiElementQuestion *question) {
|
|||||||
|
|
||||||
void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
||||||
lQuestionText->setText(
|
lQuestionText->setText(
|
||||||
QString::fromStdString(question->QuestionText)
|
QString::fromStdString(question->questionText)
|
||||||
);
|
);
|
||||||
lQuestionText->show();
|
lQuestionText->show();
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
|||||||
[question](bool checked) {
|
[question](bool checked) {
|
||||||
for (size_t i = 0; i < multiChoiceModel->rowCount(); ++i) {
|
for (size_t i = 0; i < multiChoiceModel->rowCount(); ++i) {
|
||||||
auto item = multiChoiceModel->item(i, 0);
|
auto item = multiChoiceModel->item(i, 0);
|
||||||
auto isCorrect = question->Choices[i].IsCorrect == (item->checkState() == Qt::Checked);
|
auto isCorrect = question->choices[i].isCorrect == (item->checkState() == Qt::Checked);
|
||||||
if (isCorrect) {
|
if (isCorrect) {
|
||||||
item->setData(CORRECT, Qt::UserRole + 1);
|
item->setData(CORRECT, Qt::UserRole + 1);
|
||||||
} else {
|
} else {
|
||||||
@@ -421,7 +421,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
lQuestionText->setText(
|
lQuestionText->setText(
|
||||||
QString::fromStdString(question->QuestionText)
|
QString::fromStdString(question->questionText)
|
||||||
);
|
);
|
||||||
lQuestionText->show();
|
lQuestionText->show();
|
||||||
wGroupQuestion->show();
|
wGroupQuestion->show();
|
||||||
@@ -454,7 +454,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
|||||||
for (int k = 0; k < groupViews.size(); k++) {
|
for (int k = 0; k < groupViews.size(); k++) {
|
||||||
groupViews[k]->widget.hide();
|
groupViews[k]->widget.hide();
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < question->Groups.size(); i++) {
|
for (size_t i = 0; i < question->groups.size(); i++) {
|
||||||
GroupView *groupView;
|
GroupView *groupView;
|
||||||
if (i < groupViews.size()) {
|
if (i < groupViews.size()) {
|
||||||
groupView = groupViews[i];
|
groupView = groupViews[i];
|
||||||
@@ -463,7 +463,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
|||||||
groupViews.push_back(groupView);
|
groupViews.push_back(groupView);
|
||||||
}
|
}
|
||||||
groupView->label.setText(
|
groupView->label.setText(
|
||||||
QString::fromStdString(question->Groups[i].name)
|
QString::fromStdString(question->groups[i].name)
|
||||||
);
|
);
|
||||||
vGroups->addWidget(&groupView->widget);
|
vGroups->addWidget(&groupView->widget);
|
||||||
groupView->widget.show();
|
groupView->widget.show();
|
||||||
@@ -480,7 +480,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
|||||||
}
|
}
|
||||||
for (size_t i = 0; i < groupViews.size(); i++) {
|
for (size_t i = 0; i < groupViews.size(); i++) {
|
||||||
auto groupView = groupViews[i];
|
auto groupView = groupViews[i];
|
||||||
auto group = question->Groups[i];
|
auto group = question->groups[i];
|
||||||
for (int j = 0; j < groupView->itemModel.rowCount(); ++j) {
|
for (int j = 0; j < groupView->itemModel.rowCount(); ++j) {
|
||||||
auto item = groupView->itemModel.item(j, 0);
|
auto item = groupView->itemModel.item(j, 0);
|
||||||
auto itemText = item->text().toStdString();
|
auto itemText = item->text().toStdString();
|
||||||
@@ -586,7 +586,7 @@ void setupNextQuestion() {
|
|||||||
auto lastTrainedAt = practiceBuffer->trainedAt;
|
auto lastTrainedAt = practiceBuffer->trainedAt;
|
||||||
practiceBuffer->trainedAt = time;
|
practiceBuffer->trainedAt = time;
|
||||||
for (size_t i = 0; i < practiceBuffer->questions.size(); ++i) {
|
for (size_t i = 0; i < practiceBuffer->questions.size(); ++i) {
|
||||||
auto cooldownSeconds = practiceBuffer->questions[i]->Cooldown * 3600;
|
auto cooldownSeconds = practiceBuffer->questions[i]->cooldown * 3600;
|
||||||
auto cooldownEndsAt = lastTrainedAt + cooldownSeconds;
|
auto cooldownEndsAt = lastTrainedAt + cooldownSeconds;
|
||||||
if (i != currentQuestionIndex && cooldownEndsAt <= time) {
|
if (i != currentQuestionIndex && cooldownEndsAt <= time) {
|
||||||
questionCandidates.push_back(practiceBuffer->questions[i]);
|
questionCandidates.push_back(practiceBuffer->questions[i]);
|
||||||
@@ -595,7 +595,7 @@ void setupNextQuestion() {
|
|||||||
if (newCooldown < 0) {
|
if (newCooldown < 0) {
|
||||||
newCooldown = 0;
|
newCooldown = 0;
|
||||||
}
|
}
|
||||||
practiceBuffer->questions[i]->Cooldown = (double)newCooldown / 3600;
|
practiceBuffer->questions[i]->cooldown = (double)newCooldown / 3600;
|
||||||
}
|
}
|
||||||
if (questionCandidates.size() > 0) {
|
if (questionCandidates.size() > 0) {
|
||||||
auto i = randomIndex(&questionCandidates);
|
auto i = randomIndex(&questionCandidates);
|
||||||
@@ -635,7 +635,7 @@ void setCooldownHours(double cooldown) {
|
|||||||
time_t time = getTime();
|
time_t time = getTime();
|
||||||
practiceBuffer->trainedAt = time;
|
practiceBuffer->trainedAt = time;
|
||||||
auto question = practiceBuffer->questions[currentQuestionIndex];
|
auto question = practiceBuffer->questions[currentQuestionIndex];
|
||||||
question->Cooldown = cooldown;
|
question->cooldown = cooldown;
|
||||||
update(true);
|
update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,31 +21,31 @@ struct QuestionElement {
|
|||||||
std::string content;
|
std::string content;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string MultiElementQuestion::ToString() const {
|
std::string MultiElementQuestion::toString() const {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for (const auto& choice : Choices) {
|
for (const auto& choice : choices) {
|
||||||
char opener;
|
char opener;
|
||||||
if (type == MultiElementType::Order) {
|
if (type == MultiElementType::Order) {
|
||||||
opener = '^';
|
opener = '^';
|
||||||
} else if (choice.IsCorrect) {
|
} else if (choice.isCorrect) {
|
||||||
opener = '+';
|
opener = '+';
|
||||||
} else {
|
} else {
|
||||||
opener = '-';
|
opener = '-';
|
||||||
}
|
}
|
||||||
ss << opener << " " << choice.Answer << "; ";
|
ss << opener << " " << choice.answer << "; ";
|
||||||
}
|
}
|
||||||
return std::format(
|
return std::format(
|
||||||
"<Multiple element>\nsection:{}\nid:{}\n{}\n{}",
|
"<Multiple element>\nsection:{}\nid:{}\n{}\n{}",
|
||||||
Section,
|
section,
|
||||||
Cooldown,
|
cooldown,
|
||||||
QuestionText,
|
questionText,
|
||||||
ss.str()
|
ss.str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GroupQuestion::ToString() const {
|
std::string GroupQuestion::toString() const {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for (auto group: Groups) {
|
for (auto group: groups) {
|
||||||
ss << group.name << ": ";
|
ss << group.name << ": ";
|
||||||
for (auto el: group.elements) {
|
for (auto el: group.elements) {
|
||||||
ss << el << ", ";
|
ss << el << ", ";
|
||||||
@@ -54,9 +54,9 @@ std::string GroupQuestion::ToString() const {
|
|||||||
}
|
}
|
||||||
return std::format(
|
return std::format(
|
||||||
"<GroupQuestion>\nsection:{}\nid:{}\n{}\n{}",
|
"<GroupQuestion>\nsection:{}\nid:{}\n{}\n{}",
|
||||||
Section,
|
section,
|
||||||
Cooldown,
|
cooldown,
|
||||||
QuestionText,
|
questionText,
|
||||||
ss.str()
|
ss.str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -326,9 +326,9 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
if (questionElements.size() > 0) {
|
if (questionElements.size() > 0) {
|
||||||
if (isGroupQuestion) {
|
if (isGroupQuestion) {
|
||||||
auto *question = new GroupQuestion();
|
auto *question = new GroupQuestion();
|
||||||
question->Cooldown = cooldown;
|
question->cooldown = cooldown;
|
||||||
question->QuestionText = questionText;
|
question->questionText = questionText;
|
||||||
question->Section = section;
|
question->section = section;
|
||||||
int32_t k = -1;
|
int32_t k = -1;
|
||||||
for (size_t i = 0; i < questionElements.size(); ++i) {
|
for (size_t i = 0; i < questionElements.size(); ++i) {
|
||||||
auto questionElement = questionElements[i];
|
auto questionElement = questionElements[i];
|
||||||
@@ -336,10 +336,10 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
++k;
|
++k;
|
||||||
auto group = Group();
|
auto group = Group();
|
||||||
group.name = cleanContent(questionElement.content);
|
group.name = cleanContent(questionElement.content);
|
||||||
question->Groups.push_back(group);
|
question->groups.push_back(group);
|
||||||
} else {
|
} else {
|
||||||
if (k >= 0) {
|
if (k >= 0) {
|
||||||
question->Groups[k].elements.push_back(
|
question->groups[k].elements.push_back(
|
||||||
cleanContent(
|
cleanContent(
|
||||||
questionElement.content
|
questionElement.content
|
||||||
)
|
)
|
||||||
@@ -349,18 +349,18 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
}
|
}
|
||||||
questions.push_back(question);
|
questions.push_back(question);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::cout << question->ToString() << "\n";
|
std::cout << question->toString() << "\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto *question = new MultiElementQuestion();
|
auto *question = new MultiElementQuestion();
|
||||||
question->Cooldown = cooldown;
|
question->cooldown = cooldown;
|
||||||
question->QuestionText = cleanContent(questionText);
|
question->questionText = cleanContent(questionText);
|
||||||
question->Section = section;
|
question->section = section;
|
||||||
for (const auto& elem : questionElements) {
|
for (const auto& elem : questionElements) {
|
||||||
Choice choice;
|
Choice choice;
|
||||||
choice.Answer = cleanContent(elem.content);
|
choice.answer = cleanContent(elem.content);
|
||||||
choice.IsCorrect = !elem.isDash;
|
choice.isCorrect = !elem.isDash;
|
||||||
question->Choices.push_back(choice);
|
question->choices.push_back(choice);
|
||||||
}
|
}
|
||||||
questions.push_back(question);
|
questions.push_back(question);
|
||||||
if (isPlusQuestion) {
|
if (isPlusQuestion) {
|
||||||
@@ -371,7 +371,7 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
|||||||
question->type = MultiElementType::Regular;
|
question->type = MultiElementType::Regular;
|
||||||
}
|
}
|
||||||
if (debug) {
|
if (debug) {
|
||||||
std::cout << question->ToString() << "\n";
|
std::cout << question->toString() << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user