Skip to content

Commit

Permalink
Fix METAR value translation into Aerofly Weather object
Browse files Browse the repository at this point in the history
* Visibility calculation could be improved for ranges above 10SM
* Wind speed calculation had wrong max value
  • Loading branch information
fboes committed Mar 24, 2019
1 parent fb2c382 commit 0256e65
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change log
==========

* 💊 Fix METAR value translation into Aerofly Weather object (wind speed, visibility)

1.0.1
-----

* 💊 Improve handling of ICAO codes
* 💊 Fix behaviour of seconds in UTC time

Expand Down
2 changes: 1 addition & 1 deletion src/WettergeraetDesktop/Frame.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define wxUSE_DATEPICKCTRL 1
#define MY_APP_VERSION_STRING "1.0.1"
#define MY_APP_VERSION_STRING "1.1.0"

#include <wx/wx.h>
#include <wx/datectrl.h>
Expand Down
5 changes: 2 additions & 3 deletions src/WettergeraetLib/AeroflyWeather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,15 @@ void AeroflyWeather::setThermalActivity(double celsius)

void AeroflyWeather::setVisibility(unsigned long meters)
{
const unsigned long maxMiles = 10 * 1609;
meters = std::min(maxMiles, meters);
const unsigned long maxMiles = 10 * 1609.344;
if (this->maxVisibility > 9999 && (meters == 9999 || meters == 10000)) {
// because meters cannot be greater than 9999
// but miles can reach up to 10sm
// set 9999 meters to 10 sm
meters = maxMiles;
}
this->visibility = BoShed::percent((double)meters / (double)this->maxVisibility, true);
if (this->maxVisibility > maxMiles) {
if (meters <= maxMiles && this->maxVisibility > maxMiles) {
// max visibility range cannot be reached, because in METAR there is only <= 10 sm
// Interpolate the last part
this->visibility += (1.0 - ((double)maxMiles / (double)this->maxVisibility)) * std::pow((meters / maxMiles), 8);
Expand Down
14 changes: 7 additions & 7 deletions src/WettergeraetLib/AeroflyWeather.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
class AeroflyWeather
{
private:
unsigned short maxCloudsDensity = 8;
unsigned long maxCloudsHeight = 40000; // ft
double maxWindSpeed = 40; // kt
unsigned long maxVisibility = 20000; // m
double maxTurbulence = 20; // kt
double minTemperature = 5; // °C
double maxTemperature = 30; // °C
unsigned short maxCloudsDensity = 8; // as given in METAR cloud density
unsigned long maxCloudsHeight = 40000; // ft = 100% Aerofly
double maxWindSpeed = 16; // kt = 100% Aerofly
unsigned long maxVisibility = 20000; // m = 100% Aerofly
double maxTurbulence = 20; // kt as delta to current wind
double minTemperature = 5; // °C => 0% Aerofly
double maxTemperature = 30; // °C => 100% Aerofly
double hourOffset = 0.0;
bool noRandom = false;

Expand Down
2 changes: 1 addition & 1 deletion src/WettergeraetLib/BoShed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace BoShed {
double percent(double value, bool notMoreThan1)
{
if (notMoreThan1 && value > 1.0) {
return value;
return 1.0;
}
if (value < 0.0) {
return 0.0;
Expand Down

0 comments on commit 0256e65

Please sign in to comment.