diff --git a/database/structure.sql b/database/structure.sql index 914c92d..af94180 100644 --- a/database/structure.sql +++ b/database/structure.sql @@ -180,6 +180,17 @@ INNER JOIN "xAssociationRecette-Vol" ON "xAssociationRecette-Vol".recetteId = re INNER JOIN vol ON "xAssociationRecette-Vol".volId = vol.volId GROUP BY recettes.recetteId; +-- View: stats_aeronefs +CREATE VIEW IF NOT EXISTS stats_aeronefs AS SELECT + vol.immatriculation, + aeronef.type, + strftime('%Y', vol.date) AS annee, + SUM(vol.duree) AS tempsDeVol +FROM vol +INNER JOIN aeronef ON vol.immatriculation = aeronef.immatriculation +GROUP BY vol.immatriculation, annee +ORDER BY annee, type, vol.immatriculation; + -- View: stats_heuresDeVolParMois CREATE VIEW IF NOT EXISTS stats_heuresDeVolParMois AS SELECT strftime('%m', vol.date) AS mois, diff --git a/src/AeroDms.cpp b/src/AeroDms.cpp index ef8a530..7c59d83 100644 --- a/src/AeroDms.cpp +++ b/src/AeroDms.cpp @@ -480,6 +480,9 @@ AeroDms::AeroDms(QWidget* parent) :QMainWindow(parent) listeDeroulanteStatistique->setItemIcon(AeroDmsTypes::Statistiques_HEURES_PAR_ACTIVITE, QIcon("./ressources/chart-pie.svg")); listeDeroulanteStatistique->addItem("Statuts des pilotes", AeroDmsTypes::Statistiques_STATUTS_PILOTES); listeDeroulanteStatistique->setItemIcon(AeroDmsTypes::Statistiques_STATUTS_PILOTES, QIcon("./ressources/chart-donut-variant.svg")); + listeDeroulanteStatistique->addItem("Types d'aéronefs", AeroDmsTypes::Statistiques_AERONEFS); + listeDeroulanteStatistique->setItemIcon(AeroDmsTypes::Statistiques_AERONEFS, QIcon("./ressources/chart-donut-variant.svg")); + connect(listeDeroulanteStatistique, &QComboBox::currentIndexChanged, this, &AeroDms::peuplerStatistiques); selectionToolBar->addWidget(listeDeroulanteStatistique); @@ -858,6 +861,14 @@ void AeroDms::peuplerStatistiques() case AeroDmsTypes::Statistiques_STATUTS_PILOTES: { m_activeWidget = new StatistiqueDonuts( db, + AeroDmsTypes::Statistiques_STATUTS_PILOTES, + m_contentArea); + break; + } + case AeroDmsTypes::Statistiques_AERONEFS: + { + m_activeWidget = new StatistiqueDonuts( db, + AeroDmsTypes::Statistiques_AERONEFS, m_contentArea); break; } diff --git a/src/AeroDmsTypes.cpp b/src/AeroDmsTypes.cpp index a8811e0..da34cfa 100644 --- a/src/AeroDmsTypes.cpp +++ b/src/AeroDmsTypes.cpp @@ -72,4 +72,11 @@ const AeroDmsTypes::StatsPilotes AeroDmsTypes::K_INIT_DONNEES_STATS_PILOTES = 0, 0, 0 +}; + +const AeroDmsTypes::StatsAeronef AeroDmsTypes::K_INIT_STAT_AERONEF = +{ + "", + "", + 0 }; \ No newline at end of file diff --git a/src/AeroDmsTypes.h b/src/AeroDmsTypes.h index 6b91da0..e835780 100644 --- a/src/AeroDmsTypes.h +++ b/src/AeroDmsTypes.h @@ -116,7 +116,8 @@ class AeroDmsTypes Statistiques_HEURES_PAR_PILOTE, Statistiques_HEURES_PAR_TYPE_DE_VOL, Statistiques_HEURES_PAR_ACTIVITE, - Statistiques_STATUTS_PILOTES + Statistiques_STATUTS_PILOTES, + Statistiques_AERONEFS }; enum Signature { @@ -372,6 +373,15 @@ class AeroDmsTypes }; static const StatsPilotes K_INIT_DONNEES_STATS_PILOTES; + struct StatsAeronef + { + QString immat; + QString type; + int nombreMinutesVol; + }; + static const StatsAeronef K_INIT_STAT_AERONEF; + typedef QList StatsAeronefs; + }; #endif // AERODMSTYPES_H diff --git a/src/ManageDb.cpp b/src/ManageDb.cpp index 20b3e22..144f09b 100644 --- a/src/ManageDb.cpp +++ b/src/ManageDb.cpp @@ -1520,13 +1520,39 @@ const AeroDmsTypes::StatsPilotes ManageDb::recupererStatsPilotes() statsPilotes.nbNonBrevete = query.value("nbNonBrevete").toInt() ; statsPilotes.nbOuvranDroit = query.value("nbOuvrantDroit").toInt(); statsPilotes.nbAyantDroit = query.value("nbAyantDroit").toInt(); - qDebug() << "passage ici"; } - qDebug() << "passage la" << query.lastError(); return statsPilotes; } +const AeroDmsTypes::StatsAeronefs ManageDb::recupererStatsAeronefs(const int p_annee) +{ + AeroDmsTypes::StatsAeronefs statsAeronefs; + + QSqlQuery query; + query.prepare("SELECT " + "immatriculation," + "type," + "SUM(tempsDeVol) AS tempsDeVol " + "FROM stats_aeronefs " + "GROUP BY immatriculation " + "ORDER BY type, immatriculation"); + query.exec(); + + while (query.next()) + { + AeroDmsTypes::StatsAeronef stats; + + stats.immat = query.value("immatriculation").toString(); + stats.type = query.value("type").toString(); + stats.nombreMinutesVol = query.value("tempsDeVol").toInt(); + + statsAeronefs.append(stats); + } + + return statsAeronefs; +} + void ManageDb::mettreAJourDonneesAeronefs( const QString p_immatAeronefAMettreAJour, const QString p_nouvelleValeur, const AeroDmsTypes::AeronefTableElement p_donneeAMettreAJour ) diff --git a/src/ManageDb.h b/src/ManageDb.h index 1638d99..7e9dd1e 100644 --- a/src/ManageDb.h +++ b/src/ManageDb.h @@ -123,6 +123,7 @@ class ManageDb : public QWidget { QString recupererMailPilotes( const int p_annee, const bool p_pilotesActifsSeulement, const bool p_pilotesBrevetes = false); + const AeroDmsTypes::StatsAeronefs recupererStatsAeronefs(const int p_annee); QString recupererMailDerniereDemandeDeSubvention(); const AeroDmsTypes::StatsPilotes recupererStatsPilotes(); diff --git a/src/StatistiqueDonuts.cpp b/src/StatistiqueDonuts.cpp index 64b27d9..09b5423 100644 --- a/src/StatistiqueDonuts.cpp +++ b/src/StatistiqueDonuts.cpp @@ -12,10 +12,30 @@ #include #include -StatistiqueDonuts::StatistiqueDonuts(ManageDb* p_db, QWidget* parent) +StatistiqueDonuts::StatistiqueDonuts( ManageDb* p_db, + const AeroDmsTypes::Statistiques p_statistique, + QWidget* parent) : StatistiqueWidget(parent) { - const AeroDmsTypes::StatsPilotes statsPilotes = p_db->recupererStatsPilotes(); + switch (p_statistique) + { + case AeroDmsTypes::Statistiques_STATUTS_PILOTES: + { + afficherStatsPilotes(p_db); + break; + } + case AeroDmsTypes::Statistiques_AERONEFS: + default: + { + afficherStatsAeronefs(p_db); + break; + } + } +} + +void StatistiqueDonuts::afficherStatsPilotes(ManageDb* p_db) +{ + const AeroDmsTypes::StatsPilotes statsPilotes = p_db->recupererStatsPilotes(); //! [1] auto chartView = new QChartView(this); chartView->setRenderHint(QPainter::Antialiasing); @@ -60,7 +80,6 @@ StatistiqueDonuts::StatistiqueDonuts(ManageDb* p_db, QWidget* parent) niveauDuDonut++; auto donutAyantDroit = new QPieSeries; - qDebug() << "stats pilote" << statsPilotes.nbBrevete << statsPilotes.nbNonBrevete; auto sliceOuvrantDroit = new QPieSlice(QString("Ouvrant droit"), statsPilotes.nbOuvranDroit); sliceOuvrantDroit->setLabelVisible(true); sliceOuvrantDroit->setLabelColor(Qt::white); @@ -89,10 +108,83 @@ StatistiqueDonuts::StatistiqueDonuts(ManageDb* p_db, QWidget* parent) mainLayout->addWidget(chartView, 1, 1); setLayout(mainLayout); //! [4] +} + +void StatistiqueDonuts::afficherStatsAeronefs(ManageDb* p_db) +{ + const AeroDmsTypes::StatsAeronefs statsAeronefs = p_db->recupererStatsAeronefs(0); + + auto chartView = new QChartView(this); + chartView->setRenderHint(QPainter::Antialiasing); + QChart* chart = chartView->chart(); + chart->legend()->setVisible(false); + chart->setTitle("Statistiques sur les aéronefs"); + chart->setAnimationOptions(QChart::AllAnimations); + chart->layout()->setContentsMargins(0, 0, 0, 0); + qreal minSize = 0.5; + qreal maxSize = 0.9; + int donutCount = 2; + + int niveauDonutImmat = 0; + int niveauDonutType = 1; + //! [1] + //! + //! + auto donutImmat = new QPieSeries; + auto donutType = new QPieSeries; + + int nbMinutesType = 0; + QString typeCourant = statsAeronefs.at(0).type; + + for (int i = 0; i < statsAeronefs.size(); i++) + { + auto sliceImmat = new QPieSlice(statsAeronefs.at(i).immat, statsAeronefs.at(i).nombreMinutesVol); + sliceImmat->setLabelVisible(true); + sliceImmat->setLabelColor(Qt::white); + sliceImmat->setLabelPosition(QPieSlice::LabelInsideTangential); + //connect(slice, &QPieSlice::hovered, this, &StatistiqueDonuts::explodeSlice); + donutImmat->append(sliceImmat); + + if (typeCourant != statsAeronefs.at(i).type) + { + auto sliceType = new QPieSlice(typeCourant, nbMinutesType); + sliceType->setLabelVisible(true); + sliceType->setLabelColor(Qt::white); + sliceType->setLabelPosition(QPieSlice::LabelInsideTangential); + //connect(slice, &QPieSlice::hovered, this, &StatistiqueDonuts::explodeSlice); + donutType->append(sliceType); + nbMinutesType = 0; + typeCourant = statsAeronefs.at(i).type; + } + nbMinutesType = nbMinutesType + statsAeronefs.at(i).nombreMinutesVol; + + if (i == statsAeronefs.size() - 1) + { + auto sliceType = new QPieSlice(typeCourant, nbMinutesType); + sliceType->setLabelVisible(true); + sliceType->setLabelColor(Qt::white); + sliceType->setLabelPosition(QPieSlice::LabelInsideTangential); + //connect(slice, &QPieSlice::hovered, this, &StatistiqueDonuts::explodeSlice); + donutType->append(sliceType); + } + + } + donutImmat->setHoleSize(minSize + niveauDonutImmat * (maxSize - minSize) / donutCount); + donutImmat->setPieSize(minSize + (niveauDonutImmat + 1) * (maxSize - minSize) / donutCount); + m_donuts.append(donutImmat); + chartView->chart()->addSeries(donutImmat); + + donutType->setHoleSize(minSize + niveauDonutType * (maxSize - minSize) / donutCount); + donutType->setPieSize(minSize + (niveauDonutType + 1) * (maxSize - minSize) / donutCount); + m_donuts.append(donutType); + chartView->chart()->addSeries(donutType); + + auto mainLayout = new QGridLayout; + mainLayout->addWidget(chartView, 1, 1); + setLayout(mainLayout); } -//! [7] void StatistiqueDonuts::explodeSlice(bool exploded) { auto slice = qobject_cast(sender()); diff --git a/src/StatistiqueDonuts.h b/src/StatistiqueDonuts.h index cfed014..ab33df8 100644 --- a/src/StatistiqueDonuts.h +++ b/src/StatistiqueDonuts.h @@ -13,13 +13,18 @@ class StatistiqueDonuts : public StatistiqueWidget { Q_OBJECT public: - StatistiqueDonuts(ManageDb* p_db, QWidget* parent = nullptr); + StatistiqueDonuts( ManageDb* p_db, + const AeroDmsTypes::Statistiques p_statistique, + QWidget* parent = nullptr); public slots: void explodeSlice(bool exploded); private: QList m_donuts; + + void afficherStatsPilotes(ManageDb* p_db); + void afficherStatsAeronefs(ManageDb* p_db); }; #endif