Skip to content

Commit

Permalink
Merge pull request #92 from opensky-to/online-networks
Browse files Browse the repository at this point in the history
Online networks
  • Loading branch information
sushiat authored Dec 7, 2023
2 parents e563433 + c4ea4e3 commit 2db2e19
Show file tree
Hide file tree
Showing 26 changed files with 767 additions and 142 deletions.
12 changes: 10 additions & 2 deletions OpenSky.Client.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/QualifiedUsingAtNestedScope/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">--------------------------------------------------------------------------------------------------------------------&#xD;
&lt;copyright file="$FILENAME$" company="OpenSky"&gt;&#xD;
OpenSky project $CURRENT_YEAR$&#xD;
&lt;copyright file="${File.FileName}" company="OpenSky"&gt;&#xD;
OpenSky project ${CurrentDate.Year}&#xD;
&lt;/copyright&gt;&#xD;
--------------------------------------------------------------------------------------------------------------------</s:String>
<s:Boolean x:Key="/Default/CodeStyle/Generate/=EqualityMembers/@KeyIndexDefined">True</s:Boolean>
Expand Down Expand Up @@ -584,19 +584,22 @@ OpenSky project $CURRENT_YEAR$&#xD;
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=NAMESPACE_005FALIAS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECodeCleanup_002EFileHeader_002EFileHeaderSettingsMigrate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=addon/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Adorner/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=AGLR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=aircraftmarket/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=altn/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=appdata/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=apptoken/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Barthel/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Callsign/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cashflow/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=changepassword/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=civalue/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -619,6 +622,7 @@ OpenSky project $CURRENT_YEAR$&#xD;
<s:Boolean x:Key="/Default/UserDictionary/Words/=Groupbox/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Haversine/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Headered/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ICAO/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=INSTALLFOLDER/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=magdecl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=manualrmk/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -627,22 +631,26 @@ OpenSky project $CURRENT_YEAR$&#xD;
<s:Boolean x:Key="/Default/UserDictionary/Words/=multiselector/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Multiselectors/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=MVVM/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Navlog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Navmap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=newaircraft/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=OPENSKY/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=performant/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pinquestion/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=plannable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Populator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=prefile/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Segoe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=selcal/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=shortdistance/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Simbrief/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Skybucks/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sqlite/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=syncfusion/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tabablz/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Templated/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Textbox/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vatsim/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Viewbox/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=waypoint/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=winforms/@EntryIndexedValue">True</s:Boolean>
Expand Down
8 changes: 7 additions & 1 deletion OpenSky.Client/Controls/MapView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,13 @@ public void ShowAllMarkers(bool overrideUser = false)
}
else
{
UpdateGUIDelegate resetMap = () => { this.WpfMapView.SetView(new LocationRect(new Location(80, -50), new Location(-65, 60))); };
UpdateGUIDelegate resetMap = () =>
{
if (this.WpfMapView.IsLoaded)
{
this.WpfMapView.SetView(new LocationRect(new Location(80, -50), new Location(-65, 60)));
}
};
this.Dispatcher.BeginInvoke(resetMap);
this.userMapInteraction = false;
}
Expand Down
138 changes: 138 additions & 0 deletions OpenSky.Client/Converters/LargeNumberConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LargeNumberConverter.cs" company="OpenSky">
// OpenSky project 2021-2023
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace OpenSky.Client.Converters
{
using System;
using System.Globalization;
using System.Windows.Data;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Large number converter, 8531780 => 8.5m, 11580 => 11.6k.
/// </summary>
/// <remarks>
/// sushi.at, 04/12/2023.
/// </remarks>
/// <seealso cref="System.Windows.Data.IValueConverter"/>
/// -------------------------------------------------------------------------------------------------
public class LargeNumberConverter : IValueConverter
{
/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Converts a value.
/// </summary>
/// <remarks>
/// sushi.at, 04/12/2023.
/// </remarks>
/// <param name="value">
/// The value produced by the binding source.
/// </param>
/// <param name="targetType">
/// The type of the binding target property.
/// </param>
/// <param name="parameter">
/// The converter parameter to use.
/// </param>
/// <param name="culture">
/// The culture to use in the converter.
/// </param>
/// <returns>
/// A converted value. If the method returns <see langword="null" />, the valid null value is
/// used.
/// </returns>
/// <seealso cref="IValueConverter.Convert(object,Type,object,CultureInfo)"/>
/// -------------------------------------------------------------------------------------------------
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var valueToConvert = double.NaN;
if (value is long longValue)
{
valueToConvert = longValue;
}

if (value is double doubleValue)
{
valueToConvert = doubleValue;
}

if (value is int intValue)
{
valueToConvert = intValue;
}

if (!double.IsNaN(valueToConvert))
{
// Trillions, seriously?
if (valueToConvert > Math.Pow(10, 12))
{
valueToConvert /= Math.Pow(10, 12);
valueToConvert = Math.Round(valueToConvert, 1, MidpointRounding.AwayFromZero);
return $"{valueToConvert}t";
}

// Billions, good job
if (valueToConvert > Math.Pow(10, 9))
{
valueToConvert /= Math.Pow(10, 9);
valueToConvert = Math.Round(valueToConvert, 1, MidpointRounding.AwayFromZero);
return $"{valueToConvert}b";
}

// Millions
if (valueToConvert > Math.Pow(10, 6))
{
valueToConvert /= Math.Pow(10, 6);
valueToConvert = Math.Round(valueToConvert, 1, MidpointRounding.AwayFromZero);
return $"{valueToConvert}m";
}

// Thousands
if (valueToConvert > Math.Pow(10, 3))
{
valueToConvert /= Math.Pow(10, 3);
valueToConvert = Math.Round(valueToConvert, 1, MidpointRounding.AwayFromZero);
return $"{valueToConvert}k";
}

// Below 1k
return $"{valueToConvert}";
}

return value;
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Converts a value - not supported.
/// </summary>
/// <remarks>
/// sushi.at, 04/12/2023.
/// </remarks>
/// <param name="value">
/// The value that is produced by the binding target.
/// </param>
/// <param name="targetType">
/// The type to convert to.
/// </param>
/// <param name="parameter">
/// The converter parameter to use.
/// </param>
/// <param name="culture">
/// The culture to use in the converter.
/// </param>
/// <returns>
/// A converted value. If the method returns <see langword="null" />, the valid null value is
/// used.
/// </returns>
/// <seealso cref="IValueConverter.ConvertBack(object,Type,object,CultureInfo)"/>
/// -------------------------------------------------------------------------------------------------
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
13 changes: 10 additions & 3 deletions OpenSky.Client/Converters/PieChartValueAdornerLabelConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ namespace OpenSky.Client.Converters
/// -------------------------------------------------------------------------------------------------
public class PieChartValueAdornerLabelConverter : IValueConverter
{
/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The large number converter.
/// </summary>
/// -------------------------------------------------------------------------------------------------
private readonly LargeNumberConverter largeNumberConverter = new();

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Converts a value.
Expand Down Expand Up @@ -53,7 +60,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
{
if (value is PieChartValue chartValue)
{
return $"{chartValue.Key}: {chartValue.Value}";
return $"{chartValue.Key}: {this.largeNumberConverter.Convert(chartValue.Value, null, null, null)}";
}

if (value is List<object> list)
Expand All @@ -69,15 +76,15 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
}
}

return $"Others: {totalValue}";
return $"Others: {this.largeNumberConverter.Convert(totalValue, null, null, null)}";
}

var labels = string.Empty;
foreach (var obj in list)
{
if (obj is PieChartValue chartValueFromList)
{
labels += $"{chartValueFromList.Key}: {chartValueFromList.Value}, ";
labels += $"{chartValueFromList.Key}: {this.largeNumberConverter.Convert(chartValueFromList.Value, null, null, null)}, ";
}
}

Expand Down
2 changes: 2 additions & 0 deletions OpenSky.Client/OpenAPIs/ModelExtensions/AircraftType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public AircraftType(AircraftType copyFrom)
this.EngineModel = copyFrom.EngineModel;
this.OverrideFuelType = copyFrom.OverrideFuelType;
this.IsHistoric = copyFrom.IsHistoric;
this.UsesStrobeForBeacon = copyFrom.UsesStrobeForBeacon;
this.IcaoTypeDesignator = copyFrom.IcaoTypeDesignator;
this.DeliveryLocations = new List<AircraftManufacturerDeliveryLocation>();
this.DeliveryLocations.AddRange(copyFrom.DeliveryLocations);
}
Expand Down
21 changes: 21 additions & 0 deletions OpenSky.Client/OpenAPIs/ModelExtensions/FlightLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,27 @@ public string OnBlock
/// -------------------------------------------------------------------------------------------------
public double OnBlockFuelWeight => this.OnBlockFuel * this.FuelWeightPerGallon;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the online network duration info.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public string OnlineNetworkDuration
{
get
{
if (this.OnlineNetwork != OnlineNetwork.Offline)
{
var duration = TimeSpan.FromSeconds(this.OnlineNetworkConnectedSeconds);
var percentageOfFlightTime = this.OnlineNetworkConnectedSeconds / ((this.Completed - this.Started).TotalSeconds) * 100.0;

return $"{duration}, {percentageOfFlightTime:N1} % of flight";
}

return string.Empty;
}
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets information describing the time warp.
Expand Down
Loading

0 comments on commit 2db2e19

Please sign in to comment.