<commit_before>#include "inputfield.h"
#include <cstdio>
#include <QKeyEvent>
#include <QFile>
#include <QDebug>
#include <QDir>
#include <QTimer>
#include <QAction>
#include <QScrollBar>

InputField::~InputField()
{
#ifdef _WIN32
    this->neo20->kill();
    delete this->neo20;
    qDebug() << "qwertz keylayout active";
#endif
#ifdef __linux__
    QProcess setxkbmap;
    QStringList args;
    args << "-c" << "setxkbmap de && xset r 51";
    setxkbmap.start(QString("/bin/bash"), args);
    setxkbmap.waitForFinished();
    qDebug() << "qwertz keylayout active";
#endif
    delete this->settings;
    delete this->sound;
    if (this->words == NULL)
    {
        delete this->words;
    }
    delete this->timeoutTimer;
    delete this->sessionTimer;
    delete this->guiUpdateTimer;
    delete this->elapsed;
}

InputField::InputField(QObject *parent) :
    QTextEdit((QWidget*)parent),
    neo1(QString("graphics")+QDir::separator()+QString("neo1.png")),
    neo2(QString("graphics")+QDir::separator()+QString("neo2.png")),
    neo3(QString("graphics")+QDir::separator()+QString("neo3.png")),
    words(NULL)
{
#ifdef _WIN32
    this->neo20 = new QProcess();
    this->neo20->start(QString("external")+QDir::separator()+QString("neo20.exe"));
    qDebug() << "neo keylayout active";
#endif
#ifdef __linux__
    QProcess setxkbmap;
    QStringList args;
    args << "-c" << "setxkbmap lv && xmodmap external/neo_de.xmodmap && xset -r 51";
    setxkbmap.start(QString("/bin/bash"), args);
    setxkbmap.waitForFinished();
    qDebug() << "neo keylayout active";
#endif
    display = NULL;
    corrects = 0;
    mistakes = 0;
    errorstate = false;
    setLineWrapMode(QTextEdit::NoWrap);
    this->settings = new QSettings("settings.ini", QSettings::IniFormat);
    if (!this->settings->contains("statsCounter"))
    {
        this->settings->setValue("statsCounter", 0);
    }
    if (!this->settings->contains("blockOnError"))
    {
        this->settings->setValue("blockOnError", true);
    }
    if (!this->settings->contains("playErrorSound"))
    {
        this->settings->setValue("playErrorSound", true);
    }
    if (!this->settings->contains("fontSize"))
    {
        this->settings->setValue("fontSize", 20);
    }
    if (!this->settings->contains("goodLineA"))
    {
        this->settings->setValue("goodLineA", 120);
    }
    if (!this->settings->contains("goodLineE"))
    {
        this->settings->setValue("goodLineE", 2);
    }
    if (!this->settings->contains("badLineA"))
    {
        this->settings->setValue("badLineA", 100);
    }
    if (!this->settings->contains("badLineE"))
    {
        this->settings->setValue("badLineE", 3);
    }
    if (!this->settings->contains("pow"))
    {
        this->settings->setValue("pow", 2.0);
    }
    if (!this->settings->contains("visualErrorFeedback"))
    {
        this->settings->setValue("visualErrorFeedback", true);
    }
    if (!this->settings->contains("influencingSessions"))
    {
        this->settings->setValue("influencingSessions", 5);
    }
    if (!this->settings->contains("sessionDuration"))
    {
        this->settings->setValue("sessionDuration", 300);
    }
    if (!this->settings->contains("timeout"))
    {
        this->settings->setValue("timeout", 3000);
    }
    qDebug() << "generated missing settings";
    this->fontSize = this->settings->value("fontSize").toInt();
    this->sound = new QSound(QString("sounds")+QDir::separator()+QString("err.wav"));
    this->timeoutTimer = new QTimer();
    this->guiUpdateTimer = new QTimer();
    this->sessionTimer = new QTimer();
    this->elapsed = new QElapsedTimer();
    this->running = false;
    connect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
    connect(this->guiUpdateTimer, SIGNAL(timeout()), this, SLOT(handleGuiUpdate()));
    connect(this->sessionTimer, SIGNAL(timeout()), this, SLOT(handleSessionEnd()));
    connect(this, SIGNAL(correctTextTyped()), this, SLOT(scrollDisplay()));
}

void InputField::scrollDisplay()
{
    emit scrollDisplay2((int)(((float)this->correctTextLength/this->display->toPlainText().split("\n").at(0).length())*this->display->horizontalScrollBar()->maximum()));
}

void InputField::handleTimeout()
{
    this->timeout = true;
    this->sessionTimer->stop();
    this->stats->timeout();
    this->timeUntilEnd -= this->elapsed->elapsed();
    this->elapsed->restart();
}

void InputField::handleGuiUpdate()
{
    if (!this->timeout)
    {
        this->timeUntilEnd -= this->elapsed->elapsed();
        this->elapsed->restart();
    }
    this->timeLeftLabel->setText(QString::number(this->timeUntilEnd/1000, 10)+" Sekunden");
    this->hitsLabel->setText(QString::number(corrects, 10)+" Richtige");
    this->mistakesLabel->setText(QString::number(mistakes, 10)+" Fehler");
    if (this->settings->value("sessionDuration").toInt()-this->timeUntilEnd/1000 == 0)
    {
        this->hitsPerMinuteLabel->setText("0 Anschlge/Minute");
    }
    else
    {
        this->hitsPerMinuteLabel->setText(QString::number((int)((corrects+mistakes)/(((float)(this->settings->value("sessionDuration").toInt()-this->timeUntilEnd/1000))/60)), 10)+" Anschlge/Minute");
    }
    if (corrects == 0)
    {
        this->mistakesRateLabel->setText("0 % Fehlerrate");
    }
    else
    {<commit_msg>anschläge -> zeichen<commit_after>#include "inputfield.h"
#include <cstdio>
#include <QKeyEvent>
#include <QFile>
#include <QDebug>
#include <QDir>
#include <QTimer>
#include <QAction>
#include <QScrollBar>

InputField::~InputField()
{
#ifdef _WIN32
    this->neo20->kill();
    delete this->neo20;
    qDebug() << "qwertz keylayout active";
#endif
#ifdef __linux__
    QProcess setxkbmap;
    QStringList args;
    args << "-c" << "setxkbmap de && xset r 51";
    setxkbmap.start(QString("/bin/bash"), args);
    setxkbmap.waitForFinished();
    qDebug() << "qwertz keylayout active";
#endif
    delete this->settings;
    delete this->sound;
    if (this->words == NULL)
    {
        delete this->words;
    }
    delete this->timeoutTimer;
    delete this->sessionTimer;
    delete this->guiUpdateTimer;
    delete this->elapsed;
}

InputField::InputField(QObject *parent) :
    QTextEdit((QWidget*)parent),
    neo1(QString("graphics")+QDir::separator()+QString("neo1.png")),
    neo2(QString("graphics")+QDir::separator()+QString("neo2.png")),
    neo3(QString("graphics")+QDir::separator()+QString("neo3.png")),
    words(NULL)
{
#ifdef _WIN32
    this->neo20 = new QProcess();
    this->neo20->start(QString("external")+QDir::separator()+QString("neo20.exe"));
    qDebug() << "neo keylayout active";
#endif
#ifdef __linux__
    QProcess setxkbmap;
    QStringList args;
    args << "-c" << "setxkbmap lv && xmodmap external/neo_de.xmodmap && xset -r 51";
    setxkbmap.start(QString("/bin/bash"), args);
    setxkbmap.waitForFinished();
    qDebug() << "neo keylayout active";
#endif
    display = NULL;
    corrects = 0;
    mistakes = 0;
    errorstate = false;
    setLineWrapMode(QTextEdit::NoWrap);
    this->settings = new QSettings("settings.ini", QSettings::IniFormat);
    if (!this->settings->contains("statsCounter"))
    {
        this->settings->setValue("statsCounter", 0);
    }
    if (!this->settings->contains("blockOnError"))
    {
        this->settings->setValue("blockOnError", true);
    }
    if (!this->settings->contains("playErrorSound"))
    {
        this->settings->setValue("playErrorSound", true);
    }
    if (!this->settings->contains("fontSize"))
    {
        this->settings->setValue("fontSize", 20);
    }
    if (!this->settings->contains("goodLineA"))
    {
        this->settings->setValue("goodLineA", 120);
    }
    if (!this->settings->contains("goodLineE"))
    {
        this->settings->setValue("goodLineE", 2);
    }
    if (!this->settings->contains("badLineA"))
    {
        this->settings->setValue("badLineA", 100);
    }
    if (!this->settings->contains("badLineE"))
    {
        this->settings->setValue("badLineE", 3);
    }
    if (!this->settings->contains("pow"))
    {
        this->settings->setValue("pow", 2.0);
    }
    if (!this->settings->contains("visualErrorFeedback"))
    {
        this->settings->setValue("visualErrorFeedback", true);
    }
    if (!this->settings->contains("influencingSessions"))
    {
        this->settings->setValue("influencingSessions", 5);
    }
    if (!this->settings->contains("sessionDuration"))
    {
        this->settings->setValue("sessionDuration", 300);
    }
    if (!this->settings->contains("timeout"))
    {
        this->settings->setValue("timeout", 3000);
    }
    qDebug() << "generated missing settings";
    this->fontSize = this->settings->value("fontSize").toInt();
    this->sound = new QSound(QString("sounds")+QDir::separator()+QString("err.wav"));
    this->timeoutTimer = new QTimer();
    this->guiUpdateTimer = new QTimer();
    this->sessionTimer = new QTimer();
    this->elapsed = new QElapsedTimer();
    this->running = false;
    connect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
    connect(this->guiUpdateTimer, SIGNAL(timeout()), this, SLOT(handleGuiUpdate()));
    connect(this->sessionTimer, SIGNAL(timeout()), this, SLOT(handleSessionEnd()));
    connect(this, SIGNAL(correctTextTyped()), this, SLOT(scrollDisplay()));
}

void InputField::scrollDisplay()
{
    emit scrollDisplay2((int)(((float)this->correctTextLength/this->display->toPlainText().split("\n").at(0).length())*this->display->horizontalScrollBar()->maximum()));
}

void InputField::handleTimeout()
{
    this->timeout = true;
    this->sessionTimer->stop();
    this->stats->timeout();
    this->timeUntilEnd -= this->elapsed->elapsed();
    this->elapsed->restart();
}

void InputField::handleGuiUpdate()
{
    if (!this->timeout)
    {
        this->timeUntilEnd -= this->elapsed->elapsed();
        this->elapsed->restart();
    }
    this->timeLeftLabel->setText(QString::number(this->timeUntilEnd/1000, 10)+" Sekunden");
    this->hitsLabel->setText(QString::number(corrects, 10)+" Richtige");
    this->mistakesLabel->setText(QString::number(mistakes, 10)+" Fehler");
    if (this->settings->value("sessionDuration").toInt()-this->timeUntilEnd/1000 == 0)
    {
        this->hitsPerMinuteLabel->setText("0 Zeichen/Minute");
    }
    else
    {
        this->hitsPerMinuteLabel->setText(QString::number((int)((corrects+mistakes)/(((float)(this->settings->value("sessionDuration").toInt()-this->timeUntilEnd/1000))/60)), 10)+" Zeichen/Minute");
    }
    if (corrects == 0)
    {
        this->mistakesRateLabel->setText("0 % Fehlerrate");
    }
    else
    {
{'fraction_non_alphanumeric': 0.18841262364578426, 'fraction_numerical': 0.01413094677343382, 'mean_word_length': 3.821071752951862, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 260, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4358060', 'n_tokens_mistral': 3531, 'n_tokens_neox': 3420, 'n_words': 513}