Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: nationality support #991

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 250 additions & 0 deletions quickevent/app/quickevent/plugins/Oris/src/alphatoioc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
#ifndef ALPHATOIOC_H
#define ALPHATOIOC_H

#include <QMap>
#include <QString>

QMap<QString, QString> isoAlpha2ToIoc = {
Copy link
Contributor

@arnost00 arnost00 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, fixed list of codes in the source. How will we deal with it if there is any correction or modification of the codes?
Country names evolve over time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we dont use any packaging system in this c++ project that would handle this. Git submodule for such a small thing would be overkill. The countries participating in orienteering are hardly going to change to have a meaningful impact, but I am open to suggesting how to handle this better.

{"AF", "AFG"},
{"AL", "ALB"},
{"DZ", "ALG"},
{"AS", "ASA"},
{"AD", "AND"},
{"AO", "ANG"},
{"AI", "AIA"},
{"AG", "ANT"},
{"AR", "ARG"},
{"AM", "ARM"},
{"AW", "ARU"},
{"AU", "AUS"},
{"AT", "AUT"},
{"AZ", "AZE"},
{"BS", "BAH"},
{"BH", "BRN"},
{"BD", "BAN"},
{"BB", "BAR"},
{"BY", "BLR"},
{"BE", "BEL"},
{"BZ", "BIZ"},
{"BJ", "BEN"},
{"BM", "BER"},
{"BT", "BHU"},
{"BO", "BOL"},
{"BQ", "AHO"},
{"BA", "BIH"},
{"BW", "BOT"},
{"BR", "BRA"},
{"VG", "IVB"},
{"BN", "BRU"},
{"BG", "BUL"},
{"BF", "BUR"},
{"BI", "BDI"},
{"CV", "CPV"},
{"KH", "CAM"},
{"CM", "CMR"},
{"CA", "CAN"},
{"KY", "CAY"},
{"CF", "CAF"},
{"TD", "CHA"},
{"CL", "CHI"},
{"CN", "CHN"},
{"HK", "HKG"},
{"MO", "MAC"},
{"CO", "COL"},
{"KM", "COM"},
{"CG", "CGO"},
{"CK", "COK"},
{"CR", "CRC"},
{"HR", "CRO"},
{"CU", "CUB"},
{"CY", "CYP"},
{"CZ", "CZE"},
{"KP", "PRK"},
{"CD", "COD"},
{"DK", "DEN"},
{"DJ", "DJI"},
{"DM", "DMA"},
{"DO", "DOM"},
{"EC", "ECU"},
{"EG", "EGY"},
{"SV", "ESA"},
{"GQ", "GEQ"},
{"ER", "ERI"},
{"EE", "EST"},
{"SZ", "SWZ"},
{"ET", "ETH"},
{"FK", "FLK"},
{"FO", "FAR"},
{"FJ", "FIJ"},
{"FI", "FIN"},
{"FR", "FRA"},
{"GF", "FGU"},
{"PF", "FPO"},
{"GA", "GAB"},
{"GM", "GAM"},
{"GE", "GEO"},
{"DE", "GER"},
{"GH", "GHA"},
{"GI", "GIB"},
{"GR", "GRE"},
{"GL", "GRL"},
{"GD", "GRN"},
{"GP", "GUD"},
{"GU", "GUM"},
{"GT", "GUA"},
{"GN", "GUI"},
{"GW", "GBS"},
{"GY", "GUY"},
{"HT", "HAI"},
{"HN", "HON"},
{"HU", "HUN"},
{"IS", "ISL"},
{"IN", "IND"},
{"ID", "INA"},
{"IR", "IRI"},
{"IQ", "IRQ"},
{"IE", "IRL"},
{"IL", "ISR"},
{"IT", "ITA"},
{"CI", "CIV"},
{"JM", "JAM"},
{"JP", "JPN"},
{"JO", "JOR"},
{"KZ", "KAZ"},
{"KE", "KEN"},
{"KI", "KIR"},
{"KW", "KUW"},
{"KG", "KGZ"},
{"LA", "LAO"},
{"LV", "LAT"},
{"LB", "LIB"},
{"LS", "LES"},
{"LR", "LBR"},
{"LY", "LBA"},
{"LI", "LIE"},
{"LT", "LTU"},
{"LU", "LUX"},
{"MG", "MAD"},
{"MW", "MAW"},
{"MY", "MAS"},
{"MV", "MDV"},
{"ML", "MLI"},
{"MT", "MLT"},
{"MH", "MSH"},
{"MQ", "MRT"},
{"MR", "MTN"},
{"MU", "MRI"},
{"YT", "MAY"},
{"MX", "MEX"},
{"FM", "FSM"},
{"MC", "MON"},
{"MN", "MGL"},
{"ME", "MGO"},
{"MS", "MNT"},
{"MA", "MAR"},
{"MZ", "MOZ"},
{"MM", "MYA"},
{"NA", "NAM"},
{"NR", "NRU"},
{"NP", "NEP"},
{"NL", "NED"},
{"NC", "NCD"},
{"NZ", "NZL"},
{"NI", "NCA"},
{"NE", "NIG"},
{"NG", "NGR"},
{"NU", "NIU"},
{"NF", "NFI"},
{"MP", "NMA"},
{"MK", "MKD"},
{"NO", "NOR"},
{"OM", "OMA"},
{"PK", "PAK"},
{"PW", "PLW"},
{"PA", "PAN"},
{"PG", "PNG"},
{"PY", "PAR"},
{"PE", "PER"},
{"PH", "PHI"},
{"PL", "POL"},
{"PT", "POR"},
{"PR", "PUR"},
{"QA", "QAT"},
{"KR", "KOR"},
{"MD", "MDA"},
{"RE", "REU"},
{"RO", "ROU"},
{"RU", "RUS"},
{"RW", "RWA"},
{"SH", "HEL"},
{"KN", "SKN"},
{"LC", "LCA"},
{"PM", "SPM"},
{"VC", "VIN"},
{"WS", "SAM"},
{"SM", "SMR"},
{"ST", "STP"},
{"SA", "KSA"},
{"SN", "SEN"},
{"RS", "SRB"},
{"SC", "SEY"},
{"SL", "SLE"},
{"SG", "SIN"},
{"SK", "SVK"},
{"SI", "SLO"},
{"SB", "SOL"},
{"SO", "SOM"},
{"ZA", "RSA"},
{"ES", "ESP"},
{"LK", "SRI"},
{"PS", "PLE"},
{"SD", "SUD"},
{"SR", "SUR"},
{"SE", "SWE"},
{"CH", "SUI"},
{"SY", "SYR"},
{"TW", "TPE"},
{"TJ", "TJK"},
{"TH", "THA"},
{"TL", "TLS"},
{"TG", "TOG"},
{"TO", "TGA"},
{"TT", "TTO"},
{"TN", "TUN"},
{"TR", "TUR"},
{"TM", "TKM"},
{"TC", "TKS"},
{"TV", "TUV"},
{"UG", "UGA"},
{"UA", "UKR"},
{"AE", "UAE"},
{"GB", "GBR"},
{"TZ", "TAN"},
{"US", "USA"},
{"VI", "ISV"},
{"UY", "URU"},
{"UZ", "UZB"},
{"VU", "VAN"},
{"VE", "VEN"},
{"VN", "VIE"},
{"WF", "WAF"},
{"YE", "YEM"},
{"ZM", "ZAM"},
{"ZW", "ZIM"}
};

QString convertToIOC(const QString& alpha2Code)
{
// Convert to uppercase to ensure consistent lookup
QString normalizedCode = alpha2Code.toUpper();

// Check if the code exists in the map
if (isoAlpha2ToIoc.contains(normalizedCode)) {
return isoAlpha2ToIoc.value(normalizedCode);
}

// Return empty optional if no mapping exists
return QString();
}

#endif // ALPHATOIOC_H
4 changes: 3 additions & 1 deletion quickevent/app/quickevent/plugins/Oris/src/orisimporter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "chooseoriseventdialog.h"
#include "orisimporter.h"
#include "alphatoioc.h"

#include <qf/qmlwidgets/framework/mainwindow.h>
#include <qf/qmlwidgets/dialogs/dialog.h>
Expand Down Expand Up @@ -558,13 +559,15 @@ void OrisImporter::syncEventEntries(int event_id, std::function<void ()> success
qfWarning() << "class id:" << class_id << "not found in the class definitions";
class_id = 0;
}
QString country_code = convertToIOC(competitor_o.value(QStringLiteral("Nationality")).toString());
doc->setValue("classId", (class_id == 0)? QVariant(QVariant::Int): QVariant(class_id));
doc->setSiid(siid);
doc->setValue("firstName", first_name);
doc->setValue("lastName", last_name);
doc->setValue("registration", reg_no);
doc->setValue("iofId", !iof_id.isEmpty() ? iof_id : QVariant(QVariant::Int));
doc->setValue("licence", competitor_o.value(QStringLiteral("Licence")).toString());
doc->setValue("countryCode", country_code);
doc->setValue("note", note);
doc->setValue("importId", import_id);
doc->setProperty(KEY_RUNS, runs);
Expand Down Expand Up @@ -846,4 +849,3 @@ void OrisImporter::importClubs(std::function<void ()> success_callback)
});
}


1 change: 1 addition & 0 deletions quickevent/app/quickevent/plugins/Oris/src/src.pri
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
message(including $$PWD)

HEADERS += \
$$PWD/alphatoioc.h \
$$PWD/orisimporter.h \
$$PWD/chooseoriseventdialog.h \
$$PWD/orisplugin.h \
Expand Down
9 changes: 6 additions & 3 deletions quickevent/app/quickevent/plugins/Oris/src/xmlimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ bool XmlImporter::importEntries(QXmlStreamReader &reader, const XmlCreators crea
doc.setSiid(person.siNumber);
doc.setValue("firstName", person.nameGiven);
doc.setValue("lastName", person.nameFamily);
doc.setValue("country", person.nationalityName);
doc.setValue("countryCode", person.nationalityCode);
if (creator == XmlCreators::Oris) {
doc.setValue("registration", person.regCz);
doc.setValue("note", person.noteOris);
Expand All @@ -225,7 +227,6 @@ bool XmlImporter::importEntries(QXmlStreamReader &reader, const XmlCreators crea
else if (!person.countryName.isEmpty())
doc.setValue("club",person.countryName);
}
doc.setValue("country",person.nationalityName);
if (person.iofId.has_value())
doc.setValue("importId",person.iofId.value());
}
Expand Down Expand Up @@ -359,6 +360,7 @@ bool XmlImporter::importEntries(QXmlStreamReader &reader, const XmlCreators crea
doc.setValue("club",leg.second.countryName);
}
doc.setValue("country",leg.second.nationalityName);
doc.setValue("countryCode",leg.second.nationalityCode);
if (leg.second.iofId.has_value())
doc.setValue("importId",leg.second.iofId.value());
if (leg.second.iofId.has_value())
Expand Down Expand Up @@ -672,7 +674,7 @@ bool XmlImporter::importRegistration(QXmlStreamReader &reader, const XmlCreators
}
qf::core::sql::Transaction transaction;
q.exec("DELETE FROM registrations", qf::core::Exception::Throw);
q.prepare("INSERT INTO registrations (firstName, lastName, registration, licence, clubAbbr, country, siId, importId) VALUES (:firstName, :lastName, :registration, :licence, :clubAbbr, :country, :siId, :importId)", qf::core::Exception::Throw);
q.prepare("INSERT INTO registrations (firstName, lastName, registration, licence, clubAbbr, country, countryCode, siId, importId) VALUES (:firstName, :lastName, :registration, :licence, :clubAbbr, :country, :countryCode, :siId, :importId)", qf::core::Exception::Throw);
// load data from XML
int items_processed = 0;
while(reader.readNextStartElement()) {
Expand Down Expand Up @@ -704,7 +706,8 @@ bool XmlImporter::importRegistration(QXmlStreamReader &reader, const XmlCreators
else
q.bindValue(":importId", 0);
}
q.bindValue(":country",person.nationalityCode);
q.bindValue(":country", person.nationalityName);
q.bindValue(":countryCode", person.nationalityCode);
q.exec(qf::core::Exception::Throw);
items_processed++;
}
Expand Down
21 changes: 20 additions & 1 deletion quickevent/app/quickevent/plugins/Relays/src/relaysplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ struct Leg
QString iofId;
Organization org;
QString country;
QString countryCode;
int runId = 0;
//int courseId = 0;
int time = 0;
Expand Down Expand Up @@ -275,7 +276,7 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in
qfs::QueryBuilder qb;
qb.select2("competitors", "id, registration, iofId")
.select2("runs", "id, relayId, leg, isRunning")
.select2("competitors", "firstName, lastName, club, country")
.select2("competitors", "firstName, lastName, club, country, countryCode")
.select("COALESCE(competitors.lastName, '') || ' ' || COALESCE(competitors.firstName, '') AS competitorName")
.from("runs")
.join("runs.competitorId", "competitors.id")
Expand Down Expand Up @@ -305,6 +306,7 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in
leg.org.id = club.first;
leg.org.shortName = club.second;
leg.country = q.value("competitors.country").toString();
leg.countryCode = q.value("competitors.countryCode").toString();
break;
}
}
Expand Down Expand Up @@ -466,6 +468,7 @@ qf::core::utils::TreeTable RelaysPlugin::nLegsClassResultsTable(int class_id, in
tt2_row.setValue("orgName", leg.org.name);
tt2_row.setValue("orgShortName", leg.org.shortName);
tt2_row.setValue("country", leg.country);
tt2_row.setValue("countryCode", leg.countryCode);
//tt2_row.setValue("courseId", leg.courseId);
tt2.setRow(ix2, tt2_row);
qfDebug() << '\t' << leg.pos << leg.fullName;
Expand Down Expand Up @@ -699,6 +702,14 @@ QString RelaysPlugin::resultsIofXml30()
auto family = tt_leg_row.value(QStringLiteral("lastName"));
auto given = tt_leg_row.value(QStringLiteral("firstName"));
append_list(person, QVariantList{"Name", QVariantList{"Family", family}, QVariantList{"Given", given}});
QString country_code = tt_leg_row.value(QStringLiteral("countryCode")).toString();
if (!country_code.isEmpty()) {
append_list(person,
QVariantList{"Nationality",
QVariantMap{{"code", country_code}},
tt_leg_row.value(QStringLiteral("country"))
});
}
append_list(member_result, person);

QString club_name = tt_leg_row.value(QStringLiteral("orgName")).toString();
Expand Down Expand Up @@ -956,6 +967,14 @@ QString RelaysPlugin::startListIofXml30()
auto family = tt_leg_row.value(QStringLiteral("lastName"));
auto given = tt_leg_row.value(QStringLiteral("firstName"));
append_list(person, QVariantList{"Name", QVariantList{"Family", family}, QVariantList{"Given", given}});
QString country_code = tt_leg_row.value(QStringLiteral("countryCode")).toString();
if (!country_code.isEmpty()) {
append_list(person,
QVariantList{"Nationality",
QVariantMap{{"code", country_code}},
tt_leg_row.value(QStringLiteral("country"))
});
}
append_list(member_start, person);

QVariantList start{"Start"};
Expand Down
Loading