2020-10-31 15:16:06 +01:00
|
|
|
#include "../headers/brproviderdr.h"
|
|
|
|
|
|
|
|
BRProviderDr::BRProviderDr(QObject *parent) : BRProvider(parent)
|
|
|
|
{
|
2020-11-03 15:56:43 +01:00
|
|
|
// leagues source:
|
|
|
|
// - https://github.com/ralfbecker/ranking/blob/master/sitemgr/digitalrock/dav_calendar.php
|
|
|
|
// - https://github.com/ralfbecker/ranking/blob/master/sitemgr/digitalrock/sac_calendar.php
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
this->leagues.insert(
|
|
|
|
BRWidget::DAV,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{"id", 0},
|
|
|
|
{"name", "Deutsche Meisterschaft"},
|
|
|
|
{"color", "#A8F0A8"},
|
|
|
|
{"leagueIDs", QVariantList({59, 57, 60})}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{"id", 1},
|
|
|
|
{"name", "Deutscher Jugendcup"},
|
|
|
|
{"color", "#D8FFD8"},
|
|
|
|
{"leagueIDs", QVariantList({58})}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{"id", 2},
|
|
|
|
{"name", "Landesmeisterschaft"},
|
|
|
|
{"color", "#F0F0F0"},
|
|
|
|
{"leagueIDs", QVariantList({61, 56})}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this->leagues.insert(
|
|
|
|
BRWidget::SAC,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{"id", 0},
|
|
|
|
{"name", "Erwachsene"},
|
|
|
|
{"color", "#A8F0A8"},
|
|
|
|
{"leagueIDs", QVariantList({57, 59, 60})}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{"id", 1},
|
|
|
|
{"name", "Jugend"},
|
|
|
|
{"color", "#D8FFD8"},
|
|
|
|
{"leagueIDs", QVariantList({65})}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{"id", 2},
|
|
|
|
{"name", "RegioCups"},
|
|
|
|
{"color", "#F0F0F0"},
|
|
|
|
{"leagueIDs", QVariantList({64})}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{"id", 3},
|
|
|
|
{"name", "Iceclimbing"},
|
|
|
|
{"color", "#F0F0F0"},
|
|
|
|
{"leagueIDs", QVariantList({84})}
|
|
|
|
}
|
|
|
|
});
|
2020-10-31 15:16:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRCalendar::BRCalendarData* calendarData)
|
2020-10-31 15:16:06 +01:00
|
|
|
{
|
|
|
|
// load some data
|
2020-11-03 15:56:43 +01:00
|
|
|
QString nationStr = calendarData->calendar->getFederation() == BRWidget::SAC ? "SUI":"GER";
|
|
|
|
qDebug() << "Nation str: " << nationStr << " federation: " << calendarData->calendar->getFederation();
|
|
|
|
int year = QDate::currentDate().year();
|
|
|
|
QString requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?nation=" + nationStr + "&year=" + QString::number(year);
|
|
|
|
QVariantMap ret = this->serverRequest(QUrl(requestUrl));
|
2020-10-31 15:16:06 +01:00
|
|
|
|
|
|
|
if(ret["status"] != 200){
|
|
|
|
// request was a failure
|
|
|
|
return BRWidget::BRWidgetStatusCode(ret["status"].toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap data = QJsonDocument::fromJson(ret["text"].toString().toUtf8()).toVariant().toMap();
|
2020-11-03 15:56:43 +01:00
|
|
|
data.insert("year", year);
|
|
|
|
data.insert("federation", calendarData->calendar->getFederation());
|
|
|
|
|
|
|
|
// create seasons
|
|
|
|
QVariantList seasons = data["years"].toList();
|
|
|
|
|
|
|
|
for(QVariant seasonVar : seasons) {
|
|
|
|
int seasonId = seasonVar.toString().toInt();
|
|
|
|
BRSeason* season = this->getSeason(
|
|
|
|
calendarData->calendar->getFederation(),
|
|
|
|
seasonId,
|
|
|
|
this->parseSeasonData(seasonId, data)
|
|
|
|
);
|
|
|
|
|
|
|
|
calendarData->seasons.append(season);
|
|
|
|
|
|
|
|
if(seasonId == year)
|
|
|
|
calendarData->currentSeason = season;
|
|
|
|
}
|
|
|
|
|
|
|
|
return BRWidget::Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRSeason::BRSeasonData* seasonData) {
|
|
|
|
if(seasonData->season->getLeagues().length() > 0) {
|
|
|
|
// leagues are already loaded
|
|
|
|
|
|
|
|
// load some data
|
|
|
|
QString nationStr = seasonData->season->getFederation() == BRWidget::SAC ? "SUI":"GER";
|
|
|
|
qDebug() << "Nation str: " << nationStr << " federation: " << seasonData->season->getFederation();
|
|
|
|
int year = seasonData->season->getYear();
|
|
|
|
QString requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?nation=" + nationStr + "&year=" + QString::number(year);
|
|
|
|
QVariantMap ret = this->serverRequest(QUrl(requestUrl));
|
|
|
|
|
|
|
|
if(ret["status"] != 200){
|
|
|
|
// request was a failure
|
|
|
|
return BRWidget::BRWidgetStatusCode(ret["status"].toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap data = QJsonDocument::fromJson(ret["text"].toString().toUtf8()).toVariant().toMap();
|
|
|
|
data.insert("year", year);
|
|
|
|
data.insert("federation", seasonData->season->getFederation());
|
|
|
|
|
|
|
|
// populate season
|
|
|
|
QVariantList seasons = data["years"].toList();
|
|
|
|
|
|
|
|
this->parseSeasonData(seasonData, year, data);
|
|
|
|
|
|
|
|
return BRWidget::Success;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// should never happen
|
|
|
|
return BRWidget::NotImplementedError;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BRSeason::BRSeasonData BRProviderDr::parseSeasonData(int id, QVariantMap rawData) {
|
|
|
|
BRSeason::BRSeasonData data;
|
|
|
|
this->parseSeasonData(&data, id, rawData);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BRProviderDr::parseSeasonData(BRSeason::BRSeasonData* seasonData, int id, QVariantMap rawData) {
|
|
|
|
seasonData->year = id;
|
|
|
|
seasonData->nativeMultiLeagueSupport = true;
|
|
|
|
seasonData->name = QString::number(id);
|
|
|
|
|
|
|
|
BRWidget::BRFederation federation = BRWidget::BRFederation(rawData["federation"].toInt(0));
|
|
|
|
|
|
|
|
// insert the leagues
|
|
|
|
for(QVariantMap leagueVar : this->leagues[federation]) {
|
|
|
|
BRLeague* league = this->getLeague(federation, leagueVar["id"].toInt(), this->parseLeagueData(leagueVar, rawData));
|
|
|
|
seasonData->leagues.append(league);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRLeague::BRLeagueData* leagueData) {
|
|
|
|
Q_UNUSED(leagueData)
|
|
|
|
return BRWidget::NotImplementedError;
|
|
|
|
}
|
|
|
|
|
|
|
|
BRLeague::BRLeagueData BRProviderDr::parseLeagueData(QVariantMap leagueProperties, QVariantMap rawData) {
|
|
|
|
|
|
|
|
BRLeague::BRLeagueData data;
|
|
|
|
|
|
|
|
BRWidget::BRFederation federation = BRWidget::BRFederation(rawData["federation"].toInt(0));
|
|
|
|
|
|
|
|
data.name = leagueProperties["name"].toString();
|
|
|
|
data.color = QColor(leagueProperties["color"].toString());
|
|
|
|
|
|
|
|
qDebug() << "Adding league: " << data.name;
|
2020-10-31 15:16:06 +01:00
|
|
|
|
|
|
|
// parse competitions
|
2020-11-03 15:56:43 +01:00
|
|
|
QVariantList competitionsVar = rawData["competitions"].toList();
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
// TODO: make more efficient
|
|
|
|
|
|
|
|
for(QVariant competitionVar : competitionsVar) {
|
|
|
|
QVariantMap competitionMap = competitionVar.toMap();
|
|
|
|
|
|
|
|
// check if this competition is part of this league
|
|
|
|
if(leagueProperties["leagueIDs"].toList().contains(competitionMap["cat_id"].toInt())) {
|
|
|
|
BRCompetition* competition = this->getCompetition(federation, competitionVar.toMap()["WetId"].toInt(), this->parseCompetitionData(competitionMap, federation));
|
|
|
|
data.competitions.append(competition);
|
|
|
|
qDebug() << "- Adding competition: " << competition->getName();
|
|
|
|
}
|
2020-10-31 15:16:06 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
// if this is league with id 0
|
|
|
|
if(leagueProperties["id"].toInt() == 0) {
|
|
|
|
// parse cups
|
|
|
|
QVariantList cupsVar = rawData["cups"].toList();
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
for(QVariant cupVar : cupsVar) {
|
|
|
|
QVariantMap cupMap = cupVar.toMap();
|
|
|
|
BRCup* cup = this->getCup(federation, cupMap["SerId"].toInt(), this->parseCupData(rawData["cats"].toList(), cupMap, federation));
|
|
|
|
data.cups.append(cup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
2020-10-31 15:16:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRCompetition::BRCompetitionData* competitionData) {
|
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
if(competitionData->competition->getCurrentCategory() == nullptr)
|
|
|
|
return BRWidget::NotImplementedError;
|
2020-11-03 15:56:43 +01:00
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
return competitionData->competition->getCurrentCategory()->load();
|
2020-11-03 15:56:43 +01:00
|
|
|
}
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
BRCompetition::BRCompetitionData BRProviderDr::parseCompetitionData(QVariantMap rawData, BRWidget::BRFederation federation) {
|
2020-11-04 13:55:37 +01:00
|
|
|
BRCompetition::BRCompetitionData data;
|
|
|
|
|
|
|
|
this->parseCompetitionData(&data, rawData, federation);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* competitionData, QVariantMap rawData, BRWidget::BRFederation federation) {
|
2020-10-31 15:16:06 +01:00
|
|
|
|
|
|
|
QMap<QString, BRCompetition::BRDiscipline> disciplineTranslations = {
|
|
|
|
{"boulder", BRCompetition::Boulder},
|
|
|
|
{"lead", BRCompetition::Lead},
|
|
|
|
{"speed", BRCompetition::Speed}
|
|
|
|
};
|
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
if(rawData.contains("name"))
|
|
|
|
competitionData->name = rawData["name"].toString();
|
|
|
|
else if(rawData.contains("comp_name"))
|
|
|
|
competitionData->name = rawData["comp_name"].toString();
|
2020-11-03 15:56:43 +01:00
|
|
|
|
|
|
|
if(disciplineTranslations.contains(rawData["discipline"].toString()))
|
2020-11-04 13:55:37 +01:00
|
|
|
competitionData->discipline = disciplineTranslations[rawData["discipline"].toString()];
|
2020-11-03 15:56:43 +01:00
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
if(rawData.contains("date"))
|
|
|
|
competitionData->startDate = QDate::fromString(rawData["date"].toString(), "yyyy-MM-dd");
|
|
|
|
if(rawData.contains("date_end"))
|
|
|
|
competitionData->endDate = QDate::fromString(rawData["date_end"].toString(), "yyyy-MM-dd");
|
2020-11-03 15:56:43 +01:00
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
if(rawData.contains("hompage"))
|
|
|
|
competitionData->eventWebsiteUrl = rawData["homepage"].toString();
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
// load infosheet URLs
|
2020-11-03 15:56:43 +01:00
|
|
|
for(int i = 0; i < 2; i++) {
|
|
|
|
QString infosheetName = QStringList({"info", "info2"})[i];
|
|
|
|
if(rawData.contains(infosheetName)) {
|
|
|
|
QString url = rawData[infosheetName].toString();
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
if(federation == BRWidget::DAV)
|
2020-11-04 13:55:37 +01:00
|
|
|
url = "http://ranking.alpenverein.de/" + QString::number(competitionData->startDate.year()) + "/GER/" + rawData["rkey"].toString() + ".pdf";
|
2020-11-03 15:56:43 +01:00
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
competitionData->infosheetUrls.append(url);
|
2020-11-03 15:56:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
// load categories
|
|
|
|
QVariantList categoriesList;
|
|
|
|
if(rawData.contains("cats")) {
|
|
|
|
// we are loading calendar data!
|
|
|
|
QVariantList categoriesList = rawData["cats"].toList();
|
|
|
|
competitionData->categories.clear();
|
|
|
|
for(QVariant categoryVar : categoriesList) {
|
|
|
|
BRCategory::BRCategoryData categoryData;
|
|
|
|
categoryData.name = rawData["name"].toString();
|
|
|
|
BRCategory* category = this->getCategory(federation, rawData["GrpId"].toInt(), categoryData);
|
|
|
|
competitionData->categories.append(category);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// we are loading result data!
|
|
|
|
// TODO: clean up!!
|
|
|
|
if(competitionData->competition->getCurrentCategory()->getId() != rawData["GrpId"].toInt())
|
|
|
|
// if the current category does not match the loaded category, there is some error and we cannot proceed!
|
|
|
|
return;
|
|
|
|
|
|
|
|
// load the category!
|
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
}
|
2020-10-31 15:16:06 +01:00
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
BRCup::BRCupData BRProviderDr::parseCupData(QVariantList categoriesList, QVariantMap rawData, BRWidget::BRFederation federation) {
|
|
|
|
BRCup::BRCupData data;
|
|
|
|
|
|
|
|
data.name = rawData["name"].toString();
|
|
|
|
|
|
|
|
// parse categories
|
|
|
|
for(QVariant categoryName : rawData["cats"].toList()) {
|
|
|
|
// find category name in cats:
|
|
|
|
|
|
|
|
for(QVariant categoryVar : categoriesList) {
|
|
|
|
QVariantMap categoryMap = categoryVar.toMap();
|
|
|
|
if(categoryMap["rkey"].toString() == categoryName.toString()) {
|
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
BRCategory::BRCategoryData categoryData;
|
|
|
|
categoryData.name = rawData["name"].toString();
|
|
|
|
BRCategory* category = this->getCategory(federation, rawData["GrpId"].toInt(), categoryData);
|
2020-11-03 15:56:43 +01:00
|
|
|
data.categories.append(category);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2020-11-04 13:55:37 +01:00
|
|
|
BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRCategory::BRCategoryData* categoryData) {
|
|
|
|
// load category data
|
|
|
|
QString competitionId = QString::number(categoryData->category->getCompetition()->getId());
|
|
|
|
QString categoryId = QString::number(categoryData->category->getId());
|
|
|
|
QString requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?comp=" + competitionId + "&cat=" + categoryId;
|
|
|
|
QVariantMap ret = this->serverRequest(QUrl(requestUrl));
|
|
|
|
|
|
|
|
if(ret["status"] != 200){
|
|
|
|
// request was a failure
|
|
|
|
return BRWidget::BRWidgetStatusCode(ret["status"].toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap data = QJsonDocument::fromJson(ret["text"].toString().toUtf8()).toVariant().toMap();
|
|
|
|
|
|
|
|
this->parseCategoryData(categoryData, data);
|
|
|
|
|
|
|
|
return BRWidget::Success;
|
|
|
|
}
|
|
|
|
|
2020-11-03 15:56:43 +01:00
|
|
|
BRCategory::BRCategoryData BRProviderDr::parseCategoryData(QVariantMap rawData) {
|
|
|
|
BRCategory::BRCategoryData data;
|
2020-11-04 13:55:37 +01:00
|
|
|
this->parseCategoryData(&data, rawData);
|
2020-11-03 15:56:43 +01:00
|
|
|
return data;
|
2020-10-31 15:16:06 +01:00
|
|
|
}
|
2020-11-04 13:55:37 +01:00
|
|
|
|
|
|
|
void BRProviderDr::parseCategoryData(BRCategory::BRCategoryData* categoryData, QVariantMap rawData) {
|
|
|
|
// TODO: status
|
|
|
|
// TODO: sex
|
|
|
|
// TODO: load routes
|
|
|
|
// TODO: athletes
|
|
|
|
//categoryData->name = rawData["name"].toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRRound::BRRoundData* roundData) {
|
|
|
|
|
|
|
|
}
|