Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions quickevent/app/quickevent/plugins/Event/qml/DbSchema.qml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Schema {
Field { name: 'licence'; type: String { length: 1 } },
Field { name: 'club'; type: String { } },
Field { name: 'country'; type: String { } },
Field { name: 'countryCode'; type: String { } },
Field { name: 'siId'; type: Int { } },
Field { name: 'ranking'; type: Int { } },
Field { name: 'note'; type: String { } },
Expand Down Expand Up @@ -345,6 +346,7 @@ Schema {
Field { name: 'licence'; type: String { length: 1 } },
Field { name: 'clubAbbr'; type: String { } },
Field { name: 'country'; type: String { } },
Field { name: 'countryCode'; type: String { } },
Field { name: 'siId'; type: Int { } },
//Field { name: 'nameSearchKey'; type: String {} },
Field { name: 'importId'; type: Int { } }
Expand Down
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
Collaborator

@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
Loading