Bläddra i källkod

added options for automatic night time calculations based on solar elevation angle

fiffty-50 4 år sedan
förälder
incheckning
be805f19f5

+ 1 - 1
openPilotLog.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.11.0, 2020-11-08T18:25:34. -->
+<!-- Written by QtCreator 4.11.0, 2020-11-08T19:27:35. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 11 - 4
src/classes/calc.cpp

@@ -19,6 +19,7 @@
 // Debug Makro
 #define DEB(expr) \
     qDebug() << __PRETTY_FUNCTION__ << "\t" << expr
+
 /*!
  * \brief Calc::blocktime Calculates Block Time for a given departure and arrival time
  * \param tofb QTime Time Off Blocks
@@ -337,9 +338,11 @@ double Calc::solarElevation(QDateTime utc_time_point, double lat, double lon)
  * \param dest - ICAO 4-letter Code of Destination Airport
  * \param departureTime - QDateTime of Departure (UTC)
  * \param tblk - Total block time in minutes
+ * \param nightAngle - the solar elevation angle where night conditons exist.
+ * Default -6 (end of civil evening twilight)
  * \return Total number of minutes under night flying conditions
  */
-int Calc::calculateNightTime(QString dept, QString dest, QDateTime departureTime, int tblk)
+int Calc::calculateNightTime(QString dept, QString dest, QDateTime departureTime, int tblk, int nightAngle)
 {
     QVector<QString> columns = {"lat", "long"};
     QVector<QString> deptCoordinates = Db::multiSelect(columns, "airports", "icao", dept,
@@ -369,11 +372,12 @@ int Calc::calculateNightTime(QString dept, QString dest, QDateTime departureTime
     int nightTime = 0;
     for (int i = 0; i < tblk ; i++) {
         if (solarElevation(departureTime.addSecs(60 * i), radToDeg(route[i][0]),
-                           radToDeg(route[i][1])) < -0.6) {
+                           radToDeg(route[i][1])) < nightAngle) {
             nightTime ++;
         }
     }
-    qDebug() << "Calc::CalculateNightTime result: " << nightTime << " minutes night flying time.";
+    qDebug() << "Calc::CalculateNightTime result for angle: "<< nightAngle
+             << " :" << nightTime << " minutes night flying time.";
     return nightTime;
 }
 
@@ -452,6 +456,8 @@ void Calc::updateAutoTimes(int acft_id)
  */
 void Calc::updateNightTimes()
 {
+    QSettings settings;
+    int nightAngle = settings.value("flightlogging/nightangle").toInt();
     QVector<QString> columns = {"id"};
     auto flights = Db::multiSelect(columns,"flights");
     for (const auto& item : flights) {
@@ -462,7 +468,8 @@ void Calc::updateNightTimes()
         flt->data.insert("tNIGHT", QString::number(calculateNightTime(flt->data.value("dept"),
                                                                       flt->data.value("dest"),
                                                                       dateTime,
-                                                                      flt->data.value("tblk").toInt())));
+                                                                      flt->data.value("tblk").toInt(),
+                                                                      nightAngle)));
         flt->commit();
     }
 }

+ 2 - 1
src/classes/calc.h

@@ -25,6 +25,7 @@
 #include <QDateTime>
 #include <cmath>
 #include <QDebug>
+#include <QSettings>
 /*!
  * \brief The calc class provides functionality for various calculations that are performed
  * outside of the database. This includes tasks like converting different units and formats,
@@ -60,7 +61,7 @@ public:
 
     static double solarElevation(QDateTime utc_time_point, double lat, double lon);
 
-    static int calculateNightTime(QString dept, QString dest, QDateTime departureTime, int tblk);
+    static int calculateNightTime(QString dept, QString dest, QDateTime departureTime, int tblk, int nightAngle);
 
     static QString formatTimeInput(QString userinput);
 

+ 13 - 1
src/gui/widgets/homewidget.cpp

@@ -43,9 +43,21 @@ void HomeWidget::on_pushButton_clicked()
     //for (int i=1;i<25;i++) {
     //    Calc::updateAutoTimes(i);
     //}
-    //Calc::updateNightTimes();
+    Calc::updateNightTimes();
     //DEB(Flight(23));
     //DEB(Pilot(2));
+    /*QSettings settings;
+    int nightAngle = settings.value("flightlogging/nightangle").toInt();
+    auto flt = new Flight(10);
+    auto dateTime = QDateTime(QDate::fromString(flt->data.value("doft"),Qt::ISODate),
+                              QTime().addSecs(flt->data.value("tofb").toInt() * 60),
+                              Qt::UTC);
+    DEB(QString::number(Calc::calculateNightTime(flt->data.value("dept"),
+                                                                  flt->data.value("dest"),
+                                                                  dateTime,
+                                                                  flt->data.value("tblk").toInt(),
+                                                                  nightAngle)));*/
+    //DEB(Calc::solarElevation(datetime,60.121,11.0502));
 
 }
 

