mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
paramerized show time and debug in global config
Also some additional time measurements in the qt app.
This commit is contained in:
@@ -1,7 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
Result<ParseInfo> transpile(std::string fileContent, bool isDebug);
|
Result<ParseInfo> transpile(std::string fileContent);
|
||||||
|
|
||||||
std::string escapeText(std::string text);
|
std::string escapeText(std::string text);
|
||||||
std::string wrapText(std::string text, size_t width);
|
std::string wrapText(std::string text, size_t width);
|
||||||
|
|
||||||
|
|
||||||
|
extern std::chrono::high_resolution_clock::time_point start;
|
||||||
|
extern std::chrono::high_resolution_clock::time_point end;
|
||||||
|
std::string showTime(std::string label);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
extern bool debug;
|
extern bool debug;
|
||||||
|
extern bool showTimes;
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ QMainWindow *initMdemListWindow();
|
|||||||
#define SETTING_HARD "hard"
|
#define SETTING_HARD "hard"
|
||||||
#define SETTING_MEDIUM "medium"
|
#define SETTING_MEDIUM "medium"
|
||||||
#define SETTING_EASY "easy"
|
#define SETTING_EASY "easy"
|
||||||
|
#define SETTING_DEBUG "debug"
|
||||||
|
#define SETTING_SHOW_TIMES "showTimes"
|
||||||
|
|
||||||
#define TEXT_LG = 20
|
#define TEXT_LG = 20
|
||||||
#define ERROR_POOL_CHUNK 50
|
#define ERROR_POOL_CHUNK 50
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <qmainwindow.h>
|
#include <qmainwindow.h>
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
#include "mdemList.h"
|
#include "mdemList.h"
|
||||||
|
|
||||||
enum PracticeAlgorithm {
|
enum PracticeAlgorithm {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <format>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -64,6 +63,7 @@
|
|||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "mdemList.h"
|
#include "mdemList.h"
|
||||||
#include "trainWindow.h"
|
#include "trainWindow.h"
|
||||||
@@ -573,6 +573,7 @@ void reloadMdem(std::string path) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start = std::chrono::high_resolution_clock::now();
|
||||||
auto file = std::ifstream(path);
|
auto file = std::ifstream(path);
|
||||||
std::string content;
|
std::string content;
|
||||||
|
|
||||||
@@ -589,7 +590,13 @@ void reloadMdem(std::string path) {
|
|||||||
std::stringstream buffer;
|
std::stringstream buffer;
|
||||||
buffer << file.rdbuf();
|
buffer << file.rdbuf();
|
||||||
content = buffer.str();
|
content = buffer.str();
|
||||||
auto res = transpile(content, true);
|
end = std::chrono::high_resolution_clock::now();
|
||||||
|
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
|
||||||
|
if (showTimes) {
|
||||||
|
std::cout << showTime("I/O time") << std::endl;
|
||||||
|
}
|
||||||
|
debug = settings->value(SETTING_DEBUG).toBool();
|
||||||
|
auto res = transpile(content);
|
||||||
|
|
||||||
currentMdemBuffer->error = res.error.length() > 0;
|
currentMdemBuffer->error = res.error.length() > 0;
|
||||||
if (res.error == "") {
|
if (res.error == "") {
|
||||||
@@ -599,7 +606,11 @@ void reloadMdem(std::string path) {
|
|||||||
auto timezoneOffset = settings->value("timezone").toInt();
|
auto timezoneOffset = settings->value("timezone").toInt();
|
||||||
currentMdemBuffer->trainedAt = res.value.lastTrainedAt - 3600 * timezoneOffset;
|
currentMdemBuffer->trainedAt = res.value.lastTrainedAt - 3600 * timezoneOffset;
|
||||||
}
|
}
|
||||||
std::cout << std::format("Last trained at: {}", currentMdemBuffer->trainedAt) << std::endl;
|
|
||||||
|
if (settings->value(SETTING_DEBUG).toBool()) {
|
||||||
|
std::cout << std::format("Last trained at: {}", currentMdemBuffer->trainedAt)
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
currentMdemBuffer->questions = res.value.questions;
|
currentMdemBuffer->questions = res.value.questions;
|
||||||
errorView->box.hide();
|
errorView->box.hide();
|
||||||
@@ -676,7 +687,9 @@ void pickDirectory(QString directory) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setupEditorSave() {
|
void setupEditorSave() {
|
||||||
auto res = transpile(editor->text().toStdString(), true);
|
debug = settings->value(SETTING_DEBUG).toBool();
|
||||||
|
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
|
||||||
|
auto res = transpile(editor->text().toStdString());
|
||||||
if (res.error.length() > 0) {
|
if (res.error.length() > 0) {
|
||||||
currentMdemBuffer->trainedAt = 0;
|
currentMdemBuffer->trainedAt = 0;
|
||||||
for (auto question: res.value.questions) {
|
for (auto question: res.value.questions) {
|
||||||
@@ -740,12 +753,19 @@ void setupEditorSave() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void saveMdem() {
|
void saveMdem() {
|
||||||
|
start = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
auto filename = getFilename(currentMdem);
|
auto filename = getFilename(currentMdem);
|
||||||
std::ofstream out(currentMdem);
|
std::ofstream out(currentMdem);
|
||||||
out << outputMdem(currentMdemBuffer->questions, currentMdemBuffer->trainedAt);
|
out << outputMdem(currentMdemBuffer->questions, currentMdemBuffer->trainedAt);
|
||||||
updateMdemInfo(getFilename(currentMdem), false);
|
updateMdemInfo(getFilename(currentMdem), false);
|
||||||
}
|
end = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
showTimes = settings->value(SETTING_SHOW_TIMES).toBool();
|
||||||
|
if (showTimes) {
|
||||||
|
std::cout << showTime("Saving time") << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QMainWindow *initMdemListWindow() {
|
QMainWindow *initMdemListWindow() {
|
||||||
QMainWindow* window = new QMainWindow;
|
QMainWindow* window = new QMainWindow;
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#include <qabstractbutton.h>
|
#include <qabstractbutton.h>
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
#include <qboxlayout.h>
|
#include <qboxlayout.h>
|
||||||
|
#include <qcheckbox.h>
|
||||||
#include <qcombobox.h>
|
#include <qcombobox.h>
|
||||||
|
#include <qcoreevent.h>
|
||||||
#include <qdialog.h>
|
#include <qdialog.h>
|
||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
#include <qlayoutitem.h>
|
#include <qlayoutitem.h>
|
||||||
@@ -126,6 +128,12 @@ QWidget *initSettings () {
|
|||||||
easy->setRange(0, 100);
|
easy->setRange(0, 100);
|
||||||
formLayout->addRow("Easy:", easy);
|
formLayout->addRow("Easy:", easy);
|
||||||
|
|
||||||
|
auto* debug = new QCheckBox;
|
||||||
|
formLayout->addRow("Debug:", debug);
|
||||||
|
|
||||||
|
auto* showTimes = new QCheckBox;
|
||||||
|
formLayout->addRow("Show times in the console:", showTimes);
|
||||||
|
|
||||||
auto btnLayout = new QHBoxLayout;
|
auto btnLayout = new QHBoxLayout;
|
||||||
auto btnSaveSettings = new QPushButton("Save");
|
auto btnSaveSettings = new QPushButton("Save");
|
||||||
auto btnLoad = new QPushButton("Load");
|
auto btnLoad = new QPushButton("Load");
|
||||||
@@ -141,7 +149,9 @@ QWidget *initSettings () {
|
|||||||
notRemembered,
|
notRemembered,
|
||||||
hard,
|
hard,
|
||||||
medium,
|
medium,
|
||||||
easy
|
easy,
|
||||||
|
debug,
|
||||||
|
showTimes
|
||||||
]() {
|
]() {
|
||||||
mbaseInput->setText(settings->value(SETTING_MEMORYBASE).toString());
|
mbaseInput->setText(settings->value(SETTING_MEMORYBASE).toString());
|
||||||
characterWrap->setValue(settings->value(SETTING_CHARACTER_WRAP).toInt());
|
characterWrap->setValue(settings->value(SETTING_CHARACTER_WRAP).toInt());
|
||||||
@@ -150,6 +160,8 @@ QWidget *initSettings () {
|
|||||||
hard->setValue(settings->value(SETTING_HARD).toDouble());
|
hard->setValue(settings->value(SETTING_HARD).toDouble());
|
||||||
medium->setValue(settings->value(SETTING_MEDIUM).toDouble());
|
medium->setValue(settings->value(SETTING_MEDIUM).toDouble());
|
||||||
easy->setValue(settings->value(SETTING_EASY).toDouble());
|
easy->setValue(settings->value(SETTING_EASY).toDouble());
|
||||||
|
debug->setChecked(settings->value(SETTING_DEBUG).toBool() == true);
|
||||||
|
showTimes->setChecked(settings->value(SETTING_SHOW_TIMES).toBool() == true);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto updateSettingsLabel = [settingsLabel](bool isChanged) {
|
auto updateSettingsLabel = [settingsLabel](bool isChanged) {
|
||||||
@@ -188,6 +200,17 @@ QWidget *initSettings () {
|
|||||||
updateSettingsLabel(true);
|
updateSettingsLabel(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if (QCheckBox *checkBox = qobject_cast<QCheckBox*>(input)) {
|
||||||
|
QObject::connect(
|
||||||
|
checkBox,
|
||||||
|
QOverload<int>::of(&QCheckBox::stateChanged),
|
||||||
|
[settingsLabel, key, updateSettingsLabel](int state) {
|
||||||
|
bool value = (state == Qt::Checked);
|
||||||
|
if (settings->value(key).toBool() != value) {
|
||||||
|
updateSettingsLabel(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -198,6 +221,8 @@ QWidget *initSettings () {
|
|||||||
attachChangeListener(hard, SETTING_HARD);
|
attachChangeListener(hard, SETTING_HARD);
|
||||||
attachChangeListener(medium, SETTING_MEDIUM);
|
attachChangeListener(medium, SETTING_MEDIUM);
|
||||||
attachChangeListener(easy, SETTING_EASY);
|
attachChangeListener(easy, SETTING_EASY);
|
||||||
|
attachChangeListener(debug, SETTING_DEBUG);
|
||||||
|
attachChangeListener(showTimes, SETTING_SHOW_TIMES);
|
||||||
|
|
||||||
auto saveSettings = [
|
auto saveSettings = [
|
||||||
mbaseInput,
|
mbaseInput,
|
||||||
@@ -207,6 +232,8 @@ QWidget *initSettings () {
|
|||||||
hard,
|
hard,
|
||||||
medium,
|
medium,
|
||||||
easy,
|
easy,
|
||||||
|
debug,
|
||||||
|
showTimes,
|
||||||
updateSettingsLabel
|
updateSettingsLabel
|
||||||
]() {
|
]() {
|
||||||
settings->setValue(SETTING_MEMORYBASE, mbaseInput->text());
|
settings->setValue(SETTING_MEMORYBASE, mbaseInput->text());
|
||||||
@@ -216,6 +243,8 @@ QWidget *initSettings () {
|
|||||||
settings->setValue(SETTING_HARD, hard->value());
|
settings->setValue(SETTING_HARD, hard->value());
|
||||||
settings->setValue(SETTING_MEDIUM, medium->value());
|
settings->setValue(SETTING_MEDIUM, medium->value());
|
||||||
settings->setValue(SETTING_EASY, easy->value());
|
settings->setValue(SETTING_EASY, easy->value());
|
||||||
|
settings->setValue(SETTING_DEBUG, debug->isChecked());
|
||||||
|
settings->setValue(SETTING_SHOW_TIMES, showTimes->isChecked());
|
||||||
updateSettingsLabel(false);
|
updateSettingsLabel(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -304,8 +304,8 @@ void setupAnswerQuestion(MultiElementQuestion *question) {
|
|||||||
);
|
);
|
||||||
lQuestionText->show();
|
lQuestionText->show();
|
||||||
auto ss = std::stringstream();
|
auto ss = std::stringstream();
|
||||||
for (auto answerEl: question->Choices) {
|
for (auto answerEl: question->choices) {
|
||||||
ss << std::format("- {}", answerEl.Answer) << std::endl;
|
ss << std::format("- {}", answerEl.answer) << std::endl;
|
||||||
}
|
}
|
||||||
answerText->setText(
|
answerText->setText(
|
||||||
QString::fromStdString(ss.str())
|
QString::fromStdString(ss.str())
|
||||||
@@ -344,7 +344,7 @@ void setupOrderQuestion(MultiElementQuestion *question) {
|
|||||||
item->setData(NEUTRAL, Qt::UserRole + 1);
|
item->setData(NEUTRAL, Qt::UserRole + 1);
|
||||||
item->setData(QVariant(), Qt::CheckStateRole);
|
item->setData(QVariant(), Qt::CheckStateRole);
|
||||||
item->setCheckable(false);
|
item->setCheckable(false);
|
||||||
item->setText(QString::fromStdString(answerEl.Answer));
|
item->setText(QString::fromStdString(answerEl.answer));
|
||||||
orderModel->appendRow(item);
|
orderModel->appendRow(item);
|
||||||
}
|
}
|
||||||
orderList->show();
|
orderList->show();
|
||||||
@@ -380,9 +380,9 @@ void setupMultiChoiceQuestion(MultiElementQuestion *question) {
|
|||||||
lQuestionText->show();
|
lQuestionText->show();
|
||||||
|
|
||||||
multiChoiceModel->clear();
|
multiChoiceModel->clear();
|
||||||
for (auto answerEl: question->Choices) {
|
for (auto answerEl: question->choices) {
|
||||||
auto *item = acquireItem();
|
auto *item = acquireItem();
|
||||||
item->setText(QString::fromStdString(answerEl.Answer));
|
item->setText(QString::fromStdString(answerEl.answer));
|
||||||
item->setData(NEUTRAL, Qt::UserRole + 1);
|
item->setData(NEUTRAL, Qt::UserRole + 1);
|
||||||
item->setCheckable(true);
|
item->setCheckable(true);
|
||||||
item->setCheckState(Qt::CheckState::Unchecked);
|
item->setCheckState(Qt::CheckState::Unchecked);
|
||||||
@@ -426,7 +426,7 @@ void setupGroupQuestion(GroupQuestion *question) {
|
|||||||
lQuestionText->show();
|
lQuestionText->show();
|
||||||
wGroupQuestion->show();
|
wGroupQuestion->show();
|
||||||
|
|
||||||
for (auto group: question->Groups) {
|
for (auto group: question->groups) {
|
||||||
for (auto itemText: group.elements) {
|
for (auto itemText: group.elements) {
|
||||||
auto *qItem = acquireItem();
|
auto *qItem = acquireItem();
|
||||||
qItem->setData(NEUTRAL, Qt::UserRole + 1);
|
qItem->setData(NEUTRAL, Qt::UserRole + 1);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ add_library(
|
|||||||
api
|
api
|
||||||
lexer.cpp
|
lexer.cpp
|
||||||
parser.cpp
|
parser.cpp
|
||||||
time.cpp
|
|
||||||
api.cpp
|
api.cpp
|
||||||
stringUtils.cpp
|
stringUtils.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <chrono>
|
#include <cmath>
|
||||||
|
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
#include "lexer.h"
|
#include "lexer.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "time.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#define TABWIDTH 4
|
#define TABWIDTH 4
|
||||||
|
|
||||||
bool debug;
|
bool debug = false;
|
||||||
|
bool showTimes = false;
|
||||||
std::chrono::high_resolution_clock::time_point start;
|
std::chrono::high_resolution_clock::time_point start;
|
||||||
std::chrono::high_resolution_clock::time_point end;
|
std::chrono::high_resolution_clock::time_point end;
|
||||||
|
|
||||||
@@ -88,10 +89,9 @@ std::string escapeText(std::string text) {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<ParseInfo> transpile(std::string fileContent, bool isDebug) {
|
Result<ParseInfo> transpile(std::string fileContent) {
|
||||||
start = std::chrono::high_resolution_clock::now();
|
start = std::chrono::high_resolution_clock::now();
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
debug = isDebug;
|
|
||||||
|
|
||||||
auto lexRes = tokenizeMdem(fileContent);
|
auto lexRes = tokenizeMdem(fileContent);
|
||||||
auto tokens = lexRes.value;
|
auto tokens = lexRes.value;
|
||||||
@@ -122,6 +122,16 @@ Result<ParseInfo> transpile(std::string fileContent, bool isDebug) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
showTime("Transpilation time");
|
if (showTimes) {
|
||||||
|
std::cout << showTime("Transpilation time") << std::endl;
|
||||||
|
}
|
||||||
return {questions};
|
return {questions};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string showTime(std::string label) {
|
||||||
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||||
|
double_t seconds = (double_t) duration.count() / 1000000;
|
||||||
|
double_t miliseconds = (double_t) duration.count() / 1000;
|
||||||
|
return std::format("{}: {:.3f} s, {:.3f} ms", label, seconds, miliseconds);
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#include "time.h"
|
#include "config.h"
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
|
|
||||||
std::string readFile(const std::string& filePath) {
|
std::string readFile(const std::string& filePath) {
|
||||||
@@ -27,11 +27,11 @@ std::string readFile(const std::string& filePath) {
|
|||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
|
|
||||||
bool debug = false;
|
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
auto option = std::string(argv[1]);
|
auto option = std::string(argv[1]);
|
||||||
if (option == "--debug") {
|
if (option == "--debug") {
|
||||||
debug = true;
|
debug = true;
|
||||||
|
showTimes = true;
|
||||||
} else {
|
} else {
|
||||||
std::cout << std::format("Unrecognized option: {}", option) << std::endl;
|
std::cout << std::format("Unrecognized option: {}", option) << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -47,9 +47,11 @@ int main(int argc, char* argv[]) {
|
|||||||
try {
|
try {
|
||||||
std::string fileContent = readFile(filePath);
|
std::string fileContent = readFile(filePath);
|
||||||
end = std::chrono::high_resolution_clock::now();
|
end = std::chrono::high_resolution_clock::now();
|
||||||
showTime("I/O time");
|
if (showTimes) {
|
||||||
|
std::cout << showTime("I/O time") << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
auto res = transpile(fileContent, debug);
|
auto res = transpile(fileContent);
|
||||||
auto questions = res.value.questions;
|
auto questions = res.value.questions;
|
||||||
if (res.error.length() > 0) {
|
if (res.error.length() > 0) {
|
||||||
std::cout << std::format(
|
std::cout << std::format(
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
#include <cmath>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "time.h"
|
|
||||||
|
|
||||||
void showTime(std::string label) {
|
|
||||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
|
||||||
double_t msDuration = (double_t) duration.count() / 1000;
|
|
||||||
std::cout << std::format("{}: {:.3f} ms", label, msDuration) << std::endl;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include<chrono>
|
|
||||||
|
|
||||||
extern std::chrono::high_resolution_clock::time_point start;
|
|
||||||
extern std::chrono::high_resolution_clock::time_point end;
|
|
||||||
|
|
||||||
void showTime(std::string label);
|
|
||||||
Reference in New Issue
Block a user