Skip to content

Commit

Permalink
[#897 fixed] Štafety: Chybný tisk výsledků
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Jul 7, 2023
1 parent 554b160 commit fe0c604
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 26 deletions.
4 changes: 2 additions & 2 deletions libquickevent/libquickeventcore/src/runstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libquickevent/libquickeventcore/src/runstatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
62 changes: 40 additions & 22 deletions quickevent/app/quickevent/plugins/Relays/src/relaysplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
{
Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
Expand All @@ -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<QPair<int, int>> relay_stime;
for (int legno = 0; legno < leg_count; ++legno) {
struct LegTime {
int relayId;
int stime;
};
QList<LegTime> 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<int, int>(relay.relayId, leg.stime);
relay_stime << LegTime{ .relayId = relay.relayId, .stime = leg.stime };
}
std::sort(relay_stime.begin(), relay_stime.end(), [](const QPair<int, int> &a, const QPair<int, int> &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<int, int> &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;
}
}
Expand All @@ -350,8 +367,9 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in
QMutableListIterator<Relay> 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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion quickevent/app/quickevent/src/appversion.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define APP_VERSION "3.0.0"
#define APP_VERSION "3.0.1"

0 comments on commit fe0c604

Please sign in to comment.