diff options
author | Steru <jerrydream111@gmail.com> | 2024-08-15 23:27:54 +0200 |
---|---|---|
committer | Steru <jerrydream111@gmail.com> | 2024-08-16 15:59:22 +0200 |
commit | 66d5d8685f7dcd45b2e9581315c101e69646cd6f (patch) | |
tree | 09376bc9c548ab086118f888653222860098000f /src/model/Sport.cpp | |
parent | b49c066bd5ef8d543a842249881b57eb771ffc94 (diff) |
Made Competitor a QObject and tidied up some code.
Diffstat (limited to 'src/model/Sport.cpp')
-rw-r--r-- | src/model/Sport.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/model/Sport.cpp b/src/model/Sport.cpp index a0ca649..80bfe94 100644 --- a/src/model/Sport.cpp +++ b/src/model/Sport.cpp @@ -212,7 +212,7 @@ QList<CompetitorWithResults> Sport::getCompetitorsByCategory(QString category) { /** * @brief Sport::getCompetitorsWithMedal Filters all competitors, who have at least one medal. These objects are different from getCompetitorsByCategory !!! - * @return All competitors, who won at least one medal. Structure of one competitor: {code, name, noc, medals{ME_GOLD, ME_SILVER, ME_BRONZE}} + * @return All competitors, who won at least one medal. Structure of one competitor: {code, name, m_noc, medals{ME_GOLD, ME_SILVER, ME_BRONZE}} */ QList<MedalWinner> Sport::getCompetitorsWithMedal() { map<QString, QJsonObject> competitors; @@ -238,7 +238,7 @@ QList<MedalWinner> Sport::getCompetitorsWithMedal() { QJsonArray medalComps = filter(unit["competitors"].toArray(), [](QJsonObject comp) { if (!comp.contains("results")) return false; - QString medalType = comp["results"].toObject()["medalType"].toString(); + QString medalType = comp["results"].toObject()["m_medalType"].toString(); return !medalType.isEmpty(); }); @@ -248,10 +248,10 @@ QList<MedalWinner> Sport::getCompetitorsWithMedal() { // validate competitor (with medal) if (!medalComp.contains("name") || !medalComp.contains("results") - || !medalComp["results"].toObject().contains("medalType")) continue; + || !medalComp["results"].toObject().contains("m_medalType")) continue; QString name = medalComp["name"].toString(); - QString medalType = medalComp["results"].toObject()["medalType"].toString(); + QString medalType = medalComp["results"].toObject()["m_medalType"].toString(); // check if competitor has other medal(s) if (competitors.find(name) == competitors.end()) { @@ -280,7 +280,7 @@ QList<MedalWinner> Sport::getCompetitorsWithMedal() { } /** - * @brief Sport::createCompetitorWithMedals Creates a competitor QJsonObject with the following attributes: code, name, noc, medals{ME_GOLD, ME_SILVER, ME_BRONZE} + * @brief Sport::createCompetitorWithMedals Creates a competitor QJsonObject with the following attributes: code, name, m_noc, medals{ME_GOLD, ME_SILVER, ME_BRONZE} * @param comp The original competitor object. * @return A competitor object with medal counts. */ @@ -288,7 +288,7 @@ QJsonObject Sport::createCompetitorWithMedals(QJsonObject comp) { // repair competitor if something is missing if (!comp.contains("code")) comp.insert("code", "0"); if (!comp.contains("name")) comp.insert("code", ""); - if (!comp.contains("noc")) comp.insert("code", ""); + if (!comp.contains("m_noc")) comp.insert("code", ""); // create new competitor QJsonObject and add it to the competitor map QJsonObject medals { @@ -300,7 +300,7 @@ QJsonObject Sport::createCompetitorWithMedals(QJsonObject comp) { QJsonObject medalComp { {"code", comp["code"].toString()}, {"name", comp["name"].toString()}, - {"noc", comp["noc"].toString()}, + {"m_noc", comp["m_noc"].toString()}, {"medals", medals} }; @@ -384,15 +384,17 @@ void Sport::reverseOrder(QList<Competitor> &competitors) { int iterations = competitors.size() / 2; // automatically rounds down for (int i = 0; i < iterations; i++) { - Competitor temp = competitors.value(i); - competitors.replace(i, competitors.value(competitors.size() - 1 - i)); - competitors.replace(competitors.size() - 1 - i, temp); + Competitor left = Competitor(competitors.value(i)); + Competitor right = Competitor(competitors.value(competitors.size() - 1 - i)); + + competitors.replace(i, right); + competitors.replace(competitors.size() - 1 - i, left); } } /** * @brief Sport::addRelativeToFirst Adds a relative value to the result of all competitors. Relative to the first competitor in the QJsonArray. - * Stores the statistic in obj->results->stat for each competitor. + * Stores the m_statistic in obj->results->stat for each competitor. * @param competitors The competitors of one category. */ void Sport::addRelativeToFirst(QList<CompetitorWithResults> &competitors) { @@ -401,11 +403,11 @@ void Sport::addRelativeToFirst(QList<CompetitorWithResults> &competitors) { QString reference = competitors.value(0).getMark(); for (CompetitorWithResults comp : competitors) { - QString results = comp.getMark(); + QString result = comp.getMark(); // format relative float value to string with 2 digits after decimal point and sign stringstream sstream; - sstream << fixed << setprecision(2) << calcRelativeStat(reference, results["mark"].toString()); + sstream << fixed << setprecision(2) << calcRelativeStat(reference, result); QString stat(sstream.str().c_str()); stat.append("%"); if (stat.at(0).isNumber()) stat = QString("+").append(stat); |