+ 11 - 9
src/gui/widgets/settingswidget.cpp

@@ -245,16 +245,18 @@ void SettingsWidget::on_approachComboBox_currentIndexChanged(const QString &arg1
 
 void SettingsWidget::on_nightComboBox_currentIndexChanged(int index)
 {
-    if(index == 2){
-        auto mb = new QMessageBox(this);
-        mb->setText("This option is not yet available.");
-        mb->show();
-        ui->nightComboBox->setCurrentIndex(0);
-    } else {
-        QSettings settings;
-        settings.setValue("flightlogging/nightlogging", index);
+    QSettings settings;
+    settings.setValue("flightlogging/nightlogging", index);
+    switch (index) {
+    case 1:
+        settings.setValue("flightlogging/nightangle",-6);
+        break;
+    case 2:
+        settings.setValue("flightlogging/nightangle",0);
+        break;
+    default:
+        settings.setValue("flightlogging/nightangle",-6);
     }
-
 }
 
 void SettingsWidget::on_prefixLineEdit_textChanged(const QString &arg1)

+ 28 - 1
src/gui/widgets/settingswidget.ui

@@ -17,7 +17,7 @@
    <item row="0" column="1">
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>0</number>
+      <number>1</number>
      </property>
      <widget class="QWidget" name="personalTab">
       <attribute name="title">
@@ -173,6 +173,9 @@
       <layout class="QGridLayout" name="gridLayout_4">
        <item row="0" column="1">
         <widget class="QLabel" name="aliasLabel">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;How your own name is displayed in your logbook&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
          <property name="text">
           <string>Show own name as</string>
          </property>
@@ -199,6 +202,9 @@
        </item>
        <item row="1" column="1">
         <widget class="QLabel" name="functionLabel">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default function for auto-logging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
          <property name="text">
           <string>Function</string>
          </property>
@@ -230,6 +236,9 @@
        </item>
        <item row="2" column="1">
         <widget class="QLabel" name="rulesLabel">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default Flight Rules for auto-logging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
          <property name="text">
           <string>Flight Rules</string>
          </property>
@@ -264,6 +273,9 @@
        </item>
        <item row="3" column="1">
         <widget class="QLabel" name="approachLabel">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The default approach for auto-logging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
          <property name="text">
           <string>Approach</string>
          </property>
@@ -393,6 +405,12 @@
        </item>
        <item row="4" column="1">
         <widget class="QLabel" name="nightLabel">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Determines how (if) night time is automatically calculated. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="whatsThis">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
          <property name="text">
           <string>Night Time</string>
          </property>
@@ -400,6 +418,12 @@
        </item>
        <item row="4" column="2">
         <widget class="QComboBox" name="nightComboBox">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;EASA: End of civil evening twilight until beginning of civil morning twilight&lt;/p&gt;&lt;p&gt;SR/SS: From sunrise to sunset.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
+         <property name="whatsThis">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;EASA: End of civil evening twilight until beginning of civil morning twilight&lt;/p&gt;&lt;p&gt;SR/SS: From sunrise to sunset.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
          <item>
           <property name="text">
            <string>NO</string>
@@ -419,6 +443,9 @@
        </item>
        <item row="5" column="1">
         <widget class="QLabel" name="prefixLabel">
+         <property name="toolTip">
+          <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter you airline Prefix to speed up logging of flight numbers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+         </property>
          <property name="text">
           <string>Airline Prefix</string>
          </property>

+ 2 - 2
src/gui/widgets/totalswidget.ui

@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>639</width>
-    <height>453</height>
+    <width>634</width>
+    <height>382</height>
    </rect>
   </property>
   <property name="windowTitle">