2024-08-12 22:09:50 +02:00
|
|
|
|
|
|
|
#include "CompetitorWithResults.h"
|
|
|
|
|
2024-08-15 19:21:02 +02:00
|
|
|
/**
|
|
|
|
* Replaces/sets the results of a competitor.
|
|
|
|
*
|
|
|
|
* @param results The results of the competitor.
|
|
|
|
* @return True, if successful.
|
|
|
|
*/
|
2024-08-12 22:09:50 +02:00
|
|
|
bool CompetitorWithResults::setResults(const QJsonObject &results) {
|
|
|
|
if (!results.contains("mark")
|
|
|
|
|| !results.contains("medalType")) {
|
|
|
|
throw invalid_argument("Results object of competitor is incomplete.");
|
|
|
|
}
|
|
|
|
|
2024-08-15 19:21:02 +02:00
|
|
|
this->mark = results["mark"].toString();
|
|
|
|
this->medalType = results["medalType"].toString();
|
|
|
|
|
2024-08-12 22:09:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
2024-08-15 19:21:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static compare method, which can compare the result times or points of two CompetitorsWithResult.
|
|
|
|
* Returns true, if the left competitor (lComp) got a real lesser score than the right competitor (rComp).
|
|
|
|
*
|
|
|
|
* @param lComp First competitor to compare.
|
|
|
|
* @param rComp Second competitor to compare.
|
|
|
|
* @return True, if the second competitor got a higher score.
|
|
|
|
*/
|
|
|
|
bool CompetitorWithResults::compare(CompetitorWithResults lComp, CompetitorWithResults rComp) {
|
|
|
|
QString l = lComp.getMark();
|
|
|
|
QString r = rComp.getMark();
|
|
|
|
|
|
|
|
// check if values are numerical (-> not time values)
|
|
|
|
if (!l.contains(":") || !r.contains(":")) {
|
|
|
|
return l.toFloat() < r.toFloat();
|
|
|
|
}
|
|
|
|
|
|
|
|
// compare time values if not numerical
|
|
|
|
QString lTime(""), rTime("");
|
|
|
|
|
|
|
|
for (QChar c : l) if (c.isDigit()) lTime.append(c);
|
|
|
|
for (QChar c : r) if (c.isDigit()) rTime.append(c);
|
|
|
|
|
|
|
|
return lTime.compare(rTime) < 0;
|
|
|
|
}
|