- now parsing discipline and status of category

This commit is contained in:
Dorian Zedler 2020-11-08 10:47:44 +01:00
parent 035a2edcdf
commit 9d8e1c7c42
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
13 changed files with 199 additions and 63 deletions

View file

@ -38,6 +38,7 @@ SOURCES += \
sources/brproviderdr.cpp \
sources/brprovidervl.cpp \
sources/brresult.cpp \
sources/brresultdetails.cpp \
sources/brround.cpp \
sources/brseason.cpp \
sources/brserverconnector.cpp \
@ -58,6 +59,7 @@ HEADERS += \
headers/brproviderdr.h \
headers/brprovidervl.h \
headers/brresult.h \
headers/brresultdetails.h \
headers/brround.h \
headers/brseason.h \
headers/brserverconnector.h \

View file

@ -13,15 +13,34 @@ class BRCategory : public BRWidget
{
Q_OBJECT
Q_PROPERTY(QString name READ getName NOTIFY metadataChanged)
Q_PROPERTY(BRDiscipline discipline READ getDiscipline NOTIFY metadataChanged)
Q_PROPERTY(BRCategoryStatus status READ getStatus NOTIFY metadataChanged)
Q_PROPERTY(BRRound* currentRound READ getCurrentRound WRITE setCurrentRound NOTIFY currentRoundChanged)
Q_PROPERTY(QList<QObject*> rounds READ getRoundsQML NOTIFY roundsChanged)
public:
friend class BRProvider;
friend class BRCompetition;
enum BRDiscipline {
UnknownDiscipline = -1,
Speed,
Lead,
Boulder,
Combined
};
enum BRCategoryStatus {
UnknownStatus = -1,
Registration,
Startlist,
Result
};
typedef struct {
const BRCategory* category;
QString name;
BRDiscipline discipline;
BRCategoryStatus status;
BRRound* currentRound;
QList<BRRound*> rounds;
} BRCategoryData;
@ -29,6 +48,8 @@ public:
Q_INVOKABLE BRWidget::BRWidgetStatusCode load() override;
Q_INVOKABLE BRCompetition* getCompetition() const;
Q_INVOKABLE QString getName();
Q_INVOKABLE BRDiscipline getDiscipline();
Q_INVOKABLE BRCategoryStatus getStatus();
Q_INVOKABLE BRRound* getCurrentRound() const;
Q_INVOKABLE void setCurrentRound(BRRound* round);
Q_INVOKABLE QList<BRRound*> getRounds() const;
@ -44,6 +65,8 @@ private:
BRRound* currentRound;
QString name;
BRDiscipline discipline;
BRCategoryStatus status;
QList<BRRound*> rounds;
signals:

View file

@ -15,7 +15,6 @@ class BRCompetition : public BRWidget
{
Q_OBJECT
Q_PROPERTY(QString name READ getName NOTIFY metadataChanged)
Q_PROPERTY(QString discipline READ getDiscipline NOTIFY metadataChanged)
Q_PROPERTY(QDate startDate READ getStartDate NOTIFY metadataChanged)
Q_PROPERTY(QDate endDate READ getEndDate NOTIFY metadataChanged)
Q_PROPERTY(QString dateSpan READ getDateSpan NOTIFY metadataChanged)
@ -31,18 +30,9 @@ public:
friend class BRProvider;
friend class BRLeague;
enum BRDiscipline {
Unknown = -1,
Boulder,
Lead,
Speed
};
Q_ENUM(BRDiscipline)
typedef struct BRCompetitionData {
const BRCompetition* competition;
QString name;
BRDiscipline discipline;
QDate startDate;
QDate endDate;
QUrl eventWebsiteUrl;
@ -56,7 +46,6 @@ public:
Q_INVOKABLE BRWidget::BRWidgetStatusCode load() override;
Q_INVOKABLE QString getName();
Q_INVOKABLE BRDiscipline getDiscipline();
Q_INVOKABLE QDate getStartDate();
Q_INVOKABLE QDate getEndDate();
Q_INVOKABLE QString getDateSpan();
@ -80,7 +69,6 @@ private:
// metadata
QString name;
BRDiscipline discipline;
QDate startDate;
QDate endDate;
BRLeague* league;

View file

@ -22,7 +22,7 @@ protected:
BRLeague::BRLeagueData parseLeagueData(QVariantMap leagueProperties, QVariantMap rawData);
BRWidget::BRWidgetStatusCode getWidgetData(BRCompetition::BRCompetitionData* competitionData) override;
BRCompetition::BRCompetitionData parseCompetitionData(QVariantMap rawData, BRWidget::BRFederation federation);
BRCompetition::BRCompetitionData parseCompetitionData(QVariantMap rawData, QVariantList globalCategoriesList, BRWidget::BRFederation federation);
void parseCompetitionData(BRCompetition::BRCompetitionData* competitionData, QVariantMap rawData, BRWidget::BRFederation federation);
BRCup::BRCupData parseCupData(QVariantList categoriesList, QVariantMap rawData, BRWidget::BRFederation federation);

View file

@ -21,9 +21,9 @@ protected:
void parseLeagueData(BRLeague::BRLeagueData* leagueData, QVariantMap rawData);
BRWidget::BRWidgetStatusCode getWidgetData(BRCompetition::BRCompetitionData* competitionData) override;
BRCompetition::BRCompetitionData parseCompetitionData(QVariantMap rawData, BRWidget::BRFederation federation);
BRCompetition::BRCompetitionData parseCompetitionData(QVariantMap rawData, QVariantList globalCategoriesList, BRWidget::BRFederation federation);
BRCup::BRCupData parseCupData(QVariantMap rawData);
BRCup::BRCupData parseCupData(QVariantMap rawData, QVariantList globalCategoriesList);
BRCategory::BRCategoryData parseCategoryData(QVariantMap rawData);
void parseCategoryData(BRCategory::BRCategoryData* categoryData, QVariantMap rawData);

View file

@ -4,6 +4,7 @@
#include <QObject>
#include "brwidget.h"
#include "brresultdetails.h"
class BRAthlete;
@ -11,6 +12,7 @@ class BRResult : public BRWidget
{
Q_OBJECT
Q_PROPERTY(int rank READ getRank NOTIFY metadataChanged)
Q_PROPERTY(BRResultDetails* details READ getDetails NOTIFY metadataChanged)
Q_PROPERTY(BRAthlete* athlete READ getAthlete NOTIFY metadataChanged)
public:
@ -20,12 +22,14 @@ public:
const BRResult* result;
int rank;
BRResultDetails* data;
BRAthlete* athlete;
} BRResultData;
BRWidget::BRWidgetStatusCode load() override;
Q_INVOKABLE int getRank() const;
Q_INVOKABLE BRResultDetails* getDetails() const;
Q_INVOKABLE BRAthlete* getAthlete() const;
private:
@ -33,6 +37,7 @@ private:
void setData(BRResultData data);
int rank;
BRResultDetails* details;
BRAthlete* athlete;
signals:

13
headers/brresultdetails.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef BRRESULTDATA_H
#define BRRESULTDATA_H
#include <QObject>
class BRResultDetails : public QObject
{
Q_OBJECT
public:
BRResultDetails();
};
#endif // BRRESULTDATA_H

View file

@ -5,6 +5,7 @@
BRCategory::BRCategory(BRProvider* provider, BRWidget::BRFederation federation, int id, BRCategoryData initialData) : BRWidget(provider, federation, id)
{
this->currentRound = nullptr;
this->discipline = UnknownDiscipline;
this->setData(initialData);
}
@ -16,6 +17,14 @@ QString BRCategory::getName() {
return this->name;
}
BRCategory::BRDiscipline BRCategory::getDiscipline() {
return this->discipline;
}
BRCategory::BRCategoryStatus BRCategory::getStatus() {
return this->status;
}
BRRound* BRCategory::getCurrentRound() const {
return this->currentRound;
}
@ -40,6 +49,8 @@ BRCategory::BRCategoryData BRCategory::getData() {
BRCategory::BRCategoryData data {
this,
this->name,
this->discipline,
this->status,
this->currentRound,
this->rounds
};
@ -49,6 +60,8 @@ BRCategory::BRCategoryData BRCategory::getData() {
void BRCategory::setData(BRCategoryData data) {
this->name = data.name;
this->discipline = data.discipline;
this->status = data.status;
emit this->metadataChanged();
if(this->currentRound != data.currentRound) {

View file

@ -21,10 +21,6 @@ QString BRCompetition::getName() {
return this->name;
}
BRCompetition::BRDiscipline BRCompetition::getDiscipline() {
return this->discipline;
}
QDate BRCompetition::getStartDate() {
return this->startDate;
}
@ -105,7 +101,6 @@ BRWidget::BRWidgetStatusCode BRCompetition::load() {
BRCompetitionData newData {
this,
this->name,
this->discipline,
this->startDate,
this->endDate,
this->eventWebsiteUrl,
@ -128,7 +123,6 @@ BRWidget::BRWidgetStatusCode BRCompetition::load() {
void BRCompetition::setData(BRCompetition::BRCompetitionData data) {
this->name = data.name;
this->discipline = data.discipline;
this->startDate = data.startDate;
this->endDate = data.endDate;
this->eventWebsiteUrl = data.eventWebsiteUrl;

View file

@ -182,7 +182,7 @@ BRLeague::BRLeagueData BRProviderDr::parseLeagueData(QVariantMap leaguePropertie
// 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));
BRCompetition* competition = this->getCompetition(federation, competitionVar.toMap()["WetId"].toInt(), this->parseCompetitionData(competitionMap, rawData["cats"].toList(), federation));
data.competitions.append(competition);
}
}
@ -233,22 +233,14 @@ BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRCompetition::BRCompet
return BRWidget::Success;
}
BRCompetition::BRCompetitionData BRProviderDr::parseCompetitionData(QVariantMap rawData, BRWidget::BRFederation federation) {
BRCompetition::BRCompetitionData BRProviderDr::parseCompetitionData(QVariantMap rawData, QVariantList globalCategoriesList, BRWidget::BRFederation federation) {
// Load competition data from calendar
BRCompetition::BRCompetitionData data;
QMap<QString, BRCompetition::BRDiscipline> disciplineTranslations = {
{"boulder", BRCompetition::Boulder},
{"lead", BRCompetition::Lead},
{"speed", BRCompetition::Speed}
};
data.name = rawData["name"].toString();
qDebug() << "-- Parsing competition: " << data.name;
if(disciplineTranslations.contains(rawData["discipline"].toString()))
data.discipline = disciplineTranslations[rawData["discipline"].toString()];
if(rawData.contains("date"))
data.startDate = QDate::fromString(rawData["date"].toString(), "yyyy-MM-dd");
if(rawData.contains("date_end"))
@ -273,11 +265,30 @@ BRCompetition::BRCompetitionData BRProviderDr::parseCompetitionData(QVariantMap
// load categories
QVariantList categoriesList = rawData["cats"].toList();
data.categories.clear();
for(QVariant categoryVar : categoriesList) {
BRCategory::BRCategoryData categoryData;
categoryData.currentRound = nullptr;
categoryData.name = categoryVar.toMap()["name"].toString();
BRCategory* category = this->getCategory(federation, categoryVar.toMap()["GrpId"].toInt(), categoryData);
QVariantMap categoryMap = categoryVar.toMap();
// parse discipline
QString discipline;
if(rawData.contains("discipline"))
// all categories have the same discipline
discipline = rawData["discipline"].toString();
else
// categories discipline may differ
// search category in global categories list
for(QVariant globalCategoryVar : globalCategoriesList) {
QVariantMap globalCategoryMap = globalCategoryVar.toMap();
if(categoryMap["GrpId"].toInt() == globalCategoryMap["GrpId"].toInt()) {
// TODO: sex / gender
discipline = globalCategoryMap["discipline"].toString();
break;
}
}
categoryMap.insert("discipline", discipline);
BRCategory* category = this->getCategory(federation, categoryMap["GrpId"].toInt(), this->parseCategoryData(categoryMap));
data.categories.append(category);
}
@ -297,19 +308,30 @@ void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* compet
// for that, all categories are recreated
QVariantList categoriesList = rawData["categorys"].toList();
// delete old categories
// store old categories
QMap<int, BRCategory*> oldCategories;
for(BRCategory* category : competitionData->categories)
category->deleteLater();
if(!oldCategories.contains(category->getId()))
oldCategories.insert(category->getId(), category);
competitionData->categories.clear();
for(QVariant categoryVar : categoriesList) {
QVariantMap categoryMap = categoryVar.toMap();
int categoryId = categoryMap["GrpId"].toInt();
BRCategory::BRCategoryData categoryData;
categoryData.name = categoryMap["name"].toString();
// restore data that is not available in competition view of the API
if(oldCategories.contains(categoryId)) {
categoryData.status = oldCategories[categoryId]->getStatus();
categoryData.discipline = oldCategories[categoryId]->getDiscipline();
}
categoryData.currentRound = nullptr;
qDebug() << "Loading category: " << categoryData.name;
qDebug() << "Loading category: " << categoryData.name << " with discipline: " << categoryData.discipline;
QVariantMap roundList;
// check if route_names are given:
@ -338,7 +360,7 @@ void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* compet
if(categoryData.currentRound == nullptr && categoryData.rounds.length() > 0)
categoryData.currentRound = categoryData.rounds[0];
BRCategory* category = this->getCategory(federation, categoryMap["GrpId"].toInt(), categoryData);
BRCategory* category = this->getCategory(federation, categoryId, categoryData);
competitionData->categories.append(category);
// restore current category and load its reults
@ -379,7 +401,10 @@ void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* compet
}
}
// load round results
// delete old categories
for(int categoryId : oldCategories.keys()) {
oldCategories[categoryId]->deleteLater();
}
}
}
@ -391,6 +416,8 @@ BRCup::BRCupData BRProviderDr::parseCupData(QVariantList categoriesList, QVarian
data.name = rawData["name"].toString();
qDebug() << "- Parsing Cup: " << data.name;
// parse categories
for(QVariant categoryName : rawData["cats"].toList()) {
// find category name in cats:
@ -398,10 +425,7 @@ BRCup::BRCupData BRProviderDr::parseCupData(QVariantList categoriesList, QVarian
for(QVariant categoryVar : categoriesList) {
QVariantMap categoryMap = categoryVar.toMap();
if(categoryMap["rkey"].toString() == categoryName.toString()) {
BRCategory::BRCategoryData categoryData;
categoryData.name = rawData["name"].toString();
BRCategory* category = this->getCategory(federation, rawData["GrpId"].toInt(), categoryData);
BRCategory* category = this->getCategory(federation, rawData["GrpId"].toInt(), this->parseCategoryData(categoryMap));
data.categories.append(category);
break;
}
@ -413,11 +437,37 @@ BRCup::BRCupData BRProviderDr::parseCupData(QVariantList categoriesList, QVarian
BRCategory::BRCategoryData BRProviderDr::parseCategoryData(QVariantMap rawData) {
BRCategory::BRCategoryData data;
// TODO: status
// TODO: sex
// TODO: load routes
// TODO: athletes
this->parseCategoryData(&data, rawData);
// TODO: gender
data.name = rawData["name"].toString();
data.currentRound = nullptr;
QMap<int, BRCategory::BRCategoryStatus> statusTranslations = {
{4, BRCategory::Registration},
{2, BRCategory::Startlist},
{1, BRCategory::Result},
{0, BRCategory::Result}
};
QMap<QString, BRCategory::BRDiscipline> disciplineTranslations = {
{"boulder", BRCategory::Boulder},
{"lead", BRCategory::Lead},
{"speed", BRCategory::Speed}
};
if(disciplineTranslations.contains(rawData["discipline"].toString()))
data.discipline = disciplineTranslations[rawData["discipline"].toString()];
else
data.discipline = BRCategory::UnknownDiscipline;
// parse status
if(rawData.contains("status") && statusTranslations.contains(rawData["status"].toInt()))
data.status = statusTranslations[rawData["status"].toInt()];
else
data.status = BRCategory::UnknownStatus;
qDebug() << "-- Parsing category: " << data.name << " with discipline: " << data.discipline << " and status: " << data.status;
return data;
}

View file

@ -114,7 +114,7 @@ void BRProviderVl::parseLeagueData(BRLeague::BRLeagueData* data, QVariantMap raw
QVariantMap competitionMap = competitionVar.toMap();
qDebug() << "- Adding competition: " << competitionMap["event"].toString();
BRCompetition* competition = this->getCompetition(federation, competitionVar.toMap()["event_id"].toInt(), this->parseCompetitionData(competitionMap, federation));
BRCompetition* competition = this->getCompetition(federation, competitionVar.toMap()["event_id"].toInt(), this->parseCompetitionData(competitionMap, rawData["d_cats"].toList(), federation));
data->competitions.append(competition);
}
@ -123,7 +123,7 @@ void BRProviderVl::parseLeagueData(BRLeague::BRLeagueData* data, QVariantMap raw
for(QVariant cupVar : cupsVar) {
QVariantMap cupMap = cupVar.toMap();
BRCup* cup = this->getCup(federation, cupMap["cup_id"].toInt(), this->parseCupData(cupMap));
BRCup* cup = this->getCup(federation, cupMap["cup_id"].toInt(), this->parseCupData(cupMap, rawData["d_cats"].toList()));
data->cups.append(cup);
}
}
@ -172,18 +172,11 @@ BRWidget::BRWidgetStatusCode BRProviderVl::getWidgetData(BRCompetition::BRCompet
return BRWidget::Success;
}
BRCompetition::BRCompetitionData BRProviderVl::parseCompetitionData(QVariantMap rawData, BRWidget::BRFederation federation) {
QMap<QString, BRCompetition::BRDiscipline> disciplineTranslations = {
{"boulder", BRCompetition::Boulder},
{"lead", BRCompetition::Lead},
{"speed", BRCompetition::Speed}
};
BRCompetition::BRCompetitionData BRProviderVl::parseCompetitionData(QVariantMap rawData, QVariantList globalCategoriesList, BRWidget::BRFederation federation) {
BRCompetition::BRCompetitionData data;
data.name = rawData["event"].toString();
data.discipline = BRCompetition::Unknown;
data.startDate = QDate::fromString(rawData["starts_at"].toString().split(" ")[0], "yyyy-MM-dd");
data.endDate = QDate::fromString(rawData["ends_at"].toString().split(" ")[0], "yyyy-MM-dd");
@ -200,7 +193,16 @@ BRCompetition::BRCompetitionData BRProviderVl::parseCompetitionData(QVariantMap
QVariantList categoriesList = rawData["d_cats"].toList();
for(QVariant categoryVar : categoriesList) {
QVariantMap categoryMap = categoryVar.toMap();
qDebug() << "-- Adding category: " << categoryMap["name"].toString();
// search category in global categories list
for(QVariant globalCategoryVar : globalCategoriesList) {
QVariantMap globalCategoryMap = globalCategoryVar.toMap();
if(categoryMap["id"].toInt() == globalCategoryMap["id"].toInt()) {
categoryMap.insert("discipline", globalCategoryMap["discipline"].toString());
break;
}
}
BRCategory* category = this->getCategory(federation, categoryMap["id"].toInt(), this->parseCategoryData(categoryMap));
data.categories.append(category);
}
@ -211,7 +213,7 @@ BRCompetition::BRCompetitionData BRProviderVl::parseCompetitionData(QVariantMap
}
BRCup::BRCupData BRProviderVl::parseCupData(QVariantMap rawData) {
BRCup::BRCupData BRProviderVl::parseCupData(QVariantMap rawData, QVariantList globalCategoriesList) {
BRCup::BRCupData data;
data.name = rawData["cup"].toString();
@ -223,9 +225,18 @@ BRCup::BRCupData BRProviderVl::parseCupData(QVariantMap rawData) {
QVariantMap categoryMap = categoryVar.toMap();
int categoryId = categoryMap["ranking_url"].toString().split("/").last().toInt();
// search category in global categories list
for(QVariant globalCategoryVar : globalCategoriesList) {
QVariantMap globalCategoryMap = globalCategoryVar.toMap();
if(categoryId == globalCategoryMap["id"].toInt()) {
categoryMap.insert("discipline", globalCategoryMap["discipline"].toString());
break;
}
}
BRCategory* category = this->getCategory(BRWidget::IFSC, categoryId, this->parseCategoryData(categoryMap));
data.categories.append(category);
}
return data;
@ -235,10 +246,38 @@ BRCup::BRCupData BRProviderVl::parseCupData(QVariantMap rawData) {
BRCategory::BRCategoryData BRProviderVl::parseCategoryData(QVariantMap rawData) {
// TODO: status
// TODO: sex
BRCategory::BRCategoryData data;
data.name = rawData["name"].toString();
// TODO: gender
// parse status and discipline
QMap<QString, BRCategory::BRCategoryStatus> statusTranslations = {
{"registration_pending", BRCategory::Registration},
{"registration_active", BRCategory::Registration},
// TODO {2, BRCategory::Startlist},
{"active", BRCategory::Result},
{"finished", BRCategory::Result}
};
QMap<QString, BRCategory::BRDiscipline> disciplineTranslations = {
{"Boulder", BRCategory::Boulder},
{"Lead", BRCategory::Lead},
{"Speed", BRCategory::Speed}
};
if(disciplineTranslations.contains(rawData["discipline"].toString()))
data.discipline = disciplineTranslations[rawData["discipline"].toString()];
else
data.discipline = BRCategory::UnknownDiscipline;
if(statusTranslations.contains(rawData["status"].toString()))
data.status = statusTranslations[rawData["status"].toString()];
else
data.status = BRCategory::UnknownStatus;
qDebug() << "-- Parsing category: " << data.name << " with discipline: " << data.discipline << " and status: " << data.status;
data.currentRound = nullptr;
// load rounds

View file

@ -14,6 +14,9 @@ BRAthlete* BRResult::getAthlete() const {
return this->athlete;
}
BRResultDetails* BRResult::getDetails() const {
return this->details;
}
void BRResult::setData(BRResultData data) {
this->rank = data.rank;

View file

@ -0,0 +1,6 @@
#include "../headers/brresultdetails.h"
BRResultDetails::BRResultDetails()
{
}