2
0
Эх сурвалжийг харах

Flight Time Limitations integrated

FTL are now integrated into the new CurrencyWidget
Felix Turowsky 1 жил өмнө
parent
commit
cab1b8297a

+ 2 - 0
CMakeLists.txt

@@ -118,6 +118,8 @@ set(PROJECT_SOURCES
     src/classes/md5sum.cpp
     src/classes/time.h
     src/classes/time.cpp
+    src/classes/easaftl.h
+    src/classes/easaftl.cpp
 
     # Database Entries
     src/database/flightentry.h

+ 16 - 0
src/classes/easaftl.cpp

@@ -0,0 +1,16 @@
+#include "easaftl.h"
+
+int EasaFTL::getLimit(OPL::Statistics::TimeFrame timeFrame)
+{
+    switch (timeFrame) {
+    case OPL::Statistics::TimeFrame::Rolling28Days:
+        return 100*60; // 100h
+    case OPL::Statistics::TimeFrame::Rolling12Months:
+        return 1000 * 60; // 1000h
+    case OPL::Statistics::TimeFrame::CalendarYear:
+        return 900 * 60; // 900h
+    default:
+        return 0;
+        break;
+    }
+}

+ 14 - 0
src/classes/easaftl.h

@@ -0,0 +1,14 @@
+#ifndef EASAFTL_H
+#define EASAFTL_H
+#include "src/functions/statistics.h"
+
+
+class EasaFTL
+{
+public:
+    EasaFTL() = delete;
+
+    static int getLimit(OPL::Statistics::TimeFrame timeFrame);
+};
+
+#endif // EASAFTL_H

+ 14 - 0
src/classes/time.cpp

@@ -22,6 +22,20 @@ int32_t Time::toMinutes() const
     return m_minutes;
 }
 
+int Time::toMinutes(TimeFrame timeFrame, int count)
+{
+    switch (timeFrame) {
+    case Day:
+        return count * MINUTES_PER_DAY;
+    case Week:
+        return count * 7 * MINUTES_PER_DAY;
+    case Year:
+        return count * 7 * 52 * MINUTES_PER_DAY;
+    default:
+        return 0;
+    }
+}
+
 Time Time::fromString(const QString &timeString)
 {
     const QStringList parts = timeString.split(QChar(':'));

+ 9 - 0
src/classes/time.h

@@ -21,6 +21,8 @@ public:
     Time();
     Time(int32_t minutes) : m_minutes(minutes) {};
 
+    enum TimeFrame {Day, Week, Year};
+
     /**
      * @brief isValidTimeOfDay - determines whether the instance can be converted to a time hh:mm
      * @return true if the total amount of minutes does not exceed one day.
@@ -37,6 +39,13 @@ public:
      */
     int32_t toMinutes() const;
 
+    /*!
+     * \brief toMinutes returns the number of minutes in the given time frame
+     * \param count - The number of time frames (e.g. '7' days)
+     * \return
+     */
+    static int toMinutes(TimeFrame timeFrame, int count);
+
     /**
      * @brief fromString create a Time Object from a String formatted as hh:mm
      * @param timeString the input string

+ 41 - 22
src/gui/widgets/currencywidget.cpp

@@ -2,8 +2,11 @@
 #include "QtSql/qsqltablemodel.h"
 #include "QtWidgets/qgridlayout.h"
 #include "QtWidgets/qheaderview.h"
+#include "src/classes/easaftl.h"
+#include "src/classes/time.h"
 #include "src/database/database.h"
 #include "src/functions/statistics.h"
+#include "src/classes/settings.h"
 #include <QCalendarWidget>
 #include <QInputDialog>
 #include <QLabel>
@@ -113,35 +116,52 @@ void CurrencyWidget::setupUI()
 
 void CurrencyWidget::fillTakeOffAndLandingCurrencies()
 {
-        const auto takeoff_landings = OPL::Statistics::countTakeOffLanding();
-        if(takeoff_landings.isEmpty() || takeoff_landings.size() != 2)
-            return;
-
-        QList<QLabel*> displayLabels = {
-            takeOffCountDisplayLabel,
-            landingCountDisplayLabel
-        };
-
-        for(int i = 0; i < 2; i++) {
-            int count = takeoff_landings[i].toInt();
-            if(count < 3)
-                setLabelColour(displayLabels[i], Colour::Red);
-            displayLabels[i]->setText(displayLabels[i]->text().arg(count));
-        }
-         QDate expiration_date = OPL::Statistics::currencyTakeOffLandingExpiry();
-            if (expiration_date <= QDate::currentDate())
-                setLabelColour(takeOffLandingExpiryDisplayLabel, Colour::Red);
-            takeOffLandingExpiryDisplayLabel->setText(expiration_date.toString(Qt::TextDate));
+    const auto takeoff_landings = OPL::Statistics::countTakeOffLanding();
+    if(takeoff_landings.isEmpty() || takeoff_landings.size() != 2)
+        return;
+
+    QList<QLabel*> displayLabels = {
+        takeOffCountDisplayLabel,
+        landingCountDisplayLabel
+    };
+
+    for(int i = 0; i < 2; i++) {
+        int count = takeoff_landings[i].toInt();
+        if(count < 3)
+            setLabelColour(displayLabels[i], Colour::Red);
+        displayLabels[i]->setText(displayLabels[i]->text().arg(count));
+    }
+    QDate expiration_date = OPL::Statistics::currencyTakeOffLandingExpiry();
+    if (expiration_date <= QDate::currentDate())
+        setLabelColour(takeOffLandingExpiryDisplayLabel, Colour::Red);
+    takeOffLandingExpiryDisplayLabel->setText(expiration_date.toString(Qt::TextDate));
 }
 
 void CurrencyWidget::fillFlightTimeLimitations()
 {
-    TODO << "Fill flight time limitations";
+    const QList<QPair<QLabel *, OPL::Statistics::TimeFrame>> limits =
+        {
+        { flightTime28DaysDisplayLabel, 		 OPL::Statistics::TimeFrame::Rolling28Days },
+        { flightTime365DaysDisplayLabel, 	 	 OPL::Statistics::TimeFrame::Rolling12Months },
+        { flightTimeCalendarYearDisplayLabel,    OPL::Statistics::TimeFrame::CalendarYear },
+        };
+
+    double ftlWarningThreshold = Settings::getFtlWarningThreshold();
+    for (const auto &pair : limits) {
+        int accruedMinutes = OPL::Statistics::totalTime(pair.second);
+        int limitMinutes = EasaFTL::getLimit(pair.second);
+        pair.first->setText(OPL::Time(accruedMinutes).toString());
+
+
+        if (accruedMinutes >= limitMinutes)
+            setLabelColour(pair.first, Colour::Red);
+        else if (accruedMinutes >= limitMinutes * ftlWarningThreshold)
+            setLabelColour(pair.first, Colour::Orange);
+    }
 }
 
 void CurrencyWidget::editRequested(const QModelIndex &index)
 {
-    LOG << "Edit requested at: " << index.data();
     lastSelection = index;
     const QString selection = index.data().toString();
     const QDate selectedDate = QDate::fromString(selection, dateFormat);
@@ -152,7 +172,6 @@ void CurrencyWidget::editRequested(const QModelIndex &index)
         calendar->show();
     } else {
         // the displayName column has been selected for editing
-        LOG << "Other edit requested";
         displayNameEditRequested(index);
     }
 }