From fe0c604486d4f04fd15dece01800819b8984539b Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 7 Jul 2023 23:20:36 +0200 Subject: [PATCH] =?UTF-8?q?[#897=20fixed]=20=C5=A0tafety:=20Chybn=C3=BD=20?= =?UTF-8?q?tisk=20v=C3=BDsledk=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../libquickeventcore/src/runstatus.cpp | 4 +- .../libquickeventcore/src/runstatus.h | 2 +- .../plugins/Relays/src/relaysplugin.cpp | 62 ++++++++++++------- quickevent/app/quickevent/src/appversion.h | 2 +- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/libquickevent/libquickeventcore/src/runstatus.cpp b/libquickevent/libquickeventcore/src/runstatus.cpp index a46313e6b..2c9a1e01e 100644 --- a/libquickevent/libquickeventcore/src/runstatus.cpp +++ b/libquickevent/libquickeventcore/src/runstatus.cpp @@ -38,10 +38,10 @@ RunStatus RunStatus::fromTreeTableRow(const qf::core::utils::TreeTableRow &ttr) bool RunStatus::isOk() const { - return !(m_disqualified || m_notCompeting); + return !m_disqualified && !m_notCompeting; } -int RunStatus::toTime() const +int RunStatus::ogTime() const { if (m_disqualified) { if (m_disqualifiedByOrganizer) diff --git a/libquickevent/libquickeventcore/src/runstatus.h b/libquickevent/libquickeventcore/src/runstatus.h index b62ab7594..d364f1c60 100644 --- a/libquickevent/libquickeventcore/src/runstatus.h +++ b/libquickevent/libquickeventcore/src/runstatus.h @@ -18,7 +18,7 @@ class QUICKEVENTCORE_DECL_EXPORT RunStatus static RunStatus fromTreeTableRow(const qf::core::utils::TreeTableRow &ttr); bool isOk() const; - int toTime() const; + int ogTime() const; QString toXmlExportString() const; QString toEmmaExportString() const; diff --git a/quickevent/app/quickevent/plugins/Relays/src/relaysplugin.cpp b/quickevent/app/quickevent/plugins/Relays/src/relaysplugin.cpp index 245b5ed6a..9fd5d849c 100644 --- a/quickevent/app/quickevent/plugins/Relays/src/relaysplugin.cpp +++ b/quickevent/app/quickevent/plugins/Relays/src/relaysplugin.cpp @@ -114,6 +114,19 @@ struct Leg int stime = 0; int spos = 0; quickevent::core::RunStatus runStatus; + + bool isFinishedOk() const { + return ogTime() < quickevent::core::og::TimeMs::UNREAL_TIME_MSEC; + } + + int ogTime() const { + if(runStatus.isOk()) { + if(time > 0) + return time; + return quickevent::core::og::TimeMs::NOT_FINISH_TIME_MSEC; + } + return runStatus.ogTime(); + } }; struct Organization { @@ -134,10 +147,10 @@ struct Relay int ret = 0; for (int i = 0; i < qMin(legs.count(), leg_cnt); ++i) { const Leg &leg = legs[i]; - if (leg.runStatus.isOk()) + if (leg.isFinishedOk()) ret += leg.time; else - return leg.runStatus.toTime(); + return leg.ogTime(); } return ret; } @@ -228,11 +241,11 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in .name = q.value("clubs.name").toString(), .shortName = q.value("clubs.abbr").toString() }; - for (int i = 0; i < leg_count; ++i) + for (int i = 0; i < leg_count; ++i) { r.legs << Leg(); + } relays << r; qfDebug() << r.name; - //relay_ids << QString::number(r.relayId); } } { @@ -269,13 +282,13 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in } } } - for (int legno = 1; legno <= leg_count; ++legno) { + for (int legno = 0; legno < leg_count; ++legno) { qfs::QueryBuilder qb; qb.select2("runs", "id, relayId, timeMs," + quickevent::core::RunStatus::runsTableColumns().join(",")) .from("runs") .joinRestricted("runs.relayId", "relays.id", "relays.classId=" QF_IARG(class_id) - " AND runs.leg=" QF_IARG(legno) + " AND runs.leg=" QF_IARG(legno + 1) " AND runs.isRunning" , qfs::QueryBuilder::INNER_JOIN) .orderBy("runs.disqualified, runs.timeMs"); @@ -291,7 +304,7 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in } int run_id = q.value("runs.id").toInt(); Relay &relay = relays[i]; - Leg &leg = relay.legs[legno - 1]; + Leg &leg = relay.legs[legno]; if(leg.runId != run_id) { qfError() << "internal error, leg:" << legno << "runId check:" << leg.runId << "should equal" << run_id; } @@ -310,31 +323,35 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in } } /// compute overal legs positions - for (int legno = 1; legno <= leg_count; ++legno) { - QList> relay_stime; + for (int legno = 0; legno < leg_count; ++legno) { + struct LegTime { + int relayId; + int stime; + }; + QList relay_stime; for (int i = 0; i < relays.count(); ++i) { Relay &relay = relays[i]; - Leg &leg = relay.legs[legno - 1]; + Leg &leg = relay.legs[legno]; if(leg.runStatus.isOk() && leg.time > 0) { - if(legno == 1) + if(legno == 0) leg.stime = leg.time; - else if(relay.legs[legno-2].stime > 0) - leg.stime = leg.time + relay.legs[legno-2].stime; + else if(relay.legs[legno-1].stime > 0) + leg.stime = leg.time + relay.legs[legno-1].stime; } if(leg.stime > 0) - relay_stime << QPair(relay.relayId, leg.stime); + relay_stime << LegTime{ .relayId = relay.relayId, .stime = leg.stime }; } - std::sort(relay_stime.begin(), relay_stime.end(), [](const QPair &a, const QPair &b) {return a.second < b.second;}); + std::sort(relay_stime.begin(), relay_stime.end(), [](const LegTime &a, const LegTime &b) {return a.stime < b.stime;}); int pos = 0; - int winner_time = relay_stime.begin()->second; - for(const QPair &p : relay_stime) { - int relay_id = p.first; + int winner_time = relay_stime.begin()->stime; + for(const auto &p : relay_stime) { + int relay_id = p.relayId; for (int i = 0; i < relays.count(); ++i) { if(relays[i].relayId == relay_id) { Relay &relay = relays[i]; - Leg &leg = relay.legs[legno - 1]; + Leg &leg = relay.legs[legno]; leg.spos = ++pos; - leg.lossOverall = p.second - winner_time; + leg.lossOverall = p.stime - winner_time; break; } } @@ -350,8 +367,9 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in QMutableListIterator i(relays); while (i.hasNext()) { const Relay &r = i.next(); - if(r.time(leg_count) == qog::TimeMs::NOT_FINISH_TIME_MSEC) + if(r.time(leg_count) == qog::TimeMs::NOT_FINISH_TIME_MSEC) { i.remove(); + } } } /// sort relays @@ -406,7 +424,7 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in tt2_row.setValue("lastName", leg.lastName); tt2_row.setValue("registration", leg.reg); tt2_row.setValue("iofId", leg.iofId); - tt2_row.setValue("time", leg.runStatus.isOk() ? leg.time : leg.runStatus.toTime()); + tt2_row.setValue("time", leg.ogTime()); tt2_row.setValue("pos", leg.pos); tt2_row.setValue("loss", leg.loss); tt2_row.setValue("lossOverall", leg.lossOverall); diff --git a/quickevent/app/quickevent/src/appversion.h b/quickevent/app/quickevent/src/appversion.h index 7fc2a4f4f..b7a7d8342 100644 --- a/quickevent/app/quickevent/src/appversion.h +++ b/quickevent/app/quickevent/src/appversion.h @@ -1,4 +1,4 @@ #pragma once -#define APP_VERSION "3.0.0" +#define APP_VERSION "3.0.1"