Skip to content

Commit

Permalink
Ajout stats affichage aéronefs
Browse files Browse the repository at this point in the history
Première version sans gestion de l'année ni affichage de la durée au survol
  • Loading branch information
cvermot committed Apr 17, 2024
1 parent fe0049f commit 34e6e3c
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 8 deletions.
11 changes: 11 additions & 0 deletions database/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/AeroDms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions src/AeroDmsTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
12 changes: 11 additions & 1 deletion src/AeroDmsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<StatsAeronef> StatsAeronefs;

};

#endif // AERODMSTYPES_H
30 changes: 28 additions & 2 deletions src/ManageDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions src/ManageDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
100 changes: 96 additions & 4 deletions src/StatistiqueDonuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,30 @@
#include <QPieSlice>
#include <QRandomGenerator>

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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<QPieSlice*>(sender());
Expand Down
7 changes: 6 additions & 1 deletion src/StatistiqueDonuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QPieSeries*> m_donuts;

void afficherStatsPilotes(ManageDb* p_db);
void afficherStatsAeronefs(ManageDb* p_db);
};

#endif

0 comments on commit 34e6e3c

Please sign in to comment.