openPilotLog

acalc.h
1 #ifndef ACALC_H
2 #define ACALC_H
3
4 #include "src/database/db.h"
5 #include "src/classes/aircraft.h"
6 #include "src/classes/flight.h"
7 #include "src/classes/asettings.h"
8 #include <QDateTime>
9 #include <cmath>
10 #include <QDebug>
17 namespace ACalc {
18
25 inline QTime blocktime(QTime tofb, QTime tonb)
26 {
27 QTime blocktime_out(0, 0); // initialise return value at midnight
28
29 if (tonb > tofb) { // landing same day
30 int blockseconds = tofb.secsTo(tonb);
31 blocktime_out = blocktime_out.addSecs(blockseconds);
32 } else { // landing next day
33 QTime midnight(0, 0);
34 int blockseconds = tofb.secsTo(midnight);
35 blocktime_out = blocktime_out.addSecs(blockseconds);
36 blockseconds = midnight.secsTo(tonb);
37 blocktime_out = blocktime_out.addSecs(blockseconds);
38 }
39 return blocktime_out;
40 }
46 inline QString minutesToString(QString block_minutes)
47 {
48 int minutes = block_minutes.toInt();
49 QString hour = QString::number(minutes / 60);
50 if (hour.size() < 2) {
51 hour.prepend("0");
52 }
53 QString minute = QString::number(minutes % 60);
54 if (minute.size() < 2) {
55 minute.prepend("0");
56 }
57 QString block_time = hour + ":" + minute;
58 return block_time;
59 };
60
61 inline QString minutesToString(int block_minutes)
62 {
63 QString hour = QString::number(block_minutes / 60);
64 if (hour.size() < 2) {
65 hour.prepend("0");
66 }
67 QString minute = QString::number(block_minutes % 60);
68 if (minute.size() < 2) {
69 minute.prepend("0");
70 }
71 QString blocktime = hour + ":" + minute;
72 return blocktime;
73 };
74
80 inline int QTimeToMinutes(QTime time)
81 {
82 QString timestring = time.toString("hh:mm");
83 int minutes = (timestring.left(2).toInt()) * 60;
84 minutes += timestring.right(2).toInt();
85 return minutes;
86 }
87
93 inline int stringToMinutes(QString timestring)
94 {
95 int minutes = (timestring.left(2).toInt()) * 60;
96 minutes += timestring.right(2).toInt();
97 timestring = QString::number(minutes);
98 return minutes;
99 }
100
106 inline double radToDeg(double rad)
107 {
108 double deg = rad * (180 / M_PI);
109 return deg;
110 }
111
117 inline double degToRad(double deg)
118 {
119 double rad = deg * (M_PI / 180);
120 return rad;
121 }
122
128 inline double radToNauticalMiles(double rad)
129 {
130 double nm = rad * 3440.06479482;
131 return nm;
132 }
133
142 double greatCircleDistance(double lat1, double lon1, double lat2, double lon2);
143
151 double greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest);
152
163 QVector<QVector<double>> intermediatePointsOnGreatCircle(double lat1,
164 double lon1,
165 double lat2,
166 double lon2,
167 int tblk);
184 double solarElevation(QDateTime utc_time_point, double lat, double lon);
185
196 int calculateNightTime(const QString &dept, const QString &dest, QDateTime departureTime, int tblk, int nightAngle);
197
198 bool isNight(const QString &icao, QDateTime event_time, int night_angle);
199
200 QString formatTimeInput(QString user_input);
201
202 void updateAutoTimes(int acft_id);
203
204 void autoTimes(Flight, Aircraft);
205
206 void updateNightTimes();
207 } // namespace ACalc
208
209 #endif // ACALC_H
Flight
Definition: flight.h:28
ACalc::blocktime
QTime blocktime(QTime tofb, QTime tonb)
ACalc::blocktime Calculates Block Time for a given departure and arrival time.
Definition: acalc.h:25
ACalc::intermediatePointsOnGreatCircle
QVector< QVector< double > > intermediatePointsOnGreatCircle(double lat1, double lon1, double lat2, double lon2, int tblk)
Calculates a list of points (lat,lon) along the Great Circle between two points. The points are space...
Definition: acalc.cpp:114
ACalc::updateAutoTimes
void updateAutoTimes(int acft_id)
ACalc::updateAutoTimes When the details of an aircraft are changed, this function recalculates deduct...
Definition: acalc.cpp:262
ACalc::QTimeToMinutes
int QTimeToMinutes(QTime time)
ACalc::time_to_minutes converts QTime to int minutes.
Definition: acalc.h:80
ACalc::radToNauticalMiles
double radToNauticalMiles(double rad)
radToNauticalMiles Convert Radians to nautical miles
Definition: acalc.h:128
ACalc::stringToMinutes
int stringToMinutes(QString timestring)
ACalc::string_to_minutes Converts String Time to String Number of Minutes.
Definition: acalc.h:93
Aircraft
The aircraft class.
Definition: aircraft.h:28
ACalc
The ACalc namespace provides various functions for calculations that are performed outside of the dat...
Definition: acalc.h:17
ACalc::minutesToString
QString minutesToString(QString block_minutes)
ACalc::minutes_to_string Converts database time to String Time.
Definition: acalc.h:46
ACalc::degToRad
double degToRad(double deg)
degToRad Converts degrees to radians
Definition: acalc.h:117
ACalc::radToDeg
double radToDeg(double rad)
radToDeg Converts radians to degrees
Definition: acalc.h:106
ACalc::greatCircleDistanceBetweenAirports
double greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest)
ACalc::greatCircleDistanceBetweenAirports Calculates Great Circle distance between two coordinates,...
Definition: acalc.cpp:87
ACalc::solarElevation
double solarElevation(QDateTime utc_time_point, double lat, double lon)
Calculates solar elevation angle for a given point in time and latitude/longitude coordinates.
Definition: acalc.cpp:145
ACalc::greatCircleDistance
double greatCircleDistance(double lat1, double lon1, double lat2, double lon2)
greatCircleDistance Calculates Great Circle distance between two coordinates, return in Radians.
Definition: acalc.cpp:68
ACalc::formatTimeInput
QString formatTimeInput(QString user_input)
ACalc::formatTimeInput verifies user input and formats to hh:mm if the output is not a valid time,...
Definition: acalc.cpp:15
ACalc::updateNightTimes
void updateNightTimes()
ACalc::updateNightTimes updates the night times in the database, used when changing night angle setti...
Definition: acalc.cpp:308
ACalc::calculateNightTime
int calculateNightTime(const QString &dept, const QString &dest, QDateTime departureTime, int tblk, int nightAngle)
Calculates which portion of a flight was conducted in night conditions.
Definition: acalc.cpp:205