diff --git a/.gitignore b/.gitignore index 90343c5..a975def 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,8 @@ moc_* *.exe *.out *.app + +# build dir +build/ + +.cache/ \ No newline at end of file diff --git a/.qtcreator/RennbahnZeitmessung.pro.user b/.qtcreator/RennbahnZeitmessung.pro.user new file mode 100644 index 0000000..96b6287 --- /dev/null +++ b/.qtcreator/RennbahnZeitmessung.pro.user @@ -0,0 +1,602 @@ + + + + + + EnvironmentId + {d65476ef-0da9-4e40-9dc0-9f44335f5fac} + + + ProjectExplorer.Project.ActiveTarget + 1 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {7c81c2d1-6cc4-440b-a1cc-9bba845de6c4} + 0 + 0 + 0 + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Desktop-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Desktop-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Desktop-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + RennbahnZeitmessung + + Qt4ProjectManager.Qt4RunConfiguration:/home/johannes/Dokumente/rennbahnc/RennbahnZeitmessung.pro + true + + RennbahnZeitmessung.pro + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Desktop-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.1 + + Qt 5.11.2 in PATH (System) + Qt 5.11.2 in PATH (System) + {a77f7da7-30ed-4ef3-9772-7ccbc14136dd} + 0 + 0 + 0 + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_11_2_in_PATH_System-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_11_2_in_PATH_System-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_11_2_in_PATH_System-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + RennbahnZeitmessung + + Qt4ProjectManager.Qt4RunConfiguration:/home/johannes/Dokumente/rennbahnc/RennbahnZeitmessung.pro + true + + RennbahnZeitmessung.pro + + /home/johannes/Dokumente/build-RennbahnZeitmessung-Qt_5_11_2_in_PATH_System-Debug + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/.qtcreator/project.json b/.qtcreator/project.json new file mode 100644 index 0000000..6bdef87 --- /dev/null +++ b/.qtcreator/project.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://download.qt.io/official_releases/qtcreator/latest/installer_source/jsonschemas/project.json", + "files.exclude": [ + ".qtcreator/project.json.user" + ] +} diff --git a/.qtcreator/project.json.user b/.qtcreator/project.json.user new file mode 100644 index 0000000..ae81912 --- /dev/null +++ b/.qtcreator/project.json.user @@ -0,0 +1,204 @@ + + + + + + EnvironmentId + {58d5f295-e411-40e7-bd3d-c0d49a9f363c} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + true + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 0 + 80 + true + true + 1 + 0 + false + true + false + 2 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + false + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 6 + true + + + + true + + 0 + + + + ProjectExplorer.Project.Target.0 + + Desktop + true + Desktop + Desktop + {6a8dca8f-10d1-4549-97a8-81fbe082dc03} + 0 + 0 + 0 + + /home/johannes/Dokumente/Rennbahn/build + + 0 + Erstellen + Erstellen + ProjectExplorer.BuildSteps.Build + + + 0 + Bereinigen + Bereinigen + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Vorgabe + WorkspaceProject.BuildConfiguration + 0 + 0 + + + 0 + Deployment + Deployment + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + + true + true + %{RunConfig:Executable:Path} + + 1 + + 1 + + + 0 + Deployment + Deployment + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + 0 + true + + 2 + + false + -e cpu-cycles --call-graph dwarf,4096 -F 250 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + + true + true + %{RunConfig:Executable:Path} + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + Version + 22 + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 98f832b..ba79f96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,15 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Boost bug? +# if(POLICY CMP0167) +# cmake_policy(SET CMP0167 OLD) +# endif() + #find_package(Boost REQUIRED COMPONENTS iostreams system filesystem) -find_package(Boost REQUIRED COMPONENTS iostreams system filesystem) +# find_package(Boost REQUIRED COMPONENTS iostreams system filesystem) +find_package(Boost REQUIRED COMPONENTS iostreams filesystem) find_package(fmt) diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index 6ce9eac..11d9eb8 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -21,12 +22,13 @@ #define USB_LED_OFF 0 #define USB_DATA_OUT 2 +// #define DEMO_MODE 1 // no hardware required + #define HARDWARE_VERSION 3 // V1 Parallelport // V2 USB Atmega8 // V3 STM32F07 - #define LIGHT_BARRIERS 6u // #define PORT_PATH "/dev/ttyACM0" @@ -273,77 +275,114 @@ void HardwareSetup::run() { } } #endif // ATMEGA - } // end HARDWARE_VERSION 2 + } // end HARDWARE_VERSION 2 else if (HARDWARE_VERSION == 3) { + +#ifndef DEMO_MODE TransCheck * received; sport = std::make_unique(PORT_PATH); TransCheck buffer = sport->read_frame(); +#else + uint ctr = 0; +#endif while (!this->stop) { +#ifndef DEMO_MODE usleep(100000); // 150ms buffer = sport->read_frame(); received = &buffer; - - /* - cout << buffer.begin << endl; - for (int i = 0; i < 6; i++) { - cout << "time: " << static_cast(buffer.data[i].time) - << endl; - cout << "id: " << static_cast(buffer.data[i].id) << endl; - cout << "update: " << static_cast(buffer.data[i].update) - << endl; - } - cout << static_cast(buffer.end) << endl; -*/ +#else + usleep(1000000); // 1s +#endif +#ifndef DEMO_MODE for (uint8_t i = 0; i < LIGHT_BARRIERS; i++) { - // fmt::print("{} ", TransStruct{buffer.data[i]}); // removed because build fails :( + + // fmt::print("{} ", TransStruct{buffer.data[i]}); // removed + // because build fails :( cout << "i: " << i << " time: " << static_cast(received->data[i].time) << " update: " << static_cast(received->data[i].update) << endl; if (received->data[i].update != NO_UPDATE) { switch (received->data[i].id) { + case SHELL_SECTOR_1: cout << "Shell Zeit 1: " << static_cast(received->data[i].time) << endl; - emit Shell(static_cast(received->data[i].time), SECTOR_1); + emit Shell(static_cast(received->data[i].time), + SECTOR_1); break; case DEA_SECTOR_1: cout << "Dea Zeit 1: " << static_cast(received->data[i].time) << endl; - emit Dea(static_cast(received->data[i].time), SECTOR_1); + emit Dea(static_cast(received->data[i].time), + SECTOR_1); break; case SHELL_SECTOR_2: cout << "Shell Zeit 2: " << static_cast(received->data[i].time) << endl; - emit Shell(static_cast(received->data[i].time), SECTOR_2); + emit Shell(static_cast(received->data[i].time), + SECTOR_2); break; case DEA_SECTOR_2: cout << "Dea Zeit 2: " << static_cast(received->data[i].time) << endl; - emit Dea(static_cast(received->data[i].time), SECTOR_2); + emit Dea(static_cast(received->data[i].time), + SECTOR_2); break; case SHELL_SECTOR_3: cout << "Shell Zeit 3: " << static_cast(received->data[i].time) << endl; - emit Shell(static_cast(received->data[i].time), SECTOR_3); + emit Shell(static_cast(received->data[i].time), + SECTOR_3); break; case DEA_SECTOR_3: cout << "Dea Zeit 3: " << static_cast(received->data[i].time) << endl; - emit Dea(static_cast(received->data[i].time), SECTOR_3); + emit Dea(static_cast(received->data[i].time), + SECTOR_3); break; } } } +#else + + switch (ctr) { + + case SHELL_SECTOR_1: + + emit Shell((ctr + 1) * 1000, SECTOR_1); + break; + case DEA_SECTOR_1: + emit Dea((ctr + 1) * 1000, SECTOR_1); + break; + case SHELL_SECTOR_2: + + emit Shell((ctr + 1) * 1000, SECTOR_2); + break; + case DEA_SECTOR_2: + emit Dea((ctr + 1) * 1000, SECTOR_2); + break; + case SHELL_SECTOR_3: + + emit Shell((ctr + 1) * 1000, SECTOR_3); + break; + case DEA_SECTOR_3: + emit Dea((ctr + 1) * 1000, SECTOR_3); + break; + } + ctr += 1; + ctr = ctr % LIGHT_BARRIERS; + +#endif // overwrite received data to prevent same data gets read one more // time; dummy data is array of zeros diff --git a/windowrace.cpp b/windowrace.cpp index 6c977f2..130fb21 100644 --- a/windowrace.cpp +++ b/windowrace.cpp @@ -6,9 +6,19 @@ #include #include #include +#include +#include #include +#include +#include +#include +#include +#include +#include #include #include +#include +#include using std::cout; using std::endl; @@ -167,6 +177,105 @@ WindowRace::WindowRace(DataBase * db, QWidget * parent) tableRaces = db->getData(statement, 4); this->ui->lRound->setText("1/" + QString::number(tableRaces.size())); // QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(close())); + 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> 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> 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 times; + string statement; + vector> 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> 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> result = this->db->getData2(statement, 1); + // std::cout << statement << std::endl; + return result.at(0).at(0); } void WindowRace::ReturnPress() { @@ -504,6 +613,7 @@ void WindowRace::shellSlot(int time, int sector) { ui->lWShellTime->scrollToBottom(); ui->lWShellTime->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch); + this->updateLiveRanking(); } void WindowRace::deaSlot(int time, int sector) { if (started && !paused && !this->finished) { @@ -617,6 +727,7 @@ void WindowRace::deaSlot(int time, int sector) { ui->lWDeaTime->scrollToBottom(); ui->lWDeaTime->horizontalHeader()->setSectionResizeMode( QHeaderView::Stretch); + this->updateLiveRanking(); } long WindowRace::getMinimum(std::vector a) { diff --git a/windowrace.h b/windowrace.h index 8487183..d05fd31 100644 --- a/windowrace.h +++ b/windowrace.h @@ -1,4 +1,4 @@ - #ifndef WINDOWRACE_H +#ifndef WINDOWRACE_H #define WINDOWRACE_H #include "ampel.h" @@ -12,6 +12,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -39,6 +43,14 @@ class WindowRace : public QMainWindow { int shellCarId; void closeEvent(QCloseEvent * event); + void updateLiveRanking(); + void prepareLiveRanking(); + int getAvgDriver(QString driverId); + QString getNameDriver(QString driverId); + QStringListModel modelRanking; + + QStringList QSLRanking; + // QStandardItemModel modelRanking; bool started; std::unique_ptr countdown; std::unique_ptr Hardware; @@ -65,6 +77,9 @@ class WindowRace : public QMainWindow { int renn_id; int minimumTime; QVector minSecTime; + vector carIds; + vector driverIds; + vector lanes; // sector top times int theoreticalMinShell; diff --git a/windowrace.ui b/windowrace.ui index 105e4b4..35d3b75 100644 --- a/windowrace.ui +++ b/windowrace.ui @@ -6,8 +6,8 @@ 0 0 - 1139 - 600 + 1482 + 676 @@ -26,7 +26,7 @@ - + @@ -217,7 +217,7 @@ - + @@ -235,7 +235,7 @@ - + @@ -612,12 +612,37 @@ - Qt::AlignCenter + Qt::AlignmentFlag::AlignCenter - + + + + + + + + Ranking + + + + + + + 14 + + + + + + + + + + + @@ -850,8 +875,8 @@ 0 0 - 1139 - 23 + 1482 + 26