# openPilotLog: src/functions/acalc.h Source File

acalc.h
#ifndef ACALC_H
#define ACALC_H
#include "src/database/db.h"
#include "src/classes/aircraft.h"
#include "src/classes/flight.h"
#include "src/classes/asettings.h"
#include <QDateTime>
#include <cmath>
#include <QDebug>
namespace ACalc {
inline QTime blocktime(QTime tofb, QTime tonb)
{
QTime blocktime_out(0, 0); // initialise return value at midnight
if (tonb > tofb) { // landing same day
int blockseconds = tofb.secsTo(tonb);
blocktime_out = blocktime_out.addSecs(blockseconds);
} else { // landing next day
QTime midnight(0, 0);
int blockseconds = tofb.secsTo(midnight);
blocktime_out = blocktime_out.addSecs(blockseconds);
blockseconds = midnight.secsTo(tonb);
blocktime_out = blocktime_out.addSecs(blockseconds);
}
return blocktime_out;
}
inline QString minutesToString(QString block_minutes)
{
int minutes = block_minutes.toInt();
QString hour = QString::number(minutes / 60);
if (hour.size() < 2) {
hour.prepend("0");
}
QString minute = QString::number(minutes % 60);
if (minute.size() < 2) {
minute.prepend("0");
}
QString block_time = hour + ":" + minute;
return block_time;
};
inline QString minutesToString(int block_minutes)
{
QString hour = QString::number(block_minutes / 60);
if (hour.size() < 2) {
hour.prepend("0");
}
QString minute = QString::number(block_minutes % 60);
if (minute.size() < 2) {
minute.prepend("0");
}
QString blocktime = hour + ":" + minute;
return blocktime;
};
inline int QTimeToMinutes(QTime time)
{
QString timestring = time.toString("hh:mm");
int minutes = (timestring.left(2).toInt()) * 60;
minutes += timestring.right(2).toInt();
return minutes;
}
inline int stringToMinutes(QString timestring)
{
int minutes = (timestring.left(2).toInt()) * 60;
minutes += timestring.right(2).toInt();
timestring = QString::number(minutes);
return minutes;
}
inline double radToDeg(double rad)
{
double deg = rad * (180 / M_PI);
return deg;
}
inline double degToRad(double deg)
{
double rad = deg * (M_PI / 180);
return rad;
}
inline double radToNauticalMiles(double rad)
{
double nm = rad * 3440.06479482;
return nm;
}
double greatCircleDistance(double lat1, double lon1, double lat2, double lon2);
double greatCircleDistanceBetweenAirports(const QString &dept, const QString &dest);
QVector<QVector<double>> intermediatePointsOnGreatCircle(double lat1,
double lon1,
double lat2,
double lon2,
int tblk);
double solarElevation(QDateTime utc_time_point, double lat, double lon);
int calculateNightTime(const QString &dept, const QString &dest, QDateTime departureTime, int tblk, int nightAngle);
bool isNight(const QString &icao, QDateTime event_time, int night_angle);
QString formatTimeInput(QString user_input);
void updateAutoTimes(int acft_id);
void autoTimes(Flight, Aircraft);
void updateNightTimes();
} // namespace ACalc
#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