60 lines
2 KiB
C++
60 lines
2 KiB
C++
|
#include "../headers/brproviderdr.h"
|
||
|
|
||
|
BRProviderDr::BRProviderDr(QObject *parent) : BRProvider(parent)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
BRWidget::BRWidgetStatusCode BRProviderDr::loadCalendarData(BRCalendar* calendar)
|
||
|
{
|
||
|
// load some data
|
||
|
QString nationStr = calendar->getFederation() == BRWidget::SAC ? "SUI":"GER";
|
||
|
QVariantMap ret = this->serverRequest(QUrl("https://www.digitalrock.de/egroupware/ranking/json.php?nation=" + nationStr));
|
||
|
|
||
|
if(ret["status"] != 200){
|
||
|
// request was a failure
|
||
|
return BRWidget::BRWidgetStatusCode(ret["status"].toInt());
|
||
|
}
|
||
|
|
||
|
QVariantMap data = QJsonDocument::fromJson(ret["text"].toString().toUtf8()).toVariant().toMap();
|
||
|
|
||
|
// parse competitions
|
||
|
QVariantList competitions = data["competitions"].toList();
|
||
|
QList<BRCompetition*> tmpCompetitions;
|
||
|
|
||
|
for(QVariant competitionVar : competitions) {
|
||
|
BRCompetition* competition = new BRCompetition(this, calendar->getFederation(), competitionVar.toMap()["WetId"].toInt());
|
||
|
this->loadCompetitionData(competition, competitionVar.toMap());
|
||
|
tmpCompetitions.append(competition);
|
||
|
}
|
||
|
|
||
|
if(calendar->competitions != tmpCompetitions)
|
||
|
calendar->competitions = tmpCompetitions;
|
||
|
|
||
|
return BRWidget::Success;
|
||
|
}
|
||
|
|
||
|
|
||
|
BRWidget::BRWidgetStatusCode BRProviderDr::loadCompetitionData(BRCompetition* competition, QVariantMap data) {
|
||
|
|
||
|
// load basic properties
|
||
|
competition->name = data["name"].toString();
|
||
|
|
||
|
QMap<QString, BRCompetition::BRDiscipline> disciplineTranslations = {
|
||
|
{"boulder", BRCompetition::Boulder},
|
||
|
{"lead", BRCompetition::Lead},
|
||
|
{"speed", BRCompetition::Speed}
|
||
|
};
|
||
|
|
||
|
if(disciplineTranslations.contains(data["discipline"].toString()))
|
||
|
competition->discipline = disciplineTranslations[data["discipline"].toString()];
|
||
|
|
||
|
competition->startDate = QDate::fromString(data["date"].toString());
|
||
|
competition->endDate = QDate::fromString(data["date_end"].toString());
|
||
|
|
||
|
// TODO load categories
|
||
|
//competition->categories.clear();
|
||
|
|
||
|
// TODO load results
|
||
|
}
|