From 834e5f07430f5bc92042e46f895474414c0c6283 Mon Sep 17 00:00:00 2001 From: Denis Date: Sat, 20 May 2023 12:47:55 +0300 Subject: [PATCH] add multithreading metrics call --- .../internal/service/src/SolutionService.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/server/internal/service/src/SolutionService.cpp b/server/internal/service/src/SolutionService.cpp index 1a1b3d2..bf63eac 100644 --- a/server/internal/service/src/SolutionService.cpp +++ b/server/internal/service/src/SolutionService.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "FileMethods.h" #include "MyCppAntlr.h" @@ -57,6 +58,7 @@ std::string SolutionService::setResultVerdict(float textBasedRes, float tokenBas std::pair SolutionService::getMaxTextResMetric(std::vector& solutions, const std::string& filedata, size_t userId, float treshold) { + // std::cout << "getMaxTextResMetric start" << std::endl; std::pair maxMatch = std::make_pair(0.0, 0); for (auto sol : solutions) { if (sol.getSenderId() == userId) { @@ -79,6 +81,7 @@ std::pair SolutionService::getMaxTextResMetric(std::vector SolutionService::getMaxTokenResMetric(std::vector& tokens, size_t userId, float treshold) { std::pair maxMatch = std::make_pair(0.0, 0); - + // std::cout << "getMaxTokenResMetric start" << std::endl; for (auto sol : solutions) { if (sol.getSenderId() == userId) { continue; @@ -110,13 +113,13 @@ std::pair SolutionService::getMaxTokenResMetric(std::vector fileExtension = FileMethods::checkFileExtension(filename); if (!fileExtension.second) { throw FileExtensionException("unknown file extension"); @@ -129,12 +132,20 @@ Solution SolutionService::createSolution(size_t userId, size_t taskId, const std std::time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); float treshold = taskRepo->getTaskById(taskId).value().getTreshhold(); - std::cout << "OK" << std::endl; std::vector solutions = solutionRepo->getSolutionsByTaskIdAndLanguage(taskId, fileExtension.first); - std::pair textBasedRes = getMaxTextResMetric(solutions, filedata, userId, treshold); - std::pair tokenBasedRes = getMaxTokenResMetric(solutions, tokensTypes, userId, treshold); + std::pair textBasedRes; + std::pair tokenBasedRes; + + std::thread t1([&textBasedRes, this, &solutions, &filedata, &userId, &treshold]() { + textBasedRes = getMaxTextResMetric(solutions, filedata, userId, treshold); + }); + std::thread t2([&tokenBasedRes, this, &solutions, &tokensTypes, &userId, &treshold]() { + tokenBasedRes = getMaxTokenResMetric(solutions, tokensTypes, userId, treshold); + }); + t1.join(); + t2.join(); size_t plagiatSolId = 1; if (textBasedRes.first > tokenBasedRes.first) { @@ -142,7 +153,6 @@ Solution SolutionService::createSolution(size_t userId, size_t taskId, const std } else { plagiatSolId = tokenBasedRes.second; } - std::cout << plagiatSolId << std::endl; std::string result = setResultVerdict(textBasedRes.first, tokenBasedRes.first, plagiatSolId, treshold); -- GitLab