Skip to content

Commit

Permalink
Ajout d'une vue stats par pilote
Browse files Browse the repository at this point in the history
  • Loading branch information
cvermot committed Jan 16, 2024
1 parent a442be9 commit b8149f9
Show file tree
Hide file tree
Showing 15 changed files with 236 additions and 7 deletions.
12 changes: 12 additions & 0 deletions database/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ FROM vol
GROUP BY mois, typeDeVol
ORDER BY annee, mois;

-- View: stats_heuresDeVolParPilote
CREATE VIEW IF NOT EXISTS stats_heuresDeVolParPilote AS SELECT
vol.pilote,
pilote.nom,
pilote.prenom,
strftime('%Y', vol.date) AS annee,
SUM(vol.duree) as tempsDeVol
FROM vol
INNER JOIN pilote ON vol.pilote = pilote.piloteId
GROUP BY pilote, annee
ORDER BY pilote, annee;

-- View: subventionEntrainementAlloueeParPiloteEtParAnnee
CREATE VIEW IF NOT EXISTS subventionEntrainementAlloueeParPiloteEtParAnnee AS SELECT strftime('%Y', date) AS annee,
pilote,
Expand Down
24 changes: 20 additions & 4 deletions src/AeroDms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "AeroDmsTypes.h"

#include "StatistiqueHistogrammeEmpile.h"
#include "StatistiqueDiagrammeCirculaireWidget.h"

#include <QtWidgets>
#include <QToolBar>
Expand Down Expand Up @@ -90,7 +91,6 @@ AeroDms::AeroDms(QWidget* parent):QMainWindow(parent)
parametresMetiers.proportionRemboursementBalade = settingsMetier.value("parametresMetier/proportionRemboursementBalade", "").toFloat();
parametresMetiers.nomTresorier = settings.value("noms/nomTresorier", "").toString();


db = new ManageDb(database);
pdf = new PdfRenderer( db,
ressourcesHtml);
Expand Down Expand Up @@ -370,6 +370,12 @@ AeroDms::AeroDms(QWidget* parent):QMainWindow(parent)
connect(listeDeroulantePilote, &QComboBox::currentIndexChanged, this, &AeroDms::peuplerTableVols);
SelectionToolBar->addWidget(listeDeroulantePilote);

listeDeroulanteStatistique = new QComboBox(this);
listeDeroulanteStatistique->addItem("Statistiques mensuelles", 1);
listeDeroulanteStatistique->addItem("Statistiques par pilote", 2);
connect(listeDeroulanteStatistique, &QComboBox::currentIndexChanged, this, &AeroDms::peuplerStatistiques);
SelectionToolBar->addWidget(listeDeroulanteStatistique);

//Fenêtres
dialogueGestionPilote = new DialogueGestionPilote(db, this);
connect(dialogueGestionPilote, SIGNAL(accepted()), this, SLOT(ajouterUnPiloteEnBdd()));
Expand Down Expand Up @@ -424,8 +430,6 @@ AeroDms::AeroDms(QWidget* parent):QMainWindow(parent)
prevaliderDonnneesSaisiesRecette();
changerInfosVolSurSelectionTypeVol();
peuplerStatistiques();


}

void AeroDms::initialiserOngletGraphiques()
Expand All @@ -443,7 +447,19 @@ void AeroDms::peuplerStatistiques()
m_activeWidget->deleteLater();
}

m_activeWidget = new StatistiqueHistogrammeEmpile(db, listeDeroulanteAnnee->currentData().toInt(), m_contentArea);
switch (listeDeroulanteStatistique->currentData().toInt())
{
case 1:
{
m_activeWidget = new StatistiqueHistogrammeEmpile(db, listeDeroulanteAnnee->currentData().toInt(), m_contentArea);
break;
}
case 2:
{
m_activeWidget = new StatistiqueDiagrammeCirculaireWidget(db, listeDeroulanteAnnee->currentData().toInt(), m_contentArea);
break;
}
}
graphiques->addWidget(m_activeWidget);

m_activeWidget->load();
Expand Down
1 change: 1 addition & 0 deletions src/AeroDms.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AeroDms : public QMainWindow

QComboBox* listeDeroulanteAnnee;
QComboBox* listeDeroulantePilote;
QComboBox* listeDeroulanteStatistique;

QString cheminStockageFacturesTraitees;
QString cheminStockageFacturesATraiter;
Expand Down
6 changes: 6 additions & 0 deletions src/AeroDms.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="StatistiqueDiagrammeCirculaire.cpp" />
<ClCompile Include="StatistiqueDiagrammeCirculairePartie.cpp" />
<ClCompile Include="StatistiqueDiagrammeCirculaireWidget.cpp" />
<ClCompile Include="StatistiqueHistogrammeEmpile.cpp" />
<ClCompile Include="StatistiqueWidget.cpp" />
<ClCompile Include="DialogueAjouterCotisation.cpp" />
Expand All @@ -111,6 +114,9 @@
<ClInclude Include="AeroDmsTypes.h" />
<QtMoc Include="StatistiqueHistogrammeEmpile.h" />
<QtMoc Include="StatistiqueWidget.h" />
<QtMoc Include="StatistiqueDiagrammeCirculaireWidget.h" />
<QtMoc Include="StatistiqueDiagrammeCirculaire.h" />
<QtMoc Include="StatistiqueDiagrammeCirculairePartie.h" />
<ClInclude Include="resource.h" />
<QtMoc Include="DialogueAjouterSortie.h" />
<QtMoc Include="DialogueAjouterCotisation.h" />
Expand Down
14 changes: 14 additions & 0 deletions src/AeroDmsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class AeroDmsTypes
float montantRembourse;
float coutTotal;
QString heuresDeVol;
int tempsDeVolEnMinutes;
};
struct SubventionsParPilote {
QString idPilote;
Expand Down Expand Up @@ -187,6 +188,19 @@ class AeroDmsTypes
QString nomTresorier;
};

inline static const QString convertirMinutesEnHeuresMinutes(const int p_minutes)
{
const int heures = p_minutes / 60;
const int minutes = p_minutes % 60;
QString minutesString = QString::number(minutes);
if (minutesString.size() == 1)
{
minutesString = QString("0").append(minutesString);
}
QString heuresMinutes = QString::number(heures).append("h").append(minutesString);
return heuresMinutes;
}

};

#endif // AERODMSTYPES_H
7 changes: 7 additions & 0 deletions src/ManageDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,19 @@ AeroDmsTypes::ListeSubventionsParPilotes ManageDb::recupererSubventionsPilotes(
subvention.prenom = query.value("prenom").toString();
subvention.aeroclub = query.value("aeroclub").toString();
subvention.sortie.heuresDeVol = "0h00";
subvention.sortie.tempsDeVolEnMinutes = 0;
subvention.sortie.montantRembourse = 0;
subvention.sortie.coutTotal = 0;
subvention.entrainement.heuresDeVol = "0h00";
subvention.entrainement.tempsDeVolEnMinutes = 0;
subvention.entrainement.montantRembourse = 0;
subvention.entrainement.coutTotal = 0;
subvention.balade.heuresDeVol = "0h00";
subvention.balade.tempsDeVolEnMinutes = 0;
subvention.balade.montantRembourse = 0;
subvention.balade.coutTotal = 0;
subvention.totaux.heuresDeVol = "0h00";
subvention.totaux.tempsDeVolEnMinutes = 0;
subvention.totaux.montantRembourse = 0;
subvention.totaux.coutTotal = 0;

Expand All @@ -177,18 +181,21 @@ AeroDmsTypes::ListeSubventionsParPilotes ManageDb::recupererSubventionsPilotes(
if (queryVolAnneePilote.value("typeDeVol").toString() == "Entrainement")
{
subvention.entrainement.heuresDeVol = convertirMinutesEnHeuresMinutes(queryVolAnneePilote.value("tempsDeVol").toInt());
subvention.entrainement.tempsDeVolEnMinutes = queryVolAnneePilote.value("tempsDeVol").toInt();
subvention.entrainement.montantRembourse = queryVolAnneePilote.value("montantRembourse").toFloat();
subvention.entrainement.coutTotal = queryVolAnneePilote.value("cout").toFloat();
}
else if (queryVolAnneePilote.value("typeDeVol").toString() == "Sortie")
{
subvention.sortie.heuresDeVol = convertirMinutesEnHeuresMinutes(queryVolAnneePilote.value("tempsDeVol").toInt());
subvention.sortie.tempsDeVolEnMinutes = queryVolAnneePilote.value("tempsDeVol").toInt();
subvention.sortie.montantRembourse = queryVolAnneePilote.value("montantRembourse").toFloat();
subvention.sortie.coutTotal = queryVolAnneePilote.value("cout").toFloat();
}
else if (queryVolAnneePilote.value("typeDeVol").toString() == "Balade")
{
subvention.balade.heuresDeVol = convertirMinutesEnHeuresMinutes(queryVolAnneePilote.value("tempsDeVol").toInt());
subvention.balade.tempsDeVolEnMinutes = queryVolAnneePilote.value("tempsDeVol").toInt();
subvention.balade.montantRembourse = queryVolAnneePilote.value("montantRembourse").toFloat();
subvention.balade.coutTotal = queryVolAnneePilote.value("cout").toFloat();
}
Expand Down
25 changes: 25 additions & 0 deletions src/StatistiqueDiagrammeCirculaire.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "StatistiqueDiagrammeCirculaire.h"
#include "StatistiqueDiagrammeCirculairePartie.h"

StatistiqueDiagrammeCirculaire::StatistiqueDiagrammeCirculaire(QGraphicsItem* parent, Qt::WindowFlags wFlags)
: QChart(QChart::ChartTypeCartesian, parent, wFlags)
{
}

void StatistiqueDiagrammeCirculaire::changeSeries(QAbstractSeries* series)
{
if (m_currentSeries)
removeSeries(m_currentSeries);
m_currentSeries = series;
addSeries(series);
setTitle(series->name());
}

void StatistiqueDiagrammeCirculaire::handleSliceClicked(QPieSlice* slice)
{
auto* drilldownSlice = static_cast<StatistiqueDiagrammeCirculairePartie*>(slice);
changeSeries(drilldownSlice->drilldownSeries());
}
26 changes: 26 additions & 0 deletions src/StatistiqueDiagrammeCirculaire.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef PIEDRILLDOWNCHART_H
#define PIEDRILLDOWNCHART_H

#include <QChart>

QT_FORWARD_DECLARE_CLASS(QAbstractSeries);
QT_FORWARD_DECLARE_CLASS(QPieSlice);

class StatistiqueDiagrammeCirculaire : public QChart
{
Q_OBJECT
public:
explicit StatistiqueDiagrammeCirculaire(QGraphicsItem* parent = nullptr, Qt::WindowFlags wFlags = {});
void changeSeries(QAbstractSeries* series);

public slots:
void handleSliceClicked(QPieSlice* slice);

private:
QAbstractSeries* m_currentSeries = nullptr;
};

#endif
34 changes: 34 additions & 0 deletions src/StatistiqueDiagrammeCirculairePartie.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "StatistiqueDiagrammeCirculairePartie.h"
#include "AeroDmsTypes.h"

StatistiqueDiagrammeCirculairePartie::StatistiqueDiagrammeCirculairePartie(qreal value, const QString& prefix, QAbstractSeries* drilldownSeries)
: m_drilldownSeries(drilldownSeries),
m_prefix(prefix)
{
setValue(value);
updateLabel();
setLabelFont(QFont("Arial", 8));
connect(this, &StatistiqueDiagrammeCirculairePartie::percentageChanged, this, &StatistiqueDiagrammeCirculairePartie::updateLabel);
connect(this, &StatistiqueDiagrammeCirculairePartie::hovered, this, &StatistiqueDiagrammeCirculairePartie::showHighlight);
}

QAbstractSeries* StatistiqueDiagrammeCirculairePartie::drilldownSeries() const
{
return m_drilldownSeries;
}

void StatistiqueDiagrammeCirculairePartie::updateLabel()
{
setLabel(QStringLiteral("%1 : %2, %3%").arg(m_prefix,
AeroDmsTypes::convertirMinutesEnHeuresMinutes(value()),
QString::number(percentage() * 100, 'f', 1)));
}

void StatistiqueDiagrammeCirculairePartie::showHighlight(bool show)
{
setLabelVisible(show);
setExploded(show);
}
27 changes: 27 additions & 0 deletions src/StatistiqueDiagrammeCirculairePartie.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef PIEDRILLDOWNSLICE_H
#define PIEDRILLDOWNSLICE_H

#include <QPieSlice>

QT_FORWARD_DECLARE_CLASS(QAbstractSeries);

class StatistiqueDiagrammeCirculairePartie : public QPieSlice
{
Q_OBJECT
public:
StatistiqueDiagrammeCirculairePartie(qreal value, const QString& prefix, QAbstractSeries* drilldownSeries);
QAbstractSeries* drilldownSeries() const;

public slots:
void updateLabel();
void showHighlight(bool show);

private:
QAbstractSeries* m_drilldownSeries = nullptr;
QString m_prefix;
};

#endif
44 changes: 44 additions & 0 deletions src/StatistiqueDiagrammeCirculaireWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "StatistiqueDiagrammeCirculaire.h"
#include "StatistiqueDiagrammeCirculairePartie.h"
#include "StatistiqueDiagrammeCirculaireWidget.h"

#include <QChart>
#include <QLegend>
#include <QPieSeries>
#include <QRandomGenerator>

StatistiqueDiagrammeCirculaireWidget::StatistiqueDiagrammeCirculaireWidget(ManageDb* p_db, int p_annee, QWidget* parent)
: StatistiqueWidget(parent)
{
auto* chart = new StatistiqueDiagrammeCirculaire;
chart->setTheme(QChart::ChartThemeBlueNcs);
chart->setAnimationOptions(QChart::AllAnimations);
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignRight);

AeroDmsTypes::ListeSubventionsParPilotes subventionParPilote = p_db->recupererSubventionsPilotes(p_annee);

auto donneesTypeDeVolParPilote = new QPieSeries(this);
donneesTypeDeVolParPilote->setName("Temps de vol par pilote (cliquez pour le détail par pilote)");

for (int i = 0; i < subventionParPilote.size(); i++)
{
auto detailParPilote = new QPieSeries(this);
detailParPilote->setName("Vol pour " + subventionParPilote.at(i).prenom +" "+ subventionParPilote.at(i).nom);
*detailParPilote << new StatistiqueDiagrammeCirculairePartie(subventionParPilote.at(i).entrainement.tempsDeVolEnMinutes, "Entrainement", donneesTypeDeVolParPilote);
*detailParPilote << new StatistiqueDiagrammeCirculairePartie(subventionParPilote.at(i).sortie.tempsDeVolEnMinutes, "Sorties", donneesTypeDeVolParPilote);
*detailParPilote << new StatistiqueDiagrammeCirculairePartie(subventionParPilote.at(i).balade.tempsDeVolEnMinutes, "Balades", donneesTypeDeVolParPilote);

QObject::connect(detailParPilote, &QPieSeries::clicked, chart, &StatistiqueDiagrammeCirculaire::handleSliceClicked);
*donneesTypeDeVolParPilote << new StatistiqueDiagrammeCirculairePartie(detailParPilote->sum(), subventionParPilote.at(i).prenom + " " + subventionParPilote.at(i).nom, detailParPilote);
}

QObject::connect(donneesTypeDeVolParPilote, &QPieSeries::clicked, chart, &StatistiqueDiagrammeCirculaire::handleSliceClicked);

chart->changeSeries(donneesTypeDeVolParPilote);

createDefaultChartView(chart);
}
17 changes: 17 additions & 0 deletions src/StatistiqueDiagrammeCirculaireWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#ifndef PIEDRILLDOWNWIDGET_H
#define PIEDRILLDOWNWIDGET_H

#include "StatistiqueWidget.h"
#include "ManageDb.h"

class StatistiqueDiagrammeCirculaireWidget : public StatistiqueWidget
{
Q_OBJECT
public:
explicit StatistiqueDiagrammeCirculaireWidget(ManageDb* p_db, int p_annee, QWidget* parent = nullptr);
};

#endif
2 changes: 1 addition & 1 deletion src/StatistiqueHistogrammeEmpile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <QValueAxis>

StatistiqueHistogrammeEmpile::StatistiqueHistogrammeEmpile(ManageDb* p_db, const int p_annee, QWidget* parent)
: StatistiqueWidget(p_db, parent)
: StatistiqueWidget(parent)
{
const AeroDmsTypes::ListeStatsHeuresDeVol heuresDeVol = p_db->recupererHeuresMensuelles(p_annee);
qDebug() << "annee" << p_annee;
Expand Down
2 changes: 1 addition & 1 deletion src/StatistiqueWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <QLabel>
#include <QVBoxLayout>

StatistiqueWidget::StatistiqueWidget(ManageDb* p_db, QWidget* parent)
StatistiqueWidget::StatistiqueWidget(QWidget* parent)
: QWidget(parent)
{
}
Expand Down
2 changes: 1 addition & 1 deletion src/StatistiqueWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class StatistiqueWidget : public QWidget
{
Q_OBJECT
public:
explicit StatistiqueWidget(ManageDb* p_db, QWidget* parent = nullptr);
explicit StatistiqueWidget(QWidget* parent = nullptr);

void load();

Expand Down

0 comments on commit b8149f9

Please sign in to comment.