829 lines
29 KiB
C++
829 lines
29 KiB
C++
#include "windowrace.h"
|
|
#include "qvectorhelper.h"
|
|
#include "timemodel.h"
|
|
#include "ui_windowrace.h"
|
|
#include "unistd.h"
|
|
#include <QKeySequence>
|
|
#include <QObject>
|
|
#include <QShortcut>
|
|
#include <algorithm>
|
|
#include <boost/asio/detail/descriptor_ops.hpp>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <qchar.h>
|
|
#include <qdir.h>
|
|
#include <qglobal.h>
|
|
#include <qlist.h>
|
|
#include <qstringlistmodel.h>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
using std::string;
|
|
using std::vector;
|
|
|
|
WindowRace::WindowRace(DataBase * db, QWidget * parent)
|
|
: QMainWindow(parent), ui(new Ui::WindowRace) {
|
|
ui->setupUi(this);
|
|
|
|
this->ui->pBNextRace->setEnabled(false);
|
|
this->finished = false;
|
|
|
|
// should be read from db
|
|
this->enableLiveRanking = false;
|
|
if (!this->enableLiveRanking) {
|
|
this->ui->groupBox_15->hide();
|
|
}
|
|
|
|
this->wRennlisteSeted = false;
|
|
|
|
this->db = db;
|
|
|
|
vector<vector<QString>> res;
|
|
res = db->getData("select dauer from renndauer", 1);
|
|
this->fahrzeit = res.at(0).at(0).toInt();
|
|
|
|
string statement =
|
|
"select minimumroundtime from rennen order by id DESC limit 1";
|
|
res = db->getData(statement, 1);
|
|
this->minimumTime = res.at(0).at(0).toInt();
|
|
|
|
// fill minSecTimes vector
|
|
statement = "select minsec1, minsec2, minsec3, mindestRundenDauer from "
|
|
"renndauer order by id "
|
|
"DESC limit 1";
|
|
// cout << statement << endl;
|
|
res = db->getData(statement, 4);
|
|
this->minSecTime.append(res.at(0).at(0).toInt());
|
|
this->minSecTime.append(res.at(0).at(1).toInt());
|
|
this->minSecTime.append(res.at(0).at(2).toInt());
|
|
this->minSecTime.append(res.at(0).at(3).toInt());
|
|
|
|
QVectorHelper::minSec1 = this->minSecTime.at(0);
|
|
QVectorHelper::minSec2 = this->minSecTime.at(1);
|
|
QVectorHelper::minSec3 = this->minSecTime.at(2);
|
|
QVectorHelper::minTrackTime = this->minSecTime.at(3);
|
|
// cout << "Track time minimum:" << QVectorHelper::minTrackTime << endl;
|
|
|
|
firstTimeDea = true;
|
|
firstTimeShell = true;
|
|
started = false;
|
|
countdownValue = this->fahrzeit;
|
|
countdown = std::make_unique<Countdown>();
|
|
|
|
startAmpelThread = std::make_unique<Ampel>();
|
|
ampelCounter = 0;
|
|
|
|
ui->pBStart->setFocus();
|
|
|
|
paused = false;
|
|
|
|
Hardware = std::make_unique<HardwareSetup>(this->db);
|
|
Hardware->start();
|
|
|
|
QObject::connect(Hardware.get(), SIGNAL(Dea(int, int)), this,
|
|
SLOT(deaSlot(int, int)));
|
|
QObject::connect(Hardware.get(), SIGNAL(Shell(int, int)), this,
|
|
SLOT(shellSlot(int, int)));
|
|
QObject::connect(ui->pBStart, SIGNAL(clicked()), this, SLOT(go()));
|
|
QObject::connect(countdown.get(), SIGNAL(CountdownUpdate()), this,
|
|
SLOT(countdownUpdate()));
|
|
QObject::connect(startAmpelThread.get(), SIGNAL(ampelUpdate()), this,
|
|
SLOT(ampelSlot()));
|
|
QObject::connect(startAmpelThread.get(), SIGNAL(ampelUpdate()), this,
|
|
SLOT(laufcheck()));
|
|
QObject::connect(ui->pBBreak, SIGNAL(clicked()), this,
|
|
SLOT(breakCounter()));
|
|
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this,
|
|
SLOT(prepareNextRace()));
|
|
QObject::connect(this->ui->pBStop, SIGNAL(clicked()), this,
|
|
SLOT(stopClicked()));
|
|
|
|
ui->lCountdown->setText(timeWrapper(countdownValue));
|
|
|
|
// Ampelsetup
|
|
ui->WAmpel15->hide();
|
|
ui->WAmpel25->hide();
|
|
ui->hW15->setVisible(true);
|
|
ui->hW25->setVisible(true);
|
|
ui->WAmpel14->hide();
|
|
ui->WAmpel24->hide();
|
|
ui->hW14->setVisible(true);
|
|
ui->hW24->setVisible(true);
|
|
ui->WAmpel13->hide();
|
|
ui->WAmpel23->hide();
|
|
ui->hW13->setVisible(true);
|
|
ui->hW23->setVisible(true);
|
|
ui->WAmpel12->hide();
|
|
ui->WAmpel22->hide();
|
|
ui->hW12->setVisible(true);
|
|
ui->hw22->setVisible(true);
|
|
ui->WAmpel11->hide();
|
|
ui->WAmpel21->hide();
|
|
ui->hW11->setVisible(true);
|
|
ui->hW21->setVisible(true);
|
|
|
|
vector<vector<QString>> fahrer, autos, rennid, tableData;
|
|
statement = "select id_rennen from aktrennen group by id_rennen order by "
|
|
"id_rennen DESC limit 1";
|
|
rennid = this->db->getData(statement, 1);
|
|
this->renn_id = rennid[0][0].toInt();
|
|
statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid "
|
|
"from aktrennen where id_rennen like " +
|
|
rennid[0][0].toStdString() + " limit 1";
|
|
|
|
tableData = db->getData2(statement, 4);
|
|
|
|
statement = "select name from fahrer where id like " +
|
|
tableData.at(0).at(0).toStdString();
|
|
fahrer = this->db->getData2(statement, 1);
|
|
|
|
statement = "select name from AutoKonfiguration where id_auto like " +
|
|
tableData.at(0).at(1).toStdString() + " order by seit DESC";
|
|
autos = this->db->getData2(statement, 1);
|
|
|
|
this->ui->gbShell->setTitle("Shell, " + fahrer[0][0] + ", " + autos[0][0]);
|
|
|
|
statement = "select name from fahrer where id like " +
|
|
tableData.at(0).at(2).toStdString();
|
|
fahrer = this->db->getData2(statement, 1);
|
|
|
|
statement = "select name from AutoKonfiguration where id_auto like " +
|
|
tableData.at(0).at(3).toStdString() + " order by seit DESC";
|
|
autos = this->db->getData2(statement, 1);
|
|
|
|
this->ui->gbDea->setTitle("Dea, " + fahrer[0][0] + ", " + autos[0][0]);
|
|
|
|
this->shellDriverId = tableData.at(0).at(0).toInt();
|
|
this->shellCarId = tableData.at(0).at(1).toInt();
|
|
this->deaDriverId = tableData.at(0).at(2).toInt();
|
|
this->deaCarId = tableData.at(0).at(3).toInt();
|
|
|
|
// progressbar
|
|
this->ui->pbTime->setMaximum(this->fahrzeit);
|
|
this->ui->pbTime->setMinimum(0);
|
|
this->ui->pbTime->setTextVisible(false);
|
|
this->ui->pbTime->setStyleSheet("QProgressBar::chunk { color: #05B8CC;}");
|
|
this->ui->pbTime->setValue(0);
|
|
|
|
QKeySequence ks(Qt::Key_Return); // btw, this is numpad enter
|
|
this->keyReturn = std::make_shared<QShortcut>(ks, this);
|
|
QObject::connect(keyReturn.get(), SIGNAL(activated()), this,
|
|
SLOT(ReturnPress()));
|
|
|
|
// setup round / round
|
|
// request amount of races
|
|
statement = "select fahrershellid, autoshellid, fahrerdeaid, autodeaid "
|
|
"from aktrennen where id_rennen like " +
|
|
QString::number(this->renn_id).toStdString();
|
|
|
|
vector<vector<QString>> tableRaces;
|
|
tableRaces = db->getData(statement, 4);
|
|
this->ui->lRound->setText("1/" + QString::number(tableRaces.size()));
|
|
// QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close()));
|
|
|
|
if (this->enableLiveRanking) {
|
|
this->prepareLiveRanking();
|
|
}
|
|
}
|
|
|
|
void WindowRace::prepareLiveRanking() {
|
|
|
|
// cars
|
|
string statement = "SELECT autoShellId FROM aktRennen \
|
|
where id_rennen like " +
|
|
QString::number(this->renn_id).toStdString() + " \
|
|
GROUP BY autoShellId;";
|
|
|
|
vector<vector<QString>> QScarIds = this->db->getData2(statement, 1);
|
|
for (uint ids = 0; ids < QScarIds.size(); ids++) {
|
|
this->carIds.push_back(QScarIds.at(ids).at(0));
|
|
}
|
|
|
|
// drivers
|
|
statement = "SELECT fahrerShellId FROM aktRennen where id_rennen like " +
|
|
QString::number(this->renn_id).toStdString() +
|
|
" GROUP BY fahrerShellId;";
|
|
std::cout << statement << std::endl;
|
|
vector<vector<QString>> QSDriverIds = this->db->getData2(statement, 1);
|
|
for (uint ids = 0; ids < QSDriverIds.size(); ids++) {
|
|
this->driverIds.push_back(QSDriverIds.at(ids).at(0));
|
|
}
|
|
// this->driverIds = QSDriverIds.at(0);
|
|
this->lanes.push_back("1"); // shell
|
|
this->lanes.push_back("2"); // dea
|
|
}
|
|
|
|
int WindowRace::getAvgDriver(QString driverId) {
|
|
vector<int> times;
|
|
string statement;
|
|
vector<vector<QString>> result;
|
|
for (int lane = 1; lane <= 2; lane++) {
|
|
for (int car = 0; car < this->carIds.size(); car++) {
|
|
statement =
|
|
"SELECT zeit from Zeiten WHERE "
|
|
"id_fahrer like " +
|
|
driverId.toStdString() + " and id_auto like " +
|
|
QString::number(car).toStdString() + " and id_bahn like " +
|
|
QString::number(lane).toStdString() +
|
|
" and id_rennen "
|
|
"like " +
|
|
QString::number(this->renn_id).toStdString() + " and zeit > " +
|
|
QString::number(this->minimumTime).toStdString() +
|
|
" order by zeit asc ";
|
|
result = this->db->getData2(statement, 1);
|
|
if (result.size() > 0) {
|
|
if (result.at(0).size() > 0) {
|
|
times.push_back(result.at(0).at(0).toInt());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
int sum = 0;
|
|
for (int time : times) {
|
|
sum += time;
|
|
}
|
|
if (times.size() > 0) {
|
|
int avg = sum / times.size();
|
|
return avg;
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
void WindowRace::updateLiveRanking() {
|
|
// recalculate avg
|
|
vector<std::pair<int, QString>> avgTimes;
|
|
for (QString driver : driverIds) {
|
|
avgTimes.push_back(std::make_pair(this->getAvgDriver(driver),
|
|
this->getNameDriver(driver)));
|
|
// std::cout << driver.toStdString() << std::endl;
|
|
}
|
|
std::sort(std::begin(avgTimes), std::end(avgTimes),
|
|
[&](const auto & a, const auto & b) {
|
|
return std::get<0>(a) < std::get<0>(b);
|
|
});
|
|
QStringList driverRanking;
|
|
for (auto avgTime : avgTimes) {
|
|
|
|
// QString concat =
|
|
// std::get<1>(avgTime) + " " + QString::number(std::get<0>(avgTime));
|
|
driverRanking.push_back(std::get<1>(avgTime));
|
|
// cout << std::get<1>(avgTime).toStdString() << std::endl;
|
|
}
|
|
|
|
this->modelRanking.setStringList(driverRanking);
|
|
this->ui->lVRanking->setModel(&this->modelRanking);
|
|
}
|
|
|
|
QString WindowRace::getNameDriver(QString driverId) {
|
|
string statement =
|
|
"SELECT name FROM Fahrer WHERE id like " + driverId.toStdString();
|
|
vector<vector<QString>> result = this->db->getData2(statement, 1);
|
|
// std::cout << statement << std::endl;
|
|
return result.at(0).at(0);
|
|
}
|
|
|
|
void WindowRace::ReturnPress() {
|
|
// cout << "Return pressed" << endl;
|
|
if (this->ui->pBNextRace->isEnabled()) {
|
|
this->prepareNextRace();
|
|
if (this->wRennlisteSeted) {
|
|
this->wRennliste->changeSelection();
|
|
}
|
|
else {
|
|
cout << "Problem with racelist" << endl;
|
|
}
|
|
}
|
|
else {
|
|
if (started) {
|
|
this->breakCounter();
|
|
}
|
|
else {
|
|
this->go();
|
|
}
|
|
}
|
|
}
|
|
|
|
void WindowRace::prepareNextRace() {
|
|
|
|
this->ui->lDeaLaps->setText("0");
|
|
this->ui->lShellLaps->setText("0");
|
|
|
|
this->firstTimeShell = true;
|
|
this->firstTimeDea = true;
|
|
|
|
// this->ui->lWShellTime->clear();
|
|
// this->ui->lWDeaTime->clear();
|
|
|
|
this->ui->lBestZeitDea->setText("∞");
|
|
this->ui->lBestZeitShell->setText("∞");
|
|
this->ui->lCurRoundTimeShell->setText("∞");
|
|
this->ui->lCurRoundDea->setText("∞");
|
|
|
|
this->ui->lBridgeShell->setText("∞");
|
|
this->ui->lStraightShell->setText("∞");
|
|
this->ui->lCurvesShell->setText("∞");
|
|
this->ui->lDeltaShellTop->setText("∞");
|
|
|
|
this->ui->lBridgeDea->setText("∞");
|
|
this->ui->lStraightDea->setText("∞");
|
|
this->ui->lCurvesDea->setText("∞");
|
|
this->ui->lDeltaDeaTop->setText("∞");
|
|
|
|
this->VecShell.clear();
|
|
this->VecDea.clear();
|
|
|
|
// clear tableview shell
|
|
timeModelShell = std::make_unique<TimeModel>(VecShell, minSecTime);
|
|
ui->lWShellTime->setModel(timeModelShell.get());
|
|
|
|
// clear tableview dea
|
|
timeModelDea = std::make_unique<TimeModel>(VecDea, minSecTime);
|
|
ui->lWDeaTime->setModel(timeModelDea.get());
|
|
|
|
this->finished = false;
|
|
this->paused = false;
|
|
this->started = false;
|
|
this->countdownValue = this->fahrzeit;
|
|
this->ampelCounter = 0;
|
|
this->startAmpelThread->terminate();
|
|
this->countdown->terminate();
|
|
this->ui->pBNextRace->setEnabled(false);
|
|
this->ui->lCountdown->setText(timeWrapper(countdownValue));
|
|
|
|
// progressbar
|
|
this->ui->pbTime->setStyleSheet("QProgressBar::chunk { color: #05B8CC;}");
|
|
this->ui->pbTime->setValue(0);
|
|
|
|
// countdown
|
|
this->ui->lCountdown->setStyleSheet("QLabel { color: black; }");
|
|
|
|
// Ampel Setup
|
|
ui->WAmpel15->hide();
|
|
ui->WAmpel25->hide();
|
|
ui->hW15->setVisible(true);
|
|
ui->hW25->setVisible(true);
|
|
ui->WAmpel14->hide();
|
|
ui->WAmpel24->hide();
|
|
ui->hW14->setVisible(true);
|
|
ui->hW24->setVisible(true);
|
|
ui->WAmpel13->hide();
|
|
ui->WAmpel23->hide();
|
|
ui->hW13->setVisible(true);
|
|
ui->hW23->setVisible(true);
|
|
ui->WAmpel12->hide();
|
|
ui->WAmpel22->hide();
|
|
ui->hW12->setVisible(true);
|
|
ui->hw22->setVisible(true);
|
|
ui->WAmpel11->hide();
|
|
ui->WAmpel21->hide();
|
|
ui->hW11->setVisible(true);
|
|
ui->hW21->setVisible(true);
|
|
}
|
|
void WindowRace::setDriverAndCar(vector<QString> vec) {
|
|
this->ui->gbShell->setTitle("Shell, " + vec[0] + ", " + vec[1]);
|
|
this->ui->gbDea->setTitle("Dea, " + vec[2] + ", " + vec[3]);
|
|
}
|
|
void WindowRace::setRoundCounter(uint currentRound, uint rounds) {
|
|
this->ui->lRound->setText(QString::number(currentRound) + "/" +
|
|
QString::number(rounds));
|
|
}
|
|
void WindowRace::stopClicked() {
|
|
this->prepareNextRace();
|
|
}
|
|
|
|
void WindowRace::setWindowRennliste(WindowRennliste * ptrInstance) {
|
|
|
|
this->wRennliste = ptrInstance;
|
|
this->wRennlisteSeted = true;
|
|
QObject::connect(this->ui->pBNextRace, SIGNAL(clicked()), this->wRennliste,
|
|
SLOT(changeSelection()));
|
|
}
|
|
void WindowRace::setDriverAndCarId(vector<QString> vec) {
|
|
this->shellDriverId = vec.at(0).toInt();
|
|
this->shellCarId = vec.at(1).toInt();
|
|
this->deaDriverId = vec.at(2).toInt();
|
|
this->deaCarId = vec.at(3).toInt();
|
|
}
|
|
void WindowRace::closeEvent(QCloseEvent * event) {
|
|
countdown->setStop();
|
|
|
|
QMessageBox msgBox;
|
|
msgBox.setText("Wirklich schliessen?");
|
|
msgBox.setInformativeText("");
|
|
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
msgBox.setDefaultButton(QMessageBox::No);
|
|
int ret = msgBox.exec();
|
|
|
|
switch (ret) {
|
|
case QMessageBox::No:
|
|
event->ignore();
|
|
break;
|
|
case QMessageBox::Yes:
|
|
this->wRennliste->closeRaceList();
|
|
this->Hardware->setStop();
|
|
event->accept();
|
|
break;
|
|
default:
|
|
// should never be reached
|
|
break;
|
|
}
|
|
}
|
|
|
|
void WindowRace::breakCounter() {
|
|
if (!paused) {
|
|
paused = true;
|
|
ui->pBBreak->setText("Weiter");
|
|
}
|
|
else {
|
|
ui->pBBreak->setText("Pause");
|
|
paused = false;
|
|
}
|
|
}
|
|
|
|
void WindowRace::laufcheck() {
|
|
// std::cout << "thread lauft noch" << std::endl;
|
|
}
|
|
|
|
QString WindowRace::timeWrapper(long zahl) {
|
|
|
|
long min = zahl / 60;
|
|
int sec = zahl % 60;
|
|
QString sec_q;
|
|
if (sec < 10) {
|
|
sec_q = "0" + QString::number(sec);
|
|
}
|
|
else {
|
|
sec_q = QString::number(sec);
|
|
}
|
|
QString min_q = QString::number(min);
|
|
return min_q + ":" + sec_q;
|
|
}
|
|
|
|
void WindowRace::countdownUpdate() {
|
|
if (!paused) {
|
|
countdownValue -= 1;
|
|
if (countdownValue <= 15) {
|
|
this->ui->lCountdown->setStyleSheet("QLabel { color: red; }");
|
|
this->ui->pbTime->setStyleSheet(
|
|
"QProgressBar::chunk { background-color: orange; }");
|
|
// this->ui->pbTime->
|
|
}
|
|
if (countdownValue <= -1) {
|
|
this->finished = true;
|
|
this->wRennliste->setBesttime(QVectorHelper::getMin(VecShell),
|
|
QVectorHelper::getMin(this->VecDea));
|
|
this->ui->pBNextRace->setEnabled(true);
|
|
}
|
|
else {
|
|
ui->lCountdown->setText(timeWrapper(countdownValue));
|
|
this->ui->pbTime->setValue(this->fahrzeit -
|
|
static_cast<int>(countdownValue));
|
|
}
|
|
}
|
|
}
|
|
|
|
WindowRace::~WindowRace() {
|
|
this->startAmpelThread->setStop();
|
|
this->countdown->setStop();
|
|
this->Hardware->setStop();
|
|
usleep(1000000); // 1 second
|
|
|
|
delete ui;
|
|
}
|
|
void WindowRace::shellSlot(int time, int sector) {
|
|
if (started && !paused && !this->finished) {
|
|
if (firstTimeShell) {
|
|
firstTimeShell = false;
|
|
// counterShell.start();
|
|
}
|
|
else {
|
|
// long zeit = counterShell.getTime();
|
|
QVector<int> test;
|
|
switch (sector) {
|
|
case 1:
|
|
VecShell.append(QVector<int>());
|
|
VecShell.last().append(time);
|
|
|
|
// update tableview
|
|
|
|
test.append(1);
|
|
test.append(2);
|
|
test.append(3);
|
|
this->timeModelShell = std::make_unique<TimeModel>(
|
|
VecShell, minSecTime, test, this);
|
|
// this->ui->lWShellTime->setModel(this->timeModelShell);
|
|
ui->lWShellTime->setModel(this->timeModelShell.get());
|
|
|
|
this->ui->lBridgeShell->setText(QString::number(
|
|
static_cast<double>(QVectorHelper::getMinSec1(VecShell)) /
|
|
1000));
|
|
break;
|
|
|
|
case 2:
|
|
if (VecShell.size() > 0) {
|
|
if (VecShell.last().size() == 1) {
|
|
VecShell.last().append(time);
|
|
}
|
|
// update tableview
|
|
|
|
test.append(1);
|
|
test.append(2);
|
|
test.append(3);
|
|
this->timeModelShell = std::make_unique<TimeModel>(
|
|
VecShell, minSecTime, test, this);
|
|
// timeModelShell = new
|
|
// TimeModel(VecShell, this);
|
|
this->ui->lWShellTime->setModel(timeModelShell.get());
|
|
this->ui->lStraightShell->setText(QString::number(
|
|
static_cast<double>(
|
|
QVectorHelper::getMinSec2(VecShell)) /
|
|
1000));
|
|
}
|
|
break;
|
|
case 3:
|
|
if (VecShell.size() > 0) {
|
|
if (VecShell.last().size() == 2) {
|
|
VecShell.last().append(time);
|
|
VecShell.last().append(
|
|
QVectorHelper::getCurTime(VecShell.last()));
|
|
|
|
if (QVectorHelper::getCurTime(VecShell.last()) <=
|
|
QVectorHelper::getMin(VecShell)) {
|
|
ui->lBestZeitShell->setText(QString::number(
|
|
static_cast<double>(
|
|
QVectorHelper::getMin(VecShell)) /
|
|
1000));
|
|
}
|
|
ui->lCurRoundTimeShell->setText(QString::number(
|
|
static_cast<double>(
|
|
QVectorHelper::getCurTime(VecShell.last())) /
|
|
1000));
|
|
|
|
// update tableview
|
|
|
|
test.append(1);
|
|
test.append(2);
|
|
test.append(3);
|
|
this->timeModelShell = std::make_unique<TimeModel>(
|
|
VecShell, minSecTime, test, this);
|
|
// timeModelShell = new
|
|
// TimeModel(VecShell, this);
|
|
this->ui->lWShellTime->setModel(timeModelShell.get());
|
|
|
|
this->ui->lCurvesShell->setText(QString::number(
|
|
static_cast<double>(
|
|
QVectorHelper::getMinSec3(VecShell)) /
|
|
1000));
|
|
theoreticalMinShell = 9999;
|
|
theoreticalMinShell =
|
|
QVectorHelper::getMinSec1(VecShell) +
|
|
QVectorHelper::getMinSec2(VecShell) +
|
|
QVectorHelper::getMinSec3(VecShell);
|
|
deltaShell = QVectorHelper::getMin(VecShell) -
|
|
theoreticalMinShell;
|
|
this->ui->lDeltaShellTop->setText(QString::number(
|
|
static_cast<double>(deltaShell) / 1000));
|
|
|
|
if (VecShell.size() > 0) {
|
|
int zeit =
|
|
QVectorHelper::getCurTime(VecShell.last());
|
|
QString statement =
|
|
"insert into Zeiten (id_rennen, id_fahrer, "
|
|
"id_auto, id_bahn, zeit) values (" +
|
|
QString::number(this->renn_id) + ", " +
|
|
QString::number(this->shellDriverId) + ", " +
|
|
QString::number(this->shellCarId) + ", 1, " +
|
|
QString::number(zeit) + ")";
|
|
// cout << statement.toStdString() << endl;
|
|
|
|
this->db->setData(statement.toStdString());
|
|
}
|
|
}
|
|
}
|
|
// count valid laps
|
|
int validLaps = 0;
|
|
for (auto vec : VecShell) {
|
|
if (vec.size() == 4) {
|
|
validLaps += 1;
|
|
}
|
|
}
|
|
this->ui->lShellLaps->setText(QString::number(validLaps));
|
|
break;
|
|
}
|
|
|
|
ui->lWShellTime->scrollToBottom();
|
|
}
|
|
}
|
|
ui->lWShellTime->scrollToBottom();
|
|
ui->lWShellTime->horizontalHeader()->setSectionResizeMode(
|
|
QHeaderView::Stretch);
|
|
if (this->enableLiveRanking) {
|
|
this->updateLiveRanking();
|
|
}
|
|
}
|
|
void WindowRace::deaSlot(int time, int sector) {
|
|
if (started && !paused && !this->finished) {
|
|
if (firstTimeDea) {
|
|
firstTimeDea = false;
|
|
counterDea.start();
|
|
}
|
|
else {
|
|
|
|
switch (sector) {
|
|
case 1:
|
|
VecDea.push_back(QVector<int>());
|
|
VecDea.last().push_back(time);
|
|
cout << "Dea Sektor 1" << endl;
|
|
timeModelDea =
|
|
std::make_unique<TimeModel>(VecDea, minSecTime, this);
|
|
this->ui->lWDeaTime->setModel(timeModelDea.get());
|
|
|
|
this->ui->lBridgeDea->setText(QString::number(
|
|
static_cast<double>(QVectorHelper::getMinSec1(VecDea)) /
|
|
1000));
|
|
|
|
break;
|
|
case 2:
|
|
if (VecDea.size() > 0) {
|
|
if (VecDea.last().size() == 1) {
|
|
cout << time << sector << endl;
|
|
VecDea[VecDea.size() - 1].push_back(time);
|
|
timeModelDea = std::make_unique<TimeModel>(
|
|
VecDea, minSecTime, this);
|
|
this->ui->lWDeaTime->setModel(timeModelDea.get());
|
|
this->ui->lStraightDea->setText(QString::number(
|
|
static_cast<double>(
|
|
QVectorHelper::getMinSec2(VecDea)) /
|
|
1000));
|
|
}
|
|
else {
|
|
// VecDea[VecDea.size()-1].append(9999);
|
|
}
|
|
}
|
|
break;
|
|
case 3:
|
|
if (VecDea.size() > 0) {
|
|
// cout << "Time sec 3: " << time << endl;
|
|
if (VecDea.last().size() == 2) {
|
|
// cout << time << sector <<
|
|
// endl;
|
|
VecDea.last().push_back(time);
|
|
|
|
// add sum to vector
|
|
VecDea.last().push_back(
|
|
QVectorHelper::getCurTime(VecDea.last()));
|
|
|
|
timeModelDea = std::make_unique<TimeModel>(
|
|
VecDea, minSecTime, this);
|
|
this->ui->lWDeaTime->setModel(timeModelDea.get());
|
|
}
|
|
|
|
// best time on widget
|
|
cout << "cur time: "
|
|
<< QVectorHelper::getCurTime(VecDea.last()) << endl;
|
|
cout << "min time: " << QVectorHelper::getMin(VecDea)
|
|
<< endl;
|
|
if (QVectorHelper::getCurTime(VecDea.last()) <=
|
|
QVectorHelper::getMin(VecDea)) {
|
|
ui->lBestZeitDea->setText(QString::number(
|
|
static_cast<double>(QVectorHelper::getMin(VecDea)) /
|
|
1000));
|
|
}
|
|
ui->lCurRoundDea->setText(QString::number(
|
|
static_cast<double>(
|
|
QVectorHelper::getCurTime(VecDea.last())) /
|
|
1000));
|
|
}
|
|
|
|
this->ui->lCurvesDea->setText(QString::number(
|
|
static_cast<double>(QVectorHelper::getMinSec3(VecDea)) /
|
|
1000));
|
|
theoreticalMinDea = 9999;
|
|
theoreticalMinDea = QVectorHelper::getMinSec1(VecDea) +
|
|
QVectorHelper::getMinSec2(VecDea) +
|
|
QVectorHelper::getMinSec3(VecDea);
|
|
deltaDea = QVectorHelper::getMin(VecDea) - theoreticalMinDea;
|
|
this->ui->lDeltaDeaTop->setText(
|
|
QString::number(static_cast<double>(deltaDea) / 1000));
|
|
if (VecDea.size() > 0) {
|
|
int zeit = QVectorHelper::getCurTime(VecDea.last());
|
|
QString statement =
|
|
"insert into Zeiten (id_rennen, id_fahrer, "
|
|
"id_auto, id_bahn, zeit) values (" +
|
|
QString::number(this->renn_id) + ", " +
|
|
QString::number(this->deaDriverId) + ", " +
|
|
QString::number(this->deaCarId) + ", 2, " +
|
|
QString::number(zeit) + ")";
|
|
// cout << statement.toStdString() << endl;
|
|
this->db->setData(statement.toStdString());
|
|
ui->lWDeaTime->scrollToBottom();
|
|
}
|
|
// count valid laps
|
|
int validLaps = 0;
|
|
for (auto vec : VecDea) {
|
|
if (vec.size() == 4) {
|
|
validLaps += 1;
|
|
}
|
|
}
|
|
this->ui->lDeaLaps->setText(QString::number(validLaps));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
ui->lWDeaTime->scrollToBottom();
|
|
ui->lWDeaTime->horizontalHeader()->setSectionResizeMode(
|
|
QHeaderView::Stretch);
|
|
if (this->enableLiveRanking) {
|
|
this->updateLiveRanking();
|
|
}
|
|
}
|
|
|
|
long WindowRace::getMinimum(std::vector<long> a) {
|
|
long minimum = -1;
|
|
for (unsigned int i = 0; i < a.size(); i++) {
|
|
if (minimum < 0) {
|
|
if (a.at(i) >= this->minimumTime) {
|
|
minimum = a.at(i);
|
|
}
|
|
}
|
|
else {
|
|
if (a.at(i) < minimum && a.at(i) >= this->minimumTime) {
|
|
minimum = a.at(i);
|
|
}
|
|
}
|
|
}
|
|
return minimum;
|
|
}
|
|
void WindowRace::ampelSlot() {
|
|
if (ampelCounter == 5) {
|
|
ui->WAmpel15->hide();
|
|
ui->WAmpel25->hide();
|
|
ui->hW15->setVisible(true);
|
|
ui->hW25->setVisible(true);
|
|
ui->WAmpel14->hide();
|
|
ui->WAmpel24->hide();
|
|
ui->hW14->setVisible(true);
|
|
ui->hW24->setVisible(true);
|
|
ui->WAmpel13->hide();
|
|
ui->WAmpel23->hide();
|
|
ui->hW13->setVisible(true);
|
|
ui->hW23->setVisible(true);
|
|
ui->WAmpel12->hide();
|
|
ui->WAmpel22->hide();
|
|
ui->hW12->setVisible(true);
|
|
ui->hw22->setVisible(true);
|
|
ui->WAmpel11->hide();
|
|
ui->WAmpel21->hide();
|
|
ui->hW11->setVisible(true);
|
|
ui->hW21->setVisible(true);
|
|
startAmpelThread->terminate();
|
|
started = true;
|
|
countdown->start();
|
|
}
|
|
if (ampelCounter == 4) {
|
|
ampelCounter = 5;
|
|
ui->WAmpel15->setVisible(true);
|
|
ui->WAmpel25->setVisible(true);
|
|
ui->hW15->hide();
|
|
ui->hW25->hide();
|
|
}
|
|
if (ampelCounter == 3) {
|
|
ampelCounter = 4;
|
|
ui->WAmpel14->setVisible(true);
|
|
ui->WAmpel24->setVisible(true);
|
|
ui->hW14->hide();
|
|
ui->hW24->hide();
|
|
}
|
|
if (ampelCounter == 2) {
|
|
ampelCounter = 3;
|
|
ui->WAmpel13->setVisible(true);
|
|
ui->WAmpel23->setVisible(true);
|
|
ui->hW13->hide();
|
|
ui->hW23->hide();
|
|
}
|
|
if (ampelCounter == 1) {
|
|
ampelCounter = 2;
|
|
ui->WAmpel12->setVisible(true);
|
|
ui->WAmpel22->setVisible(true);
|
|
ui->hW12->hide();
|
|
ui->hw22->hide();
|
|
}
|
|
if (ampelCounter == 0) {
|
|
ampelCounter = 1;
|
|
ui->WAmpel11->setVisible(true);
|
|
ui->WAmpel21->setVisible(true);
|
|
ui->hW11->hide();
|
|
ui->hW21->hide();
|
|
}
|
|
}
|
|
|
|
void WindowRace::go() {
|
|
startAmpelThread->start();
|
|
}
|