From 85c8760bed66444bc404b3ff798077082ec49469 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Sun, 15 Nov 2020 14:48:12 +0100 Subject: [PATCH] - moved some stuff - results work now (still basic) --- blueROCK.pro | 53 ++++--- headers/brresultdetails.h | 13 -- headers/brwidget.h | 12 ++ headers/{ => competition}/brcategory.h | 20 +-- headers/{ => competition}/brcompetition.h | 0 headers/{ => competition}/brround.h | 10 +- headers/{ => competition/result}/brresult.h | 14 +- headers/competition/result/brresultdetails.h | 50 ++++++ .../result/brresultdetailsgeneralresult.h | 28 ++++ .../result/brresultdetailsunknown.h | 27 ++++ headers/{ => cup}/brcup.h | 0 headers/{ => provider}/brprovider.h | 5 +- headers/{ => provider}/brproviderdr.h | 6 + headers/{ => provider}/brprovidervl.h | 2 +- resources/qml/Components/SelectorPopup.qml | 2 + resources/qml/Pages/ResultPage.qml | 60 +++---- sources/brathlete.cpp | 2 +- sources/brcalendar.cpp | 4 +- sources/brcontroller.cpp | 2 +- sources/brleague.cpp | 4 +- sources/brresult.cpp | 30 ---- sources/brresultdetails.cpp | 6 - sources/brseason.cpp | 4 +- sources/brserverconnector.cpp | 2 +- sources/brwidget.cpp | 4 +- sources/{ => competition}/brcategory.cpp | 37 ++++- sources/{ => competition}/brcompetition.cpp | 23 ++- sources/{ => competition}/brround.cpp | 27 +++- sources/competition/result/brresult.cpp | 55 +++++++ .../competition/result/brresultdetails.cpp | 42 +++++ .../result/brresultdetailsgeneralresult.cpp | 44 ++++++ .../result/brresultdetailsunknown.cpp | 6 + sources/{ => cup}/brcup.cpp | 2 +- sources/main.cpp | 6 +- sources/{ => provider}/brprovider.cpp | 10 +- sources/{ => provider}/brproviderdr.cpp | 146 ++++++++++++------ sources/{ => provider}/brprovidervl.cpp | 79 ++++++++-- 37 files changed, 611 insertions(+), 226 deletions(-) delete mode 100644 headers/brresultdetails.h rename headers/{ => competition}/brcategory.h (80%) rename headers/{ => competition}/brcompetition.h (100%) rename headers/{ => competition}/brround.h (78%) rename headers/{ => competition/result}/brresult.h (69%) create mode 100644 headers/competition/result/brresultdetails.h create mode 100644 headers/competition/result/brresultdetailsgeneralresult.h create mode 100644 headers/competition/result/brresultdetailsunknown.h rename headers/{ => cup}/brcup.h (100%) rename headers/{ => provider}/brprovider.h (92%) rename headers/{ => provider}/brproviderdr.h (86%) rename headers/{ => provider}/brprovidervl.h (93%) delete mode 100644 sources/brresult.cpp delete mode 100644 sources/brresultdetails.cpp rename sources/{ => competition}/brcategory.cpp (62%) rename sources/{ => competition}/brcompetition.cpp (82%) rename sources/{ => competition}/brround.cpp (60%) create mode 100644 sources/competition/result/brresult.cpp create mode 100644 sources/competition/result/brresultdetails.cpp create mode 100644 sources/competition/result/brresultdetailsgeneralresult.cpp create mode 100644 sources/competition/result/brresultdetailsunknown.cpp rename sources/{ => cup}/brcup.cpp (95%) rename sources/{ => provider}/brprovider.cpp (91%) rename sources/{ => provider}/brproviderdr.cpp (77%) rename sources/{ => provider}/brprovidervl.cpp (82%) diff --git a/blueROCK.pro b/blueROCK.pro index 84d5b1e..c049738 100644 --- a/blueROCK.pro +++ b/blueROCK.pro @@ -30,20 +30,22 @@ SOURCES += \ sources/brleague.cpp \ sources/appsettings.cpp \ sources/brcalendar.cpp \ - sources/brcategory.cpp \ - sources/brcompetition.cpp \ - sources/brcontroller.cpp \ - sources/brcup.cpp \ - sources/brprovider.cpp \ - sources/brproviderdr.cpp \ - sources/brprovidervl.cpp \ - sources/brresult.cpp \ - sources/brresultdetails.cpp \ - sources/brround.cpp \ + sources/competition/brround.cpp \ sources/brseason.cpp \ sources/brserverconnector.cpp \ sources/brwidget.cpp \ - sources/main.cpp + sources/competition/result/brresultdetailsgeneralresult.cpp \ + sources/main.cpp \ + sources/brcontroller.cpp \ + sources/provider/brprovider.cpp \ + sources/provider/brproviderdr.cpp \ + sources/provider/brprovidervl.cpp \ + sources/competition/brcategory.cpp \ + sources/competition/brcompetition.cpp \ + sources/competition/result/brresult.cpp \ + sources/competition/result/brresultdetails.cpp \ + sources/competition/result/brresultdetailsunknown.cpp \ + sources/cup/brcup.cpp HEADERS += \ @@ -51,19 +53,28 @@ HEADERS += \ headers/brleague.h \ headers/appsettings.h \ headers/brcalendar.h \ - headers/brcategory.h \ - headers/brcompetition.h \ + headers/competition/brcategory.h \ + headers/competition/brcompetition.h \ headers/brcontroller.h \ - headers/brcup.h \ - headers/brprovider.h \ - headers/brproviderdr.h \ - headers/brprovidervl.h \ - headers/brresult.h \ - headers/brresultdetails.h \ - headers/brround.h \ headers/brseason.h \ headers/brserverconnector.h \ - headers/brwidget.h + headers/brwidget.h \ + headers/competition/result/brresultdetailsgeneralresult.h \ + headers/provider/brprovider.h \ + headers/provider/brproviderdr.h \ + headers/provider/brprovidervl.h \ + headers/competition/brround.h \ + headers/competition/result/brresult.h \ + headers/competition/result/brresultdetails.h \ + headers/competition/result/brresultdetailsunknown.h \ + headers/cup/brcup.h + +INCLUDEPATH += \ + headers \ + headers/provider \ + headers/competition \ + headers/competition/result \ + headers/cup RESOURCES += resources/qml/qml.qrc \ resources/shared/shared.qrc \ diff --git a/headers/brresultdetails.h b/headers/brresultdetails.h deleted file mode 100644 index e638664..0000000 --- a/headers/brresultdetails.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef BRRESULTDATA_H -#define BRRESULTDATA_H - -#include - -class BRResultDetails : public QObject -{ - Q_OBJECT -public: - BRResultDetails(); -}; - -#endif // BRRESULTDATA_H diff --git a/headers/brwidget.h b/headers/brwidget.h index 792a415..e5a3b14 100644 --- a/headers/brwidget.h +++ b/headers/brwidget.h @@ -12,12 +12,24 @@ class BRWidget : public QObject public: enum BRFederation { + UnknownFederation = -1, IFSC, DAV, SAC }; Q_ENUM(BRFederation) + + enum BRDiscipline { + UnknownDiscipline = -1, + Speed, + Lead, + Boulder, + Combined, + AllDisciplines = 99 + }; + Q_ENUM(BRDiscipline) + enum BRWidgetState { Unconfigured = -1, Configured, diff --git a/headers/brcategory.h b/headers/competition/brcategory.h similarity index 80% rename from headers/brcategory.h rename to headers/competition/brcategory.h index 89d666c..55edc15 100644 --- a/headers/brcategory.h +++ b/headers/competition/brcategory.h @@ -6,6 +6,7 @@ #include "brwidget.h" #include "brround.h" #include "brathlete.h" +#include "brresultdetailsgeneralresult.h" class BRCompetition; @@ -16,25 +17,19 @@ class BRCategory : public BRWidget 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(BRRound* generalResult READ getGeneralResult NOTIFY generalResultChanged) Q_PROPERTY(QList 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 }; + Q_ENUM(BRCategoryStatus) typedef struct { const BRCategory* category; @@ -42,6 +37,8 @@ public: BRDiscipline discipline; BRCategoryStatus status; BRRound* currentRound; + BRRound* generalResult; + QList rounds; } BRCategoryData; @@ -51,8 +48,9 @@ public: Q_INVOKABLE BRDiscipline getDiscipline(); Q_INVOKABLE BRCategoryStatus getStatus(); Q_INVOKABLE BRRound* getCurrentRound() const; - Q_INVOKABLE void setCurrentRound(BRRound* round); - Q_INVOKABLE QList getRounds() const; + Q_INVOKABLE void setCurrentRound(BRRound* round = nullptr); + Q_INVOKABLE BRRound* getGeneralResult(); + Q_INVOKABLE QList getRounds(bool includeGeneralResult = false) const; Q_INVOKABLE QList getRoundsQML(); BRCategoryData getData(); @@ -67,12 +65,14 @@ private: QString name; BRDiscipline discipline; BRCategoryStatus status; + BRRound* generalResult; QList rounds; signals: void metadataChanged(); void currentRoundChanged(); void roundsChanged(); + void generalResultChanged(); void resultsChanged(); }; diff --git a/headers/brcompetition.h b/headers/competition/brcompetition.h similarity index 100% rename from headers/brcompetition.h rename to headers/competition/brcompetition.h diff --git a/headers/brround.h b/headers/competition/brround.h similarity index 78% rename from headers/brround.h rename to headers/competition/brround.h index b300ac3..43650b0 100644 --- a/headers/brround.h +++ b/headers/competition/brround.h @@ -18,7 +18,7 @@ public: friend class BRCategory; typedef struct { - const BRRound* round; + BRRound* round; QString name; QList results; @@ -28,16 +28,22 @@ public: Q_INVOKABLE BRCategory* getCategory() const; + Q_INVOKABLE bool isGeneralResult() const; + Q_INVOKABLE QString getName(); + Q_INVOKABLE QList getResults(); Q_INVOKABLE QList getResultsQML(); BRRoundData getData(); + static bool lessThan(BRRound* round1, BRRound* round2); + private: - BRRound(BRProvider* provider, BRWidget::BRFederation federation, int id, BRRoundData initialData); + BRRound(BRProvider* provider, BRWidget::BRFederation federation, int id, BRRoundData initialData, bool generalResult = false); void setData(BRRoundData data); BRCategory* category; + bool generalResult; QString name; QList results; diff --git a/headers/brresult.h b/headers/competition/result/brresult.h similarity index 69% rename from headers/brresult.h rename to headers/competition/result/brresult.h index ee855f2..b281751 100644 --- a/headers/brresult.h +++ b/headers/competition/result/brresult.h @@ -7,38 +7,48 @@ #include "brresultdetails.h" class BRAthlete; +class BRRound; class BRResult : public BRWidget { Q_OBJECT Q_PROPERTY(int rank READ getRank NOTIFY metadataChanged) + Q_PROPERTY(int startNumber READ getStartNumber NOTIFY metadataChanged) Q_PROPERTY(BRResultDetails* details READ getDetails NOTIFY metadataChanged) Q_PROPERTY(BRAthlete* athlete READ getAthlete NOTIFY metadataChanged) public: friend class BRProvider; + friend class BRRound; typedef struct { const BRResult* result; int rank; - BRResultDetails* data; + int startNumber; + BRResultDetails* details; BRAthlete* athlete; } BRResultData; BRWidget::BRWidgetStatusCode load() override; Q_INVOKABLE int getRank() const; + Q_INVOKABLE int getStartNumber() const; Q_INVOKABLE BRResultDetails* getDetails() const; Q_INVOKABLE BRAthlete* getAthlete() const; + Q_INVOKABLE BRRound* getRound() const; + + static bool lessThan(BRResult* result1, BRResult* result2); private: - BRResult(BRProvider* provider, BRWidget::BRFederation federation, int id, BRResultData initialData); + BRResult(BRResultData initialData); void setData(BRResultData data); int rank; + int startNumber; BRResultDetails* details; BRAthlete* athlete; + BRRound* round; signals: void metadataChanged(); diff --git a/headers/competition/result/brresultdetails.h b/headers/competition/result/brresultdetails.h new file mode 100644 index 0000000..b40f24f --- /dev/null +++ b/headers/competition/result/brresultdetails.h @@ -0,0 +1,50 @@ +#ifndef BRRESULTDATA_H +#define BRRESULTDATA_H + +#include + +#include "brwidget.h" + +class BRResult; + +class BRResultDetails : public BRWidget +{ + Q_OBJECT + Q_PROPERTY(BRResultDetailsType type READ getType NOTIFY metadataChanged) +public: + friend class BRResult; + + enum BRResultDetailsType { + UnknownResultType = -1, + GeneralResult, + SpeedQualificationResult, + SpeedFinalResult, + LeadResult, + BoulderResult, + CombinedResult + }; + + BRWidget::BRWidgetStatusCode load() final override; + Q_INVOKABLE virtual QString toString() = 0; + + Q_INVOKABLE virtual QString string() final; + + Q_INVOKABLE BRResultDetailsType getType(); + +protected: + BRResultDetails(BRResultDetailsType type); + + BRResult* getResult(); + +private: + + BRResult* result; + BRResultDetailsType type; + + + BRWidget::BRDiscipline getDiscipline(); +signals: + void metadataChanged(); +}; + +#endif // BRRESULTDATA_H diff --git a/headers/competition/result/brresultdetailsgeneralresult.h b/headers/competition/result/brresultdetailsgeneralresult.h new file mode 100644 index 0000000..5bce886 --- /dev/null +++ b/headers/competition/result/brresultdetailsgeneralresult.h @@ -0,0 +1,28 @@ +#ifndef BRGENERALRESULT_H +#define BRGENERALRESULT_H + +#include +#include +#include "brresultdetails.h" + +class BRResult; + +class BRResultDetailsGeneralResult : public BRResultDetails +{ + Q_OBJECT + Q_PROPERTY(QList results READ getResultsQML NOTIFY resultsChanged) +public: + BRResultDetailsGeneralResult(); + + QList getResults(); + QList getResultsQML(); + + Q_INVOKABLE QString toString() override; + +private: + +signals: + void resultsChanged(); +}; + +#endif // BRGENERALRESULT_H diff --git a/headers/competition/result/brresultdetailsunknown.h b/headers/competition/result/brresultdetailsunknown.h new file mode 100644 index 0000000..296c45a --- /dev/null +++ b/headers/competition/result/brresultdetailsunknown.h @@ -0,0 +1,27 @@ +#ifndef BRRESULTDETAILSUNKNOWN_H +#define BRRESULTDETAILSUNKNOWN_H + +#include + +#include "brresultdetails.h" + +class BRResultDetailsUnknown : public BRResultDetails +{ + Q_OBJECT + Q_PROPERTY(QString score READ toString NOTIFY metadataChanged()) +public: + BRResultDetailsUnknown(QString score); + + Q_INVOKABLE QString toString() { + return this->score; + } + +private: + QString score; + + BRDiscipline getType() { + return BRWidget::UnknownDiscipline; + } +}; + +#endif // BRRESULTDETAILSUNKNOWN_H diff --git a/headers/brcup.h b/headers/cup/brcup.h similarity index 100% rename from headers/brcup.h rename to headers/cup/brcup.h diff --git a/headers/brprovider.h b/headers/provider/brprovider.h similarity index 92% rename from headers/brprovider.h rename to headers/provider/brprovider.h index 4d2d040..8c01ce7 100644 --- a/headers/brprovider.h +++ b/headers/provider/brprovider.h @@ -15,6 +15,7 @@ #include "brathlete.h" #include "brcup.h" #include "brresult.h" +#include "brresultdetailsunknown.h" class BRProvider : public QObject { @@ -41,8 +42,8 @@ protected: virtual BRCup* getCup(BRWidget::BRFederation federation, int id, BRCup::BRCupData initialData) final; virtual BRCategory* getCategory(BRWidget::BRFederation federation, int id, BRCategory::BRCategoryData initialData) final; virtual BRAthlete* getAthlete(BRWidget::BRFederation federation, int id, BRAthlete::BRAthleteData initialData) final; - virtual BRRound* getRound(BRWidget::BRFederation federation, int id, BRRound::BRRoundData initialData) final; - virtual BRResult* getResult(BRWidget::BRFederation federation, int id, BRResult::BRResultData initialData) final; + virtual BRRound* getRound(BRWidget::BRFederation federation, int id, BRRound::BRRoundData initialData, bool generalResult = false) final; + virtual BRResult* getResult(BRResult::BRResultData initialData) final; virtual void setCategoryData(BRCategory* category, BRCategory::BRCategoryData data) final { category->setData(data); diff --git a/headers/brproviderdr.h b/headers/provider/brproviderdr.h similarity index 86% rename from headers/brproviderdr.h rename to headers/provider/brproviderdr.h index 279ca01..d441d18 100644 --- a/headers/brproviderdr.h +++ b/headers/provider/brproviderdr.h @@ -30,6 +30,12 @@ protected: BRCategory::BRCategoryData parseCategoryData(QVariantMap rawData); void parseCategoryData(BRCategory::BRCategoryData* categoryData, QVariantMap rawData); + void parseRoundData(BRRound::BRRoundData* roundData, QVariantMap rawData, QString resultKeyAttachment = ""); + + BRAthlete::BRAthleteData parseAthletedata(QVariantMap rawData); + + BRResult::BRResultData parseResultData(QVariantMap rawData); + private: QMap> leagues; diff --git a/headers/brprovidervl.h b/headers/provider/brprovidervl.h similarity index 93% rename from headers/brprovidervl.h rename to headers/provider/brprovidervl.h index 07705a0..66d77d2 100644 --- a/headers/brprovidervl.h +++ b/headers/provider/brprovidervl.h @@ -26,7 +26,7 @@ protected: BRCup::BRCupData parseCupData(QVariantMap rawData, QVariantList globalCategoriesList); BRCategory::BRCategoryData parseCategoryData(QVariantMap rawData); - void parseCategoryData(BRCategory::BRCategoryData* categoryData, QVariantMap rawData); + //void parseCategoryData(BRCategory::BRCategoryData* categoryData, QVariantMap rawData); BRRound::BRRoundData parseRoundData(QVariantMap rawData); void parseRoundData(BRRound::BRRoundData* roundData, QVariantMap rawData); diff --git a/resources/qml/Components/SelectorPopup.qml b/resources/qml/Components/SelectorPopup.qml index 89bf15b..f9dcd4d 100644 --- a/resources/qml/Components/SelectorPopup.qml +++ b/resources/qml/Components/SelectorPopup.qml @@ -51,6 +51,7 @@ Dialog { text: control.title onLinkActivated: { + console.log("Opening " + link) Qt.openUrlExternally(link) } } @@ -72,6 +73,7 @@ Dialog { text: control.subTitle onLinkActivated: { + console.log("Opening " + link) Qt.openUrlExternally(link) } diff --git a/resources/qml/Pages/ResultPage.qml b/resources/qml/Pages/ResultPage.qml index bdf09fb..07ecbed 100644 --- a/resources/qml/Pages/ResultPage.qml +++ b/resources/qml/Pages/ResultPage.qml @@ -136,7 +136,7 @@ BRWidgetPage { bottom: routeSelectTb.top } - model: control.data.currentCategory.currentRound.results + model: control.data.results onRefresh: { control.data.load() @@ -172,7 +172,7 @@ BRWidgetPage { enabled: speedFlowChartBackgroundRect.state === "hidden" - width: parent.width + width: resultLv.width height: 70 text: "" @@ -215,7 +215,7 @@ BRWidgetPage { id: partDelFirstRow width: parent.width - height: parent.height // TODO - partDelSecondRow.height + height: parent.height - partDelSecondRow.height Label { height: parent.height @@ -264,13 +264,13 @@ BRWidgetPage { } } } -/* + Row { id: partDelSecondRow width: parent.width - height: 0 // TODO multiResRow.active || multiGenResRow.active || resultLa.acitve ? parent.height / 2 : 0 - + height: resultLa.acitve ? parent.height / 2 : 0 // TODO multiResRow.active || multiGenResRow.active || resultLa.acitve ? parent.height / 2 : 0 +/* Row { id: multiResRow @@ -585,28 +585,28 @@ BRWidgetPage { } } - +*/ Label { id: resultLa - property bool acitve: false // TODO ( boulderResRep.model > 0 || widgetData["discipline"] !== "boulder" ) && parseInt(widgetData[ "route_order" ]) > -1 + property bool acitve: true // TODO ( boulderResRep.model > 0 || widgetData["discipline"] !== "boulder" ) && parseInt(widgetData[ "route_order" ]) > -1 - width: enabled ? parent.width * 0.25:0 + width: enabled ? parent.width * 0.75:0 height: enabled ? parent.height:0 - enabled: ( boulderResRep.model > 0 || widgetData["discipline"] !== "boulder" ) && parseInt(widgetData[ "route_order" ]) > -1 + enabled: true //( boulderResRep.model > 0 || widgetData["discipline"] !== "boulder" ) && parseInt(widgetData[ "route_order" ]) > -1 verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignHCenter + horizontalAlignment: Text.AlignLeft fontSizeMode: Text.Fit font.pixelSize: Math.abs( height * 0.6 ) minimumPixelSize: 1 - text: widgetData[ "participants" ][partDel.ind]["result"] === undefined ? "":widgetData[ "participants" ][partDel.ind]["result"] + text: partDel.thisData.details.string() } } - */ + } } @@ -652,25 +652,10 @@ BRWidgetPage { position: TabBar.Footer - currentIndex: getIndex(control.data.currentCategory.currentRound) + currentIndex: tabs.indexOf(control.data.currentCategory.currentRound) - function getIndex(round) { - //console.log("getting index for route number: " + routeNumber) - - if(tabs === undefined){ - return - } - - for(var i = 0; i < tabs.length; i++){ - //console.log(tabs[i]) - if(tabs[i] === round){ - //console.log("found index: " + i) - return i - } - } - - - return 0 + onTabsChanged: { + console.log("tabs: " + tabs + " rounds: " + control.data.currentCategory.rounds) } Repeater { @@ -679,7 +664,7 @@ BRWidgetPage { model: routeSelectTb.tabs onModelChanged: { - routeSelectTb.setCurrentIndex(routeSelectTb.getIndex(control.data.currentCategory.currentRound)) + //routeSelectTb.setCurrentIndex(routeSelectTb.tabs.indexOf(control.data.currentCategory.currentRound)) } delegate: TabButton { @@ -693,7 +678,6 @@ BRWidgetPage { } } } - } Rectangle { @@ -702,13 +686,13 @@ BRWidgetPage { state: "hidden" anchors { - top: parent.top - bottom: parent.bottom - left: parent.right + top: control.top + bottom: control.bottom + left: control.right } - width: parent.width - height: parent.height + width: control.width + height: control.height color: Material.background diff --git a/sources/brathlete.cpp b/sources/brathlete.cpp index 01a3759..a49a828 100644 --- a/sources/brathlete.cpp +++ b/sources/brathlete.cpp @@ -1,4 +1,4 @@ -#include "../headers/brathlete.h" +#include "brathlete.h" BRAthlete::BRAthlete(BRProvider* provider, BRWidget::BRFederation federation, int id, BRAthleteData initialData) : BRWidget(provider, federation, id) { diff --git a/sources/brcalendar.cpp b/sources/brcalendar.cpp index 571fc91..813fab2 100644 --- a/sources/brcalendar.cpp +++ b/sources/brcalendar.cpp @@ -1,5 +1,5 @@ -#include "../headers/brcalendar.h" -#include "headers/brprovider.h" +#include "brcalendar.h" +#include "brprovider.h" BRCalendar::BRCalendar(BRProvider* provider, BRFederation federation) : BRWidget(provider, federation, -1) { diff --git a/sources/brcontroller.cpp b/sources/brcontroller.cpp index 9c3d21e..02141cf 100644 --- a/sources/brcontroller.cpp +++ b/sources/brcontroller.cpp @@ -1,4 +1,4 @@ -#include "../headers/brcontroller.h" +#include "brcontroller.h" BRController::BRController(QObject *parent) : QObject(parent) { diff --git a/sources/brleague.cpp b/sources/brleague.cpp index cefff79..00e7d0d 100644 --- a/sources/brleague.cpp +++ b/sources/brleague.cpp @@ -1,5 +1,5 @@ -#include "headers/brleague.h" -#include "headers/brprovider.h" +#include "brleague.h" +#include "brprovider.h" BRLeague::BRLeague(BRProvider* provider, BRWidget::BRFederation federation, int id, BRLeagueData initialData) : BRWidget(provider, federation, id) { diff --git a/sources/brresult.cpp b/sources/brresult.cpp deleted file mode 100644 index fe8b3bd..0000000 --- a/sources/brresult.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "headers/brresult.h" - -BRResult::BRResult(BRProvider* provider, BRWidget::BRFederation federation, int id, BRResultData initialData) : BRWidget(provider, federation, id) -{ - this->setData(initialData); -} - - -int BRResult::getRank() const { - return this->rank; -} - -BRAthlete* BRResult::getAthlete() const { - return this->athlete; -} - -BRResultDetails* BRResult::getDetails() const { - return this->details; -} - -void BRResult::setData(BRResultData data) { - this->rank = data.rank; - this->athlete = data.athlete; - emit this->metadataChanged(); -} - - -BRWidget::BRWidgetStatusCode BRResult::load() { - return BRWidget::OpeationNotSupportedError; -} diff --git a/sources/brresultdetails.cpp b/sources/brresultdetails.cpp deleted file mode 100644 index d76882f..0000000 --- a/sources/brresultdetails.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "../headers/brresultdetails.h" - -BRResultDetails::BRResultDetails() -{ - -} diff --git a/sources/brseason.cpp b/sources/brseason.cpp index edf115b..2ec2768 100644 --- a/sources/brseason.cpp +++ b/sources/brseason.cpp @@ -1,5 +1,5 @@ -#include "headers/brseason.h" -#include "headers/brprovider.h" +#include "brseason.h" +#include "brprovider.h" using namespace std; diff --git a/sources/brserverconnector.cpp b/sources/brserverconnector.cpp index 0f73ca5..2e82fbb 100644 --- a/sources/brserverconnector.cpp +++ b/sources/brserverconnector.cpp @@ -16,7 +16,7 @@ along with this program. If not, see . */ -#include "headers/brserverconnector.h" +#include "brserverconnector.h" BRServerConnector::BRServerConnector(QObject *parent) : QObject(parent) { diff --git a/sources/brwidget.cpp b/sources/brwidget.cpp index 761003a..e08e7ba 100644 --- a/sources/brwidget.cpp +++ b/sources/brwidget.cpp @@ -1,6 +1,6 @@ -#include "../headers/brwidget.h" +#include "brwidget.h" -#include "headers/brprovider.h" +#include "brprovider.h" BRWidget::BRWidget(BRProvider* provider, BRFederation federation, int id) : QObject(provider), provider(provider), federation(federation), id(id) { diff --git a/sources/brcategory.cpp b/sources/competition/brcategory.cpp similarity index 62% rename from sources/brcategory.cpp rename to sources/competition/brcategory.cpp index c115c12..e7eb543 100644 --- a/sources/brcategory.cpp +++ b/sources/competition/brcategory.cpp @@ -1,11 +1,14 @@ -#include "../headers/brcategory.h" -#include "headers/brprovider.h" -#include "headers/brcompetition.h" +#include "brcategory.h" +#include "brprovider.h" +#include "brcompetition.h" BRCategory::BRCategory(BRProvider* provider, BRWidget::BRFederation federation, int id, BRCategoryData initialData) : BRWidget(provider, federation, id) { this->currentRound = nullptr; this->discipline = UnknownDiscipline; + this->generalResult = nullptr; + connect(this, &BRCategory::generalResultChanged, this, &BRCategory::resultsChanged); + connect(this, &BRCategory::roundsChanged, this, &BRCategory::resultsChanged); this->setData(initialData); } @@ -30,28 +33,39 @@ BRRound* BRCategory::getCurrentRound() const { } void BRCategory::setCurrentRound(BRRound* round) { - if(!this->rounds.contains(round)) + if(!this->rounds.contains(round) && this->generalResult != round) return; this->currentRound = round; emit this->currentRoundChanged(); } -QList BRCategory::getRounds() const { - return this->rounds; +BRRound* BRCategory::getGeneralResult() { + return this->generalResult; +} + +QList BRCategory::getRounds(bool includeGeneralResult) const { + QList rounds; + if(includeGeneralResult && this->generalResult != nullptr) + rounds.append(this->generalResult); + + rounds.append(this->rounds); + + return rounds; } QList BRCategory::getRoundsQML() { - return this->listToQmlList(this->rounds); + return this->listToQmlList(this->getRounds(true)); } BRCategory::BRCategoryData BRCategory::getData() { BRCategory::BRCategoryData data { this, - this->name, + this->name, this->discipline, this->status, this->currentRound, + this->generalResult, this->rounds }; @@ -69,6 +83,13 @@ void BRCategory::setData(BRCategoryData data) { emit this->currentRoundChanged(); } + if(this->generalResult != data.generalResult) { + this->generalResult = data.generalResult; + this->generalResult->category = this; + connect(this->generalResult, &BRRound::resultsChanged, this, &BRCategory::generalResultChanged); + emit this->generalResultChanged(); + } + if(this->rounds != data.rounds) { this->rounds.clear(); this->rounds = data.rounds; diff --git a/sources/brcompetition.cpp b/sources/competition/brcompetition.cpp similarity index 82% rename from sources/brcompetition.cpp rename to sources/competition/brcompetition.cpp index 762bb8f..b1b6db6 100644 --- a/sources/brcompetition.cpp +++ b/sources/competition/brcompetition.cpp @@ -1,11 +1,12 @@ -#include "headers/brcompetition.h" -#include "headers/brleague.h" -#include "headers/brprovider.h" +#include "brcompetition.h" +#include "brleague.h" +#include "brprovider.h" BRCompetition::BRCompetition(BRProvider* provider, BRWidget::BRFederation federation, int id, BRCompetitionData initialData) : BRWidget(provider, federation, id) { this->currentCategory = nullptr; this->eventWebsiteUrl = ""; this->pinned = false; + connect(this, &BRCompetition::categoriesChanged, this, &BRCompetition::resultsChanged); this->setData(initialData); } @@ -81,9 +82,13 @@ void BRCompetition::setCurrentCategory(BRCategory* category) { QString currentRoundName = this->currentCategory->getCurrentRound()->getName(); // search round name in new category - for(BRRound* round : category->getRounds()) + for(BRRound* round : category->getRounds()) { + qDebug() << "Trying to restore round: " << currentRoundName << " with round: " << round->getName(); if(round->getName() == currentRoundName) category->setCurrentRound(round); + } + + qDebug() << "Restored round with ID: " << category->currentRound->getId(); } this->currentCategory = category; @@ -91,10 +96,16 @@ void BRCompetition::setCurrentCategory(BRCategory* category) { } QList BRCompetition::getResultsQML() { - if(this->currentCategory == nullptr || this->currentCategory->getCurrentRound() == nullptr) + if(this->currentCategory == nullptr) return {}; - return this->currentCategory->getCurrentRound()->getResultsQML(); + qDebug() << "getting results"; + if( this->currentCategory->getCurrentRound() != nullptr) + return this->currentCategory->getCurrentRound()->getResultsQML(); + else if(this->currentCategory->getGeneralResult() != nullptr) + return this->currentCategory->getGeneralResult()->getResultsQML(); + else + return {}; } BRWidget::BRWidgetStatusCode BRCompetition::load() { diff --git a/sources/brround.cpp b/sources/competition/brround.cpp similarity index 60% rename from sources/brround.cpp rename to sources/competition/brround.cpp index 9953250..fe39a56 100644 --- a/sources/brround.cpp +++ b/sources/competition/brround.cpp @@ -1,8 +1,10 @@ -#include "../headers/brround.h" -#include "headers/brprovider.h" +#include "brround.h" +#include "brprovider.h" -BRRound::BRRound(BRProvider* provider, BRWidget::BRFederation federation, int id, BRRoundData initialData) : BRWidget(provider, federation, id) +BRRound::BRRound(BRProvider* provider, BRWidget::BRFederation federation, int id, BRRoundData initialData, bool generalResult) : BRWidget(provider, federation, id) { + this->generalResult = generalResult; + this->results = {}; this->setData(initialData); } @@ -10,10 +12,18 @@ BRCategory* BRRound::getCategory() const { return this->category; } +bool BRRound::isGeneralResult() const { + return this->generalResult; +} + QString BRRound::getName() { return this->name; } +QList BRRound::getResults() { + return this->results; +} + QList BRRound::getResultsQML() { return this->listToQmlList(this->results); } @@ -39,6 +49,17 @@ void BRRound::setData(BRRoundData data) { if(this->results != data.results) { this->results.clear(); this->results = data.results; + + for(BRResult* result : this->results) + result->round = this; + emit this->resultsChanged(); } } + + +bool BRRound::lessThan(BRRound* round1, BRRound* round2) { + // TODO ?? + return round1->getId() < round2->getId(); +} + diff --git a/sources/competition/result/brresult.cpp b/sources/competition/result/brresult.cpp new file mode 100644 index 0000000..812f5bb --- /dev/null +++ b/sources/competition/result/brresult.cpp @@ -0,0 +1,55 @@ +#include "brresult.h" +#include "brround.h" +#include "brcategory.h" + +BRResult::BRResult(BRResultData initialData) : BRWidget(nullptr, BRWidget::UnknownFederation, -1) +{ + this->round = nullptr; + this->setData(initialData); +} + +int BRResult::getRank() const { + return this->rank; +} + +int BRResult::getStartNumber() const { + return this->startNumber; +} + +BRAthlete* BRResult::getAthlete() const { + return this->athlete; +} + +BRResultDetails* BRResult::getDetails() const { + return this->details; +} + +BRRound* BRResult::getRound() const { + return this->round; +} + +void BRResult::setData(BRResultData data) { + this->rank = data.rank; + this->startNumber = data.startNumber; + + this->details = data.details; + if(data.details != nullptr) + this->details->result = this; + + this->athlete = data.athlete; + emit this->metadataChanged(); +} + + +BRWidget::BRWidgetStatusCode BRResult::load() { + return BRWidget::OpeationNotSupportedError; +} + + +bool BRResult::lessThan(BRResult* result1, BRResult* result2) { + if(result1->getAthlete()->getId() == result2->getAthlete()->getId()) + return BRRound::lessThan(result1->getRound(), result2->getRound()); + else + return result1->getRank() < result2->getRank(); + +} diff --git a/sources/competition/result/brresultdetails.cpp b/sources/competition/result/brresultdetails.cpp new file mode 100644 index 0000000..2b1940f --- /dev/null +++ b/sources/competition/result/brresultdetails.cpp @@ -0,0 +1,42 @@ +#include "brresultdetails.h" + +BRResultDetails::BRResultDetails(BRResultDetailsType type) : BRWidget(nullptr, BRWidget::UnknownFederation, -1) +{ + this->type = type; +} + +QString BRResultDetails::string() { + return this->toString(); +} + +BRResultDetails::BRResultDetailsType BRResultDetails::getType() { + return this->type; +} + +BRResult* BRResultDetails::getResult() { + return this->result; +} + +BRWidget::BRDiscipline BRResultDetails::getDiscipline() { + switch (this->type) { + case GeneralResult: + return BRWidget::AllDisciplines; + case SpeedQualificationResult: + case SpeedFinalResult: + return BRWidget::Speed; + case LeadResult: + return BRWidget::Lead; + case BoulderResult: + return BRWidget::Boulder; + case CombinedResult: + return BRWidget::Combined; + case UnknownResultType: + return BRWidget::AllDisciplines; + default: + return BRWidget::UnknownDiscipline; + } +} + +BRWidget::BRWidgetStatusCode BRResultDetails::load() { + return BRWidget::OpeationNotSupportedError; +} diff --git a/sources/competition/result/brresultdetailsgeneralresult.cpp b/sources/competition/result/brresultdetailsgeneralresult.cpp new file mode 100644 index 0000000..d82a734 --- /dev/null +++ b/sources/competition/result/brresultdetailsgeneralresult.cpp @@ -0,0 +1,44 @@ +#include "brresultdetailsgeneralresult.h" +#include "brcategory.h" +#include "brresult.h" + +BRResultDetailsGeneralResult::BRResultDetailsGeneralResult() : BRResultDetails(BRResultDetails::GeneralResult) +{ + +} + +QString BRResultDetailsGeneralResult::toString() { + QString resultString = ""; + + for(BRResult* result : this->getResults()) + resultString += result->getDetails()->toString() + " | " ; + + resultString = resultString.left(resultString.length() - 3); + + return resultString; +} + +QList BRResultDetailsGeneralResult::getResults() { + + if(this->getResult() == nullptr || this->getResult()->getRound() == nullptr || this->getResult()->getRound()->getCategory() == nullptr) + return {}; + + BRCategory* category = this->getResult()->getRound()->getCategory(); + + // get all results of this athlete from all rounds + QList results; + for(BRRound* round : category->getRounds()) { + for(BRResult* result : round->getResults()) { + if(result->getAthlete()->getId() == this->getResult()->getAthlete()->getId()) { + results.append(result); + } + } + } + + return results; +} + +QList BRResultDetailsGeneralResult::getResultsQML() { + return this->listToQmlList(this->getResults()); +} + diff --git a/sources/competition/result/brresultdetailsunknown.cpp b/sources/competition/result/brresultdetailsunknown.cpp new file mode 100644 index 0000000..7be96f5 --- /dev/null +++ b/sources/competition/result/brresultdetailsunknown.cpp @@ -0,0 +1,6 @@ +#include "brresultdetailsunknown.h" + +BRResultDetailsUnknown::BRResultDetailsUnknown(QString score) : BRResultDetails(BRResultDetails::UnknownResultType) +{ + this->score = score; +} diff --git a/sources/brcup.cpp b/sources/cup/brcup.cpp similarity index 95% rename from sources/brcup.cpp rename to sources/cup/brcup.cpp index 4a0422d..481a417 100644 --- a/sources/brcup.cpp +++ b/sources/cup/brcup.cpp @@ -1,4 +1,4 @@ -#include "../headers/brcup.h" +#include "brcup.h" BRCup::BRCup(BRProvider* provider, BRWidget::BRFederation federation, int id, BRCupData initialData) : BRWidget(provider, federation, id) { diff --git a/sources/main.cpp b/sources/main.cpp index 0faf879..028d5f5 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -23,9 +23,9 @@ #include #include -#include "headers/brserverconnector.h" -#include "headers/appsettings.h" -#include "headers/brcontroller.h" +#include "brserverconnector.h" +#include "appsettings.h" +#include "brcontroller.h" int main(int argc, char *argv[]) { diff --git a/sources/brprovider.cpp b/sources/provider/brprovider.cpp similarity index 91% rename from sources/brprovider.cpp rename to sources/provider/brprovider.cpp index b85db6b..40d3bee 100644 --- a/sources/brprovider.cpp +++ b/sources/provider/brprovider.cpp @@ -1,4 +1,4 @@ -#include "../headers/brprovider.h" +#include "brprovider.h" BRProvider::BRProvider(QObject *parent) : QObject(parent) { @@ -35,13 +35,13 @@ BRAthlete* BRProvider::getAthlete(BRWidget::BRFederation federation, int id, BRA return new BRAthlete(this, federation, id, initialData); } -BRRound* BRProvider::getRound(BRWidget::BRFederation federation, int id, BRRound::BRRoundData initialData) { - return new BRRound(this, federation, id, initialData); +BRRound* BRProvider::getRound(BRWidget::BRFederation federation, int id, BRRound::BRRoundData initialData, bool generalResult) { + return new BRRound(this, federation, id, initialData, generalResult); } -BRResult* BRProvider::getResult(BRWidget::BRFederation federation, int id, BRResult::BRResultData initialData) { - return new BRResult(this, federation, id, initialData); +BRResult* BRProvider::getResult(BRResult::BRResultData initialData) { + return new BRResult(initialData); } QVariantMap BRProvider::serverRequest(QUrl serviceUrl, QList additionalHeaders, QUrlQuery postData) diff --git a/sources/brproviderdr.cpp b/sources/provider/brproviderdr.cpp similarity index 77% rename from sources/brproviderdr.cpp rename to sources/provider/brproviderdr.cpp index e4f1213..692e00d 100644 --- a/sources/brproviderdr.cpp +++ b/sources/provider/brproviderdr.cpp @@ -1,4 +1,4 @@ -#include "../headers/brproviderdr.h" +#include "brproviderdr.h" BRProviderDr::BRProviderDr(QObject *parent) : BRProvider(parent) { @@ -210,21 +210,32 @@ BRWidget::BRWidgetStatusCode BRProviderDr::getWidgetData(BRCompetition::BRCompet // reload all data BRCategory* currentCategory = competitionData->competition->getCurrentCategory(); + QVariantMap ret; + int retryCount = 0; - // load category data - QString competitionId = QString::number(currentCategory->getCompetition()->getId()); - QString categoryId = QString::number(currentCategory->getId()); - QString requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?comp=" + competitionId + "&cat=" + categoryId; + // handle route not found errors + do { + retryCount ++; + // load category data + QString competitionId = QString::number(currentCategory->getCompetition()->getId()); + QString categoryId = QString::number(currentCategory->getId()); + QString requestUrl = "https://www.digitalrock.de/egroupware/ranking/json.php?comp=" + competitionId + "&cat=" + categoryId; - if(currentCategory->getCurrentRound() != nullptr && currentCategory->getCurrentRound()->getId() >= 0) - requestUrl += "&route=" + QString::number(currentCategory->getCurrentRound()->getId()); + if(currentCategory->getCurrentRound() != nullptr && currentCategory->getCurrentRound()->getId() >= 0) + requestUrl += "&route=" + QString::number(currentCategory->getCurrentRound()->getId()); - QVariantMap ret = this->serverRequest(QUrl(requestUrl)); + ret = this->serverRequest(QUrl(requestUrl)); - if(ret["status"] != 200){ - // request was a failure - return BRWidget::BRWidgetStatusCode(ret["status"].toInt()); - } + // handle route not found errors + if(ret["status"] != 200 && (ret["status"] != 404 || retryCount > 1)){ + // request was a failure + return BRWidget::BRWidgetStatusCode(ret["status"].toInt()); + } + + // if 404 is returned, the route probaply does not exist -> try again without route + currentCategory->setCurrentRound(currentCategory->getGeneralResult()); + + } while(ret["status"] != 200); QVariantMap data = QJsonDocument::fromJson(ret["text"].toString().toUtf8()).toVariant().toMap(); @@ -271,16 +282,19 @@ BRCompetition::BRCompetitionData BRProviderDr::parseCompetitionData(QVariantMap // parse discipline QString discipline; - if(rawData.contains("discipline")) + if(rawData.contains("discipline")) { // all categories have the same discipline discipline = rawData["discipline"].toString(); + // remove numbers (the Year of a competition is in the discipline somtimes) + discipline = discipline.remove( QRegExp("/[0-9]/g") ); + } 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 + // TODO: gender discipline = globalCategoryMap["discipline"].toString(); break; } @@ -330,6 +344,7 @@ void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* compet } categoryData.currentRound = nullptr; + categoryData.generalResult = nullptr; qDebug() << "Loading category: " << categoryData.name << " with discipline: " << categoryData.discipline; @@ -337,13 +352,10 @@ void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* compet // check if route_names are given: if(rawData.contains("route_names")) roundList = rawData["route_names"].toMap(); - else - // if they are not -> insert Qualification - roundList.insert("-1", "Qualifikation"); // load rounds for(QString roundId : roundList.keys()) { - if(roundId.toInt() > categoryMap["route_order"].toInt()) + if(roundId.toInt() < 0) continue; BRRound::BRRoundData roundData; @@ -356,9 +368,14 @@ void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* compet categoryData.currentRound = round; } + // general result + BRRound::BRRoundData generalResultRoundData; + generalResultRoundData.name = "Gesamtergebnis"; + categoryData.generalResult = this->getRound(competitionData->competition->getFederation(), -1, generalResultRoundData, true); + // set default round if it was not restored - if(categoryData.currentRound == nullptr && categoryData.rounds.length() > 0) - categoryData.currentRound = categoryData.rounds[0]; + if(categoryData.currentRound == nullptr) + categoryData.currentRound = categoryData.generalResult; BRCategory* category = this->getCategory(federation, categoryId, categoryData); competitionData->categories.append(category); @@ -367,37 +384,21 @@ void BRProviderDr::parseCompetitionData(BRCompetition::BRCompetitionData* compet if(category->getId() == rawData["GrpId"]) { competitionData->currentCategory = category; + // if we have a currentRound or a general result if(categoryData.currentRound != nullptr) { + qDebug() << "-- Current Round is: " << categoryData.currentRound->getName() << " with id: " << categoryData.currentRound->getId(); BRRound::BRRoundData roundData = categoryData.currentRound->getData(); - roundData.results = {}; - // load results - QVariantList resultList = rawData["participants"].toList(); - for(QVariant resultVar : resultList) { - QVariantMap resultMap = resultVar.toMap(); - // load athlete - BRAthlete::BRAthleteData athleteData; - // TODO: start number - athleteData.firstName = resultMap["firstname"].toString(); - athleteData.lastName = resultMap["lastname"].toString(); - athleteData.federation = resultMap["federation"].toString(); - athleteData.federationUrl = resultMap["fed_url"].toUrl(); - athleteData.nation = resultMap["nation"].toString(); - athleteData.city = resultMap["city"].toString(); - athleteData.yearOfBirth = resultMap["birthyear"].toInt(); - qDebug() << "--- Adding athlete: " << athleteData.firstName << " " << athleteData.lastName; - - BRAthlete* athlete = this->getAthlete(BRWidget::IFSC, resultMap["athlete_id"].toInt(), athleteData); - - // load result - QString resultNumber = categoryData.currentRound->getId() < 0 ? "":QString::number(categoryData.currentRound->getId()); - BRResult::BRResultData resultData; - resultData.rank = resultMap["result_rank"].toInt(); - resultData.athlete = athlete; - BRResult* result = this->getResult(federation, -1, resultData); - roundData.results.append(result); - } - + this->parseRoundData(&roundData, rawData); this->setRoundData(categoryData.currentRound, roundData); + + // if we have a general result -> load all other round results + if(categoryData.currentRound->isGeneralResult()) { + for(BRRound* round : categoryData.rounds) { + BRRound::BRRoundData roundData = round->getData(); + this->parseRoundData(&roundData, rawData, QString::number(round->getId())); + this->setRoundData(round, roundData); + } + } } } @@ -441,6 +442,7 @@ BRCategory::BRCategoryData BRProviderDr::parseCategoryData(QVariantMap rawData) data.name = rawData["name"].toString(); data.currentRound = nullptr; + data.generalResult = nullptr; QMap statusTranslations = { {4, BRCategory::Registration}, @@ -477,3 +479,51 @@ void BRProviderDr::parseCategoryData(BRCategory::BRCategoryData* categoryData, Q } + +void BRProviderDr::parseRoundData(BRRound::BRRoundData* roundData, QVariantMap rawData, QString resultKeyAttachment) { + roundData->results = {}; + // load results + QVariantList resultList = rawData["participants"].toList(); + for(QVariant resultVar : resultList) { + QVariantMap resultMap = resultVar.toMap(); + // load athlete + BRAthlete* athlete = this->getAthlete(roundData->round->getFederation(), resultMap["PerId"].toInt(), this->parseAthletedata(resultMap)); + + // load result + // TODO: start number + BRResult::BRResultData resultData; + resultData.startNumber = resultMap["start_number"].toInt(); + resultData.athlete = athlete; + resultData.rank = resultMap["result_rank" + resultKeyAttachment].toInt(); + resultData.details = nullptr; + + // load details: + // - check if we have a general result + if(roundData->round->isGeneralResult()) + resultData.details = new BRResultDetailsGeneralResult(); + else + resultData.details = new BRResultDetailsUnknown(resultMap["result" + resultKeyAttachment].toString()); + + BRResult* result = this->getResult(resultData); + roundData->results.append(result); + } +} + +BRAthlete::BRAthleteData BRProviderDr::parseAthletedata(QVariantMap rawData) { + BRAthlete::BRAthleteData data; + + data.firstName = rawData["firstname"].toString(); + data.lastName = rawData["lastname"].toString(); + data.federation = rawData["federation"].toString(); + data.federationUrl = rawData["fed_url"].toUrl(); + data.nation = rawData["nation"].toString(); + data.city = rawData["city"].toString(); + data.yearOfBirth = rawData["birthyear"].toInt(); + qDebug() << "--- Parsing athlete: " << data.firstName << " " << data.lastName; + + return data; +} + +BRResult::BRResultData BRProviderDr::parseResultData(QVariantMap rawData) { + +} diff --git a/sources/brprovidervl.cpp b/sources/provider/brprovidervl.cpp similarity index 82% rename from sources/brprovidervl.cpp rename to sources/provider/brprovidervl.cpp index f7e3538..d051977 100644 --- a/sources/brprovidervl.cpp +++ b/sources/provider/brprovidervl.cpp @@ -1,4 +1,4 @@ -#include "headers/brprovidervl.h" +#include "brprovidervl.h" BRProviderVl::BRProviderVl(QObject *parent) : BRProvider(parent) { @@ -165,8 +165,9 @@ BRWidget::BRWidgetStatusCode BRProviderVl::getWidgetData(BRCompetition::BRCompet QVariantMap data = QJsonDocument::fromJson(ret["text"].toString().toUtf8()).toVariant().toMap(); + // TODO: reload all rounds, as they may change! + // (load category instead of competition) this->parseRoundData(&roundData, data); - this->setRoundData(currentRound, roundData); return BRWidget::Success; @@ -186,7 +187,7 @@ BRCompetition::BRCompetitionData BRProviderVl::parseCompetitionData(QVariantMap for(int i = 0; i < 2; i++) { QString infosheetName = QStringList({"infosheet_url", "additional_info_url"})[i]; if(rawData.contains(infosheetName) && !rawData[infosheetName].isNull()) { - data.infosheetUrls.append(rawData[infosheetName].toString()); + data.infosheetUrls.append("https://ifsc.results.info" + rawData[infosheetName].toString()); } } @@ -245,7 +246,6 @@ BRCup::BRCupData BRProviderVl::parseCupData(QVariantMap rawData, QVariantList gl BRCategory::BRCategoryData BRProviderVl::parseCategoryData(QVariantMap rawData) { - // TODO: status BRCategory::BRCategoryData data; data.name = rawData["name"].toString(); @@ -280,10 +280,14 @@ BRCategory::BRCategoryData BRProviderVl::parseCategoryData(QVariantMap rawData) data.currentRound = nullptr; + BRRound::BRRoundData roundData; + roundData.name = "General result"; + qDebug() << "--- Adding round: " << roundData.name; + data.generalResult = this->getRound(BRWidget::IFSC, -1, roundData, true); + // load rounds QVariantList roundsList = rawData["category_rounds"].toList(); // insert general result - roundsList.insert(0, QVariantMap({{"name", "General result"}, {"category_round_id", -1}})); for(QVariant roundVar : roundsList) { QVariantMap roundMap = roundVar.toMap(); @@ -294,12 +298,12 @@ BRCategory::BRCategoryData BRProviderVl::parseCategoryData(QVariantMap rawData) data.rounds.append(round); } - data.currentRound = data.rounds[0]; + data.currentRound = data.generalResult; return data; } -void BRProviderVl::parseCategoryData(BRCategory::BRCategoryData* categoryData, QVariantMap rawData) { +/*void BRProviderVl::parseCategoryData(BRCategory::BRCategoryData* categoryData, QVariantMap rawData) { // no need to load rounds, they were already loaded when the whole competition was loaded! @@ -327,7 +331,7 @@ void BRProviderVl::parseCategoryData(BRCategory::BRCategoryData* categoryData, Q BRResult::BRResultData resultData; resultData.rank = resultMap["rank"].toInt(); resultData.athlete = tmpAthletes[athleteId]; - BRResult* result = this->getResult(BRWidget::IFSC, -1, resultData); + BRResult* result = this->getResult(resultData); roundData.results.append(result); } @@ -335,9 +339,7 @@ void BRProviderVl::parseCategoryData(BRCategory::BRCategoryData* categoryData, Q qDebug() << "General result round: " << generalResultRound; categoryData->rounds.insert(0, generalResultRound); categoryData->currentRound = generalResultRound; -} - - +}*/ BRRound::BRRoundData BRProviderVl::parseRoundData(QVariantMap rawData) { BRRound::BRRoundData data; @@ -350,12 +352,29 @@ void BRProviderVl::parseRoundData(BRRound::BRRoundData* roundData, QVariantMap r // TODO status // clear up - for(BRResult* result : roundData->results) - result->deleteLater(); + qDebug() << "clearing"; + QList clearRounds; + clearRounds.append(roundData->round); + + if(roundData->round->isGeneralResult()) { + // if we are parsing a general result -> clear all rounds + clearRounds.append(roundData->round->getCategory()->getRounds()); + } + + for(BRRound* round : clearRounds) { + for(BRResult* result : round->getResults()) + result->deleteLater(); + + BRRound::BRRoundData roundData = round->getData(); + roundData.results.clear(); + this->setRoundData(round, roundData); + } roundData->results.clear(); + qDebug() << "finished clearing"; - // parse RankingQVariantList resultList = rawData["ranking"].toList(); + + // parse Ranking QVariantList resultList = rawData["ranking"].toList(); for(QVariant resultVar : resultList) { QVariantMap resultMap = resultVar.toMap(); @@ -376,8 +395,36 @@ void BRProviderVl::parseRoundData(BRRound::BRRoundData* roundData, QVariantMap r BRResult::BRResultData resultData; resultData.rank = resultMap["rank"].toInt(); resultData.athlete = athlete; - BRResult* result = this->getResult(BRWidget::IFSC, -1, resultData); + + // if this is the general result -> parse all other rounds as well + if(roundData->round->isGeneralResult()) { + qDebug() << "THIS is general result!!"; + resultData.details = new BRResultDetailsGeneralResult(); + + // add results of other rounds + for(QVariant subRoundVar : resultMap["rounds"].toList()) { + QVariantMap subRoundMap = subRoundVar.toMap(); + for(BRRound* subRound : roundData->round->getCategory()->getRounds(false)) { + if(subRound->getId() == subRoundMap["category_round_id"].toInt()) { + BRResult::BRResultData subResultData; + subResultData.rank = subRoundMap["rank"].toInt(); + subResultData.athlete = athlete; + subResultData.details = new BRResultDetailsUnknown(subRoundMap["score"].toString()); + + + qDebug() << "Adding subResult: rank: " << resultMap["rank"]; + + BRRound::BRRoundData subRoundData = subRound->getData(); + subRoundData.results.append(this->getResult(subResultData)); + this->setRoundData(subRound, subRoundData); + } + } + } + } + else + resultData.details = new BRResultDetailsUnknown(resultMap["score"].toString()); + + BRResult* result = this->getResult(resultData); roundData->results.append(result); } - }