Ejemplo n.º 1
0
        public void AircraftListJsonMessageConverter_Deals_Correctly_With_Altitude_Types_From_Older_Versions_Of_VRS()
        {
            // If the Geometric altitude is null then the feed is coming from an older version of VRS
            // that didn't send Geometric, Altitude and AltitudeType as a set. In that case we always
            // use Altitude regardless of altitude type

            var json = new AircraftJson()
            {
                Icao24 = "ABCDEF", Altitude = 100
            };

            _AircraftListJson.Aircraft.Add(json);

            // If altitude type is missing then use altitude...
            var eventArgs = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();

            Assert.AreEqual(100, eventArgs.Message.Altitude);

            // If altitude type is barometric then use altitude...
            json.AltitudeType = (int)AltitudeType.Barometric;
            eventArgs         = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();
            Assert.AreEqual(100, eventArgs.Message.Altitude);

            // ... and if altitude type is geometric then use altitude
            json.AltitudeType = (int)AltitudeType.Geometric;
            eventArgs         = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();
            Assert.AreEqual(100, eventArgs.Message.Altitude);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds the full or short coordinates list and attaches it to the aircraft JSON object.
        /// </summary>
        /// <param name="shortCoordinates"></param>
        /// <param name="firstTimeSeen"></param>
        /// <param name="aircraftJson"></param>
        /// <param name="aircraftSnapshot"></param>
        /// <param name="args"></param>
        private void BuildCoordinatesList(bool shortCoordinates, bool firstTimeSeen, AircraftJson aircraftJson, IAircraft aircraftSnapshot, AircraftListJsonBuilderArgs args)
        {
            aircraftJson.ResetTrail = firstTimeSeen || args.ResendTrails || aircraftSnapshot.FirstCoordinateChanged > args.PreviousDataVersion;
            List <double?> list = new List <double?>();

            Coordinate lastCoordinate = null;

            foreach (var coordindate in shortCoordinates ? aircraftSnapshot.ShortCoordinates : aircraftSnapshot.FullCoordinates)
            {
                if (aircraftJson.ResetTrail || coordindate.DataVersion > args.PreviousDataVersion)
                {
                    list.Add(Round.Coordinate(coordindate.Latitude));
                    list.Add(Round.Coordinate(coordindate.Longitude));
                    if (shortCoordinates)
                    {
                        list.Add(JavascriptHelper.ToJavascriptTicks(coordindate.Tick));
                    }
                    else
                    {
                        list.Add(Round.Track(coordindate.Heading));
                    }
                }

                lastCoordinate = coordindate;
            }

            if (aircraftSnapshot.Latitude != null && aircraftSnapshot.Longitude != null &&
                (lastCoordinate.Latitude != aircraftSnapshot.Latitude || lastCoordinate.Longitude != aircraftSnapshot.Longitude) &&
                aircraftSnapshot.PositionTimeChanged > args.PreviousDataVersion)
            {
                list.Add(Round.Coordinate(aircraftSnapshot.Latitude));
                list.Add(Round.Coordinate(aircraftSnapshot.Longitude));
                if (shortCoordinates)
                {
                    list.Add(JavascriptHelper.ToJavascriptTicks(aircraftSnapshot.PositionTime.Value));
                }
                else
                {
                    list.Add(Round.Track(aircraftSnapshot.Track));
                }
            }

            if (list.Count != 0)
            {
                if (shortCoordinates)
                {
                    aircraftJson.ShortCoordinates = list;
                }
                else
                {
                    aircraftJson.FullCoordinates = list;
                }
            }
        }
        public void AircraftJson_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var aircraftJson = new AircraftJson();

            TestUtilities.TestProperty(aircraftJson, r => r.Altitude, null, 12);
            TestUtilities.TestProperty(aircraftJson, r => r.BearingFromHere, null, 12.3);
            TestUtilities.TestProperty(aircraftJson, r => r.Callsign, null, "ND");
            TestUtilities.TestProperty(aircraftJson, r => r.CallsignIsSuspect, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.ConstructionNumber, null, "Uu");
            TestUtilities.TestProperty(aircraftJson, r => r.Destination, null, "Bb");
            TestUtilities.TestProperty(aircraftJson, r => r.DistanceFromHere, null, 12.45);
            TestUtilities.TestProperty(aircraftJson, r => r.Emergency, null, false);
            TestUtilities.TestProperty(aircraftJson, r => r.EngineType, null, 1);
            TestUtilities.TestProperty(aircraftJson, r => r.FirstSeen, null, DateTime.UtcNow);
            TestUtilities.TestProperty(aircraftJson, r => r.FullCoordinates, null, new List <double?>()
            {
                1.1, 2.2
            });
            TestUtilities.TestProperty(aircraftJson, r => r.GroundSpeed, null, 12.4f);
            TestUtilities.TestProperty(aircraftJson, r => r.HasPicture, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.Icao24, null, "Hh");
            TestUtilities.TestProperty(aircraftJson, r => r.Icao24Country, null, "Jk");
            TestUtilities.TestProperty(aircraftJson, r => r.Icao24Invalid, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.IsMilitary, null, false);
            TestUtilities.TestProperty(aircraftJson, r => r.Latitude, null, 1.234);
            TestUtilities.TestProperty(aircraftJson, r => r.Longitude, null, 1.234);
            TestUtilities.TestProperty(aircraftJson, r => r.Model, null, "Mm");
            TestUtilities.TestProperty(aircraftJson, r => r.NumberOfEngines, null, "C");
            TestUtilities.TestProperty(aircraftJson, r => r.OnGround, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.Operator, null, "Hj");
            TestUtilities.TestProperty(aircraftJson, r => r.OperatorIcao, null, "Ik");
            TestUtilities.TestProperty(aircraftJson, r => r.Origin, null, "Yh");
            TestUtilities.TestProperty(aircraftJson, r => r.PositionTime, null, 1234L);
            TestUtilities.TestProperty(aircraftJson, r => r.Registration, null, "Fd");
            TestUtilities.TestProperty(aircraftJson, r => r.ResetTrail, false);
            TestUtilities.TestProperty(aircraftJson, r => r.ShortCoordinates, null, new List <double?>()
            {
                1.1, 2.2
            });
            TestUtilities.TestProperty(aircraftJson, r => r.Species, null, 12);
            TestUtilities.TestProperty(aircraftJson, r => r.Squawk, null, "4721");
            TestUtilities.TestProperty(aircraftJson, r => r.Stopovers, null, new List <string>()
            {
                "Hd"
            });
            TestUtilities.TestProperty(aircraftJson, r => r.Track, null, 12.34f);
            TestUtilities.TestProperty(aircraftJson, r => r.Type, null, "B747");
            TestUtilities.TestProperty(aircraftJson, r => r.UniqueId, 0, 12);
            TestUtilities.TestProperty(aircraftJson, r => r.UserTag, null, "Abc");
            TestUtilities.TestProperty(aircraftJson, r => r.VerticalRate, null, -239);
            TestUtilities.TestProperty(aircraftJson, r => r.WakeTurbulenceCategory, null, 7);
        }
Ejemplo n.º 4
0
        public void AircraftListJsonMessageConverter_Clears_IsMlat_When_Position_Is_Not_Present_And_Position_Is_Not_MLAT()
        {
            var aircraft = new AircraftJson()
            {
                Icao24         = "A",
                PositionIsMlat = true,
            };

            _AircraftListJson.Aircraft.Add(aircraft);

            var eventArgs = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();

            Assert.IsFalse(eventArgs.Message.IsMlat);
        }
Ejemplo n.º 5
0
        public void AircraftListJsonMessageConverter_Sets_IsMlat_When_Position_Is_Present_And_Position_Is_MLAT()
        {
            var aircraft = new AircraftJson()
            {
                Icao24         = "A",
                Latitude       = 1,
                Longitude      = 2,
                PositionIsMlat = true,
            };

            _AircraftListJson.Aircraft.Add(aircraft);

            var eventArgs = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();

            Assert.IsTrue(eventArgs.Message.IsMlat);
        }
Ejemplo n.º 6
0
        public void AircraftListJsonMessageConverter_Deals_Correctly_With_Altitude_Types_From_Current_Versions_Of_VRS()
        {
            var json = new AircraftJson()
            {
                Icao24 = "ABCDEF", Altitude = 100, GeometricAltitude = 200
            };

            _AircraftListJson.Aircraft.Add(json);

            // If the altitude type is Barometric then JSON Altitude should be copied into Altitude
            json.AltitudeType = (int)AltitudeType.Barometric;
            var eventArgs = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();

            Assert.AreEqual(100, eventArgs.Message.Altitude);

            // If the altitude type is Geometric then the JSON Altitude may have been calculated - the GeometricAltitude
            // should be used instead.
            json.AltitudeType = (int)AltitudeType.Geometric;
            eventArgs         = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();
            Assert.AreEqual(200, eventArgs.Message.Altitude);
        }
Ejemplo n.º 7
0
        public void AircraftListJsonMessageConverter_Copies_Json_Properties_To_Correct_Message_Property()
        {
            var worksheet = new ExcelWorksheetData(TestContext);

            var jsonPropertyName          = worksheet.String("JsonProperty");
            var jsonValueText             = worksheet.EString("JsonValue");
            var messagePropertyName       = worksheet.String("MsgProperty");
            var messageValueText          = worksheet.EString("MsgValue");
            var supplementaryPropertyName = worksheet.String("SuppProperty");
            var supplementaryValueText    = worksheet.EString("SuppValue");

            var isSupplementary = supplementaryPropertyName != null;

            var jsonProperty = typeof(AircraftJson).GetProperty(jsonPropertyName);

            if (jsonProperty == null)
            {
                Assert.Fail(jsonPropertyName);
            }
            var jsonValue = TestUtilities.ChangeType(jsonValueText, jsonProperty.PropertyType, CultureInfo.InvariantCulture);

            var messageProperty = isSupplementary ? null : typeof(BaseStationMessage).GetProperty(messagePropertyName);

            if (messageProperty == null && !isSupplementary)
            {
                Assert.Fail(messagePropertyName);
            }
            var messageValue = messageProperty == null ? null : TestUtilities.ChangeType(messageValueText, messageProperty.PropertyType, CultureInfo.InvariantCulture);

            var supplementaryProperty = isSupplementary ? typeof(BaseStationSupplementaryMessage).GetProperty(supplementaryPropertyName) : null;

            if (supplementaryProperty == null && isSupplementary)
            {
                Assert.Fail(supplementaryPropertyName);
            }
            var supplementaryValue = supplementaryProperty == null ? null : TestUtilities.ChangeType(supplementaryValueText, supplementaryProperty.PropertyType, CultureInfo.InvariantCulture);

            var aircraftJson = new AircraftJson();

            _AircraftListJson.Aircraft.Add(aircraftJson);
            jsonProperty.SetValue(aircraftJson, jsonValue, null);

            var eventArgs     = _Converter.ConvertIntoBaseStationMessageEventArgs(_AircraftListJson).Single();
            var supplementary = eventArgs.Message.Supplementary;

            if (messageProperty != null)
            {
                var actualValue = messageProperty.GetValue(eventArgs.Message, null);
                Assert.AreEqual(messageValue, actualValue, jsonPropertyName);
            }
            else
            {
                if (supplementary == null)
                {
                    if (supplementaryValue != null)
                    {
                        Assert.Fail(jsonPropertyName);
                    }
                }
                else
                {
                    var actualValue = supplementaryProperty.GetValue(supplementary, null);
                    Assert.AreEqual(supplementaryValue, actualValue, jsonPropertyName);
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Builds the full or short coordinates list and attaches it to the aircraft JSON object.
        /// </summary>
        /// <param name="shortCoordinates"></param>
        /// <param name="firstTimeSeen"></param>
        /// <param name="aircraftJson"></param>
        /// <param name="aircraftSnapshot"></param>
        /// <param name="args"></param>
        /// <param name="sendAltitude"></param>
        /// <param name="sendSpeed"></param>
        private void BuildCoordinatesList(bool shortCoordinates, bool firstTimeSeen, AircraftJson aircraftJson, IAircraft aircraftSnapshot, AircraftListJsonBuilderArgs args, bool sendAltitude, bool sendSpeed)
        {
            aircraftJson.ResetTrail = firstTimeSeen || args.ResendTrails || aircraftSnapshot.FirstCoordinateChanged > args.PreviousDataVersion;
            List <double?> list = new List <double?>();

            List <Coordinate> coordinates    = shortCoordinates ? aircraftSnapshot.ShortCoordinates : aircraftSnapshot.FullCoordinates;
            Coordinate        lastCoordinate = null;
            Coordinate        nextCoordinate = null;

            for (var i = 0; i < coordinates.Count; ++i)
            {
                var coordinate = nextCoordinate ?? coordinates[i];
                nextCoordinate = i + 1 == coordinates.Count ? null : coordinates[i + 1];

                if (aircraftJson.ResetTrail || coordinate.DataVersion > args.PreviousDataVersion)
                {
                    // If this is a full coordinate list then entries can be in here that only record a change in altitude or speed, and not a change in track. Those
                    // entries are to be ignored. They can be identified by having a track that is the same as their immediate neighbours in the list.
                    if (!shortCoordinates && lastCoordinate != null && nextCoordinate != null)
                    {
                        var dupeHeading = lastCoordinate.Heading == coordinate.Heading && coordinate.Heading == nextCoordinate.Heading;
                        if (dupeHeading && !sendAltitude && !sendSpeed)
                        {
                            continue;
                        }
                        var dupeAltitude = lastCoordinate.Altitude == coordinate.Altitude && coordinate.Altitude == nextCoordinate.Altitude;
                        if (sendAltitude && dupeHeading && dupeAltitude)
                        {
                            continue;
                        }
                        var dupeSpeed = lastCoordinate.GroundSpeed == coordinate.GroundSpeed && coordinate.GroundSpeed == nextCoordinate.GroundSpeed;
                        if (sendSpeed && dupeHeading && dupeSpeed)
                        {
                            continue;
                        }
                    }

                    list.Add(Round.Coordinate(coordinate.Latitude));
                    list.Add(Round.Coordinate(coordinate.Longitude));
                    if (shortCoordinates)
                    {
                        list.Add(JavascriptHelper.ToJavascriptTicks(coordinate.Tick));
                    }
                    else
                    {
                        list.Add((int?)coordinate.Heading);
                    }
                    if (sendAltitude)
                    {
                        list.Add(coordinate.Altitude);
                    }
                    else if (sendSpeed)
                    {
                        list.Add(coordinate.GroundSpeed);
                    }
                }

                lastCoordinate = coordinate;
            }

            if (aircraftSnapshot.Latitude != null && aircraftSnapshot.Longitude != null &&
                (lastCoordinate.Latitude != aircraftSnapshot.Latitude || lastCoordinate.Longitude != aircraftSnapshot.Longitude) &&
                aircraftSnapshot.PositionTimeChanged > args.PreviousDataVersion)
            {
                list.Add(Round.Coordinate(aircraftSnapshot.Latitude));
                list.Add(Round.Coordinate(aircraftSnapshot.Longitude));
                if (shortCoordinates)
                {
                    list.Add(JavascriptHelper.ToJavascriptTicks(aircraftSnapshot.PositionTime.Value));
                }
                else
                {
                    list.Add((int?)Round.TrackHeading(aircraftSnapshot.Track));
                }
                if (sendAltitude)
                {
                    list.Add(Round.TrackAltitude(aircraftSnapshot.Altitude));
                }
                else if (sendSpeed)
                {
                    list.Add(Round.TrackGroundSpeed(aircraftSnapshot.GroundSpeed));
                }
            }

            if (list.Count != 0)
            {
                if (shortCoordinates)
                {
                    aircraftJson.ShortCoordinates = list;
                }
                else
                {
                    aircraftJson.FullCoordinates = list;
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Copies the aircraft from the snapshot to the JSON object.
        /// </summary>
        /// <param name="aircraftListJson"></param>
        /// <param name="aircraftListSnapshot"></param>
        /// <param name="args"></param>
        /// <param name="distances"></param>
        private void CopyAircraft(AircraftListJson aircraftListJson, List <IAircraft> aircraftListSnapshot, AircraftListJsonBuilderArgs args, Dictionary <int, double?> distances)
        {
            var now                      = Provider.UtcNow;
            var configuration            = _SharedConfiguration.Get();
            var positionTimeoutThreshold = now.AddSeconds(-(configuration.BaseStationSettings.DisplayTimeoutSeconds + BoostStalePositionSeconds));

            HashSet <int> previousAircraftSet = null;
            List <int>    previousAircraft    = args.PreviousAircraft;

            if (previousAircraft.Count > 15)
            {
                previousAircraftSet = new HashSet <int>(previousAircraft);
                previousAircraft    = null;
            }

            double?distance = null;

            for (var i = 0; i < aircraftListSnapshot.Count; ++i)
            {
                var aircraftSnapshot = aircraftListSnapshot[i];
                if (distances != null)
                {
                    distances.TryGetValue(aircraftSnapshot.UniqueId, out distance);
                }

                var aircraftJson = new AircraftJson()
                {
                    UniqueId     = aircraftSnapshot.UniqueId,
                    IsSatcomFeed = aircraftSnapshot.LastSatcomUpdate != DateTime.MinValue,
                };
                if (!args.OnlyIncludeMessageFields)
                {
                    aircraftJson.BearingFromHere  = GreatCircleMaths.Bearing(args.BrowserLatitude, args.BrowserLongitude, aircraftSnapshot.Latitude, aircraftSnapshot.Longitude, null, false, true);
                    aircraftJson.DistanceFromHere = distance == null ? (double?)null : Math.Round(distance.Value, 2);
                    if (aircraftJson.BearingFromHere != null)
                    {
                        aircraftJson.BearingFromHere = Math.Round(aircraftJson.BearingFromHere.Value, 1);
                    }
                }

                var firstTimeSeen = previousAircraft != null ? !previousAircraft.Contains(aircraftSnapshot.UniqueId)
                                                             : !previousAircraftSet.Contains(aircraftSnapshot.UniqueId);

                if (firstTimeSeen || aircraftSnapshot.AirPressureInHgChanged > args.PreviousDataVersion)
                {
                    aircraftJson.AirPressureInHg = aircraftSnapshot.AirPressureInHg;
                }
                if (firstTimeSeen || aircraftSnapshot.AltitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Altitude = aircraftSnapshot.Altitude;
                }
                if (firstTimeSeen || aircraftSnapshot.AltitudeTypeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.AltitudeType = (int)aircraftSnapshot.AltitudeType;
                }
                if (firstTimeSeen || aircraftSnapshot.CallsignChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Callsign = aircraftSnapshot.Callsign;
                }
                if (firstTimeSeen || aircraftSnapshot.CallsignIsSuspectChanged > args.PreviousDataVersion)
                {
                    aircraftJson.CallsignIsSuspect = aircraftSnapshot.CallsignIsSuspect;
                }
                if (firstTimeSeen || aircraftSnapshot.GroundSpeedChanged > args.PreviousDataVersion)
                {
                    aircraftJson.GroundSpeed = Round.GroundSpeed(aircraftSnapshot.GroundSpeed);
                }
                if (firstTimeSeen || aircraftSnapshot.EmergencyChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Emergency = aircraftSnapshot.Emergency;
                }
                if (firstTimeSeen || aircraftSnapshot.GeometricAltitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.GeometricAltitude = aircraftSnapshot.GeometricAltitude;
                }
                if (firstTimeSeen || args.AlwaysShowIcao || aircraftSnapshot.Icao24Changed > args.PreviousDataVersion)
                {
                    aircraftJson.Icao24 = aircraftSnapshot.Icao24;
                }
                if (firstTimeSeen || aircraftSnapshot.IsTisbChanged > args.PreviousDataVersion)
                {
                    aircraftJson.IsTisb = aircraftSnapshot.IsTisb;
                }
                if (firstTimeSeen || aircraftSnapshot.LatitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Latitude = Round.Coordinate(aircraftSnapshot.Latitude);
                }
                if (firstTimeSeen || aircraftSnapshot.LongitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Longitude = Round.Coordinate(aircraftSnapshot.Longitude);
                }
                if (firstTimeSeen || aircraftSnapshot.OnGroundChanged > args.PreviousDataVersion)
                {
                    aircraftJson.OnGround = aircraftSnapshot.OnGround;
                }
                if (firstTimeSeen || aircraftSnapshot.PositionIsMlatChanged > args.PreviousDataVersion)
                {
                    aircraftJson.PositionIsMlat = aircraftSnapshot.PositionIsMlat;
                }
                if (firstTimeSeen || aircraftSnapshot.SignalLevelChanged > args.PreviousDataVersion)
                {
                    aircraftJson.HasSignalLevel = aircraftSnapshot.SignalLevel != null; aircraftJson.SignalLevel = aircraftSnapshot.SignalLevel;
                }
                if (firstTimeSeen || aircraftSnapshot.SpeedTypeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.SpeedType = (int)aircraftSnapshot.SpeedType;
                }
                if (firstTimeSeen || aircraftSnapshot.SquawkChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Squawk = String.Format("{0:0000}", aircraftSnapshot.Squawk);
                }
                if (firstTimeSeen || aircraftSnapshot.TargetAltitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.TargetAltitude = aircraftSnapshot.TargetAltitude;
                }
                if (firstTimeSeen || aircraftSnapshot.TargetTrackChanged > args.PreviousDataVersion)
                {
                    aircraftJson.TargetTrack = aircraftSnapshot.TargetTrack;
                }
                if (firstTimeSeen || aircraftSnapshot.TrackChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Track = Round.Track(aircraftSnapshot.Track);
                }
                if (firstTimeSeen || aircraftSnapshot.TrackIsHeadingChanged > args.PreviousDataVersion)
                {
                    aircraftJson.TrackIsHeading = aircraftSnapshot.TrackIsHeading;
                }
                if (firstTimeSeen || aircraftSnapshot.TransponderTypeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.TransponderType = (int)aircraftSnapshot.TransponderType;
                }
                if (firstTimeSeen || aircraftSnapshot.VerticalRateChanged > args.PreviousDataVersion)
                {
                    aircraftJson.VerticalRate = aircraftSnapshot.VerticalRate;
                }
                if (firstTimeSeen || aircraftSnapshot.VerticalRateTypeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.VerticalRateType = (int)aircraftSnapshot.VerticalRateType;
                }

                if (args.OnlyIncludeMessageFields)
                {
                    if (aircraftJson.Latitude != null || aircraftJson.Longitude != null || aircraftJson.PositionIsMlat != null)
                    {
                        if (aircraftJson.Latitude == null)
                        {
                            aircraftJson.Latitude = Round.Coordinate(aircraftSnapshot.Latitude);
                        }
                        if (aircraftJson.Longitude == null)
                        {
                            aircraftJson.Longitude = Round.Coordinate(aircraftSnapshot.Longitude);
                        }
                        if (aircraftJson.PositionIsMlat == null)
                        {
                            aircraftJson.PositionIsMlat = aircraftSnapshot.PositionIsMlat;
                        }
                    }
                    if (aircraftJson.Altitude != null || aircraftJson.GeometricAltitude != null || aircraftJson.AltitudeType != null)
                    {
                        if (aircraftJson.Altitude == null)
                        {
                            aircraftJson.Altitude = aircraftSnapshot.Altitude;
                        }
                        if (aircraftJson.AltitudeType == null)
                        {
                            aircraftJson.AltitudeType = (int)aircraftSnapshot.AltitudeType;
                        }
                        if (aircraftJson.GeometricAltitude == null)
                        {
                            aircraftJson.GeometricAltitude = aircraftSnapshot.GeometricAltitude;
                        }
                    }
                }
                else if (!args.OnlyIncludeMessageFields)
                {
                    if (firstTimeSeen || aircraftSnapshot.ConstructionNumberChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.ConstructionNumber = aircraftSnapshot.ConstructionNumber;
                    }
                    if (firstTimeSeen || aircraftSnapshot.CountMessagesReceivedChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.CountMessagesReceived = aircraftSnapshot.CountMessagesReceived;
                    }
                    if (firstTimeSeen || aircraftSnapshot.DestinationChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Destination = aircraftSnapshot.Destination;
                    }
                    if (firstTimeSeen || aircraftSnapshot.EnginePlacementChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.EnginePlacement = (int)aircraftSnapshot.EnginePlacement;
                    }
                    if (firstTimeSeen || aircraftSnapshot.EngineTypeChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.EngineType = (int)aircraftSnapshot.EngineType;
                    }
                    if (firstTimeSeen || aircraftSnapshot.FirstSeenChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.FirstSeen = aircraftSnapshot.FirstSeen;
                    }
                    if (firstTimeSeen || aircraftSnapshot.FlightsCountChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.FlightsCount = aircraftSnapshot.FlightsCount;
                    }
                    if (firstTimeSeen || aircraftSnapshot.Icao24CountryChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Icao24Country = aircraftSnapshot.Icao24Country;
                    }
                    if (firstTimeSeen || aircraftSnapshot.Icao24InvalidChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Icao24Invalid = aircraftSnapshot.Icao24Invalid;
                    }
                    if (firstTimeSeen || aircraftSnapshot.IsInterestingChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.IsInteresting = aircraftSnapshot.IsInteresting;
                    }
                    if (firstTimeSeen || aircraftSnapshot.IsMilitaryChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.IsMilitary = aircraftSnapshot.IsMilitary;
                    }
                    if (firstTimeSeen || aircraftSnapshot.ManufacturerChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Manufacturer = aircraftSnapshot.Manufacturer;
                    }
                    if (firstTimeSeen || aircraftSnapshot.ModelChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Model = aircraftSnapshot.Model;
                    }
                    if (firstTimeSeen || aircraftSnapshot.NumberOfEnginesChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.NumberOfEngines = aircraftSnapshot.NumberOfEngines;
                    }
                    if (firstTimeSeen || aircraftSnapshot.OperatorChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Operator = aircraftSnapshot.Operator;
                    }
                    if (firstTimeSeen || aircraftSnapshot.OperatorIcaoChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.OperatorIcao = aircraftSnapshot.OperatorIcao;
                    }
                    if (firstTimeSeen || aircraftSnapshot.OriginChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Origin = aircraftSnapshot.Origin;
                    }
                    if (firstTimeSeen || aircraftSnapshot.PictureFileNameChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.HasPicture = !String.IsNullOrEmpty(aircraftSnapshot.PictureFileName);
                    }
                    if (firstTimeSeen || aircraftSnapshot.PictureHeightChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.PictureHeight = aircraftSnapshot.PictureHeight == 0 ? (int?)null : aircraftSnapshot.PictureHeight;
                    }
                    if (firstTimeSeen || aircraftSnapshot.PictureWidthChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.PictureWidth = aircraftSnapshot.PictureWidth == 0 ? (int?)null : aircraftSnapshot.PictureWidth;
                    }
                    if (firstTimeSeen || aircraftSnapshot.PositionTimeChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.PositionTime = aircraftSnapshot.PositionTime == null ? (long?)null : JavascriptHelper.ToJavascriptTicks(aircraftSnapshot.PositionTime.Value);
                    }
                    if (firstTimeSeen || aircraftSnapshot.ReceiverIdChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.ReceiverId = aircraftSnapshot.ReceiverId;
                    }
                    if (firstTimeSeen || aircraftSnapshot.RegistrationChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Registration = aircraftSnapshot.Registration;
                    }
                    if (firstTimeSeen || aircraftSnapshot.SpeciesChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Species = (int)aircraftSnapshot.Species;
                    }
                    if (firstTimeSeen || aircraftSnapshot.TypeChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.Type = aircraftSnapshot.Type;
                    }
                    if (firstTimeSeen || aircraftSnapshot.UserTagChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.UserTag = aircraftSnapshot.UserTag;
                    }
                    if (firstTimeSeen || aircraftSnapshot.WakeTurbulenceCategoryChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.WakeTurbulenceCategory = (int)aircraftSnapshot.WakeTurbulenceCategory;
                    }
                    if (firstTimeSeen || aircraftSnapshot.YearBuiltChanged > args.PreviousDataVersion)
                    {
                        aircraftJson.YearBuilt = aircraftSnapshot.YearBuilt;
                    }

                    if (aircraftSnapshot.Stopovers.Count > 0 && (firstTimeSeen || aircraftSnapshot.StopoversChanged > args.PreviousDataVersion))
                    {
                        aircraftJson.Stopovers = new List <string>();
                        aircraftJson.Stopovers.AddRange(aircraftSnapshot.Stopovers);
                    }

                    aircraftJson.SecondsTracked  = (long)((now - aircraftSnapshot.FirstSeen).TotalSeconds);
                    aircraftJson.PositionIsStale = aircraftSnapshot.LastSatcomUpdate == DateTime.MinValue &&        // Never flag satcom aircraft as having a stale position
                                                   aircraftSnapshot.PositionTime != null &&
                                                   aircraftSnapshot.PositionTime < positionTimeoutThreshold ? true : (bool?)null;
                }

                if (args.TrailType != TrailType.None)
                {
                    var hasTrail     = false;
                    var isShort      = false;
                    var showAltitude = false;
                    var showSpeed    = false;
                    switch (args.TrailType)
                    {
                    case TrailType.Short:           isShort = true; hasTrail = aircraftSnapshot.ShortCoordinates.Count > 0; break;

                    case TrailType.ShortAltitude:   showAltitude = true; aircraftJson.TrailType = "a"; goto case TrailType.Short;

                    case TrailType.ShortSpeed:      showSpeed = true; aircraftJson.TrailType = "s"; goto case TrailType.Short;

                    case TrailType.Full:            hasTrail = aircraftSnapshot.FullCoordinates.Count > 0; break;

                    case TrailType.FullAltitude:    showAltitude = true; aircraftJson.TrailType = "a"; goto case TrailType.Full;

                    case TrailType.FullSpeed:       showSpeed = true; aircraftJson.TrailType = "s"; goto case TrailType.Full;
                    }
                    if (hasTrail)
                    {
                        BuildCoordinatesList(isShort, firstTimeSeen, aircraftJson, aircraftSnapshot, args, showAltitude, showSpeed);
                    }
                }

                aircraftListJson.Aircraft.Add(aircraftJson);
            }
        }
Ejemplo n.º 10
0
        public void AircraftJson_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var aircraftJson = new AircraftJson();

            TestUtilities.TestProperty(aircraftJson, r => r.AirPressureInHg, null, 1.2F);
            TestUtilities.TestProperty(aircraftJson, r => r.Altitude, null, 12);
            TestUtilities.TestProperty(aircraftJson, r => r.AltitudeType, null, 1);
            TestUtilities.TestProperty(aircraftJson, r => r.BearingFromHere, null, 12.3);
            TestUtilities.TestProperty(aircraftJson, r => r.Callsign, null, "ND");
            TestUtilities.TestProperty(aircraftJson, r => r.CallsignIsSuspect, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.ConstructionNumber, null, "Uu");
            TestUtilities.TestProperty(aircraftJson, r => r.Destination, null, "Bb");
            TestUtilities.TestProperty(aircraftJson, r => r.DistanceFromHere, null, 12.45);
            TestUtilities.TestProperty(aircraftJson, r => r.Emergency, null, false);
            TestUtilities.TestProperty(aircraftJson, r => r.EngineType, null, 1);
            TestUtilities.TestProperty(aircraftJson, r => r.EnginePlacement, null, 1);
            TestUtilities.TestProperty(aircraftJson, r => r.FirstSeen, null, DateTime.UtcNow);
            TestUtilities.TestProperty(aircraftJson, r => r.FullCoordinates, null, new List <double?>()
            {
                1.1, 2.2
            });
            TestUtilities.TestProperty(aircraftJson, r => r.GeometricAltitude, null, 1);
            TestUtilities.TestProperty(aircraftJson, r => r.GroundSpeed, null, 12.4f);
            TestUtilities.TestProperty(aircraftJson, r => r.HasPicture, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.HasSignalLevel, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.Icao24, null, "Hh");
            TestUtilities.TestProperty(aircraftJson, r => r.Icao24Country, null, "Jk");
            TestUtilities.TestProperty(aircraftJson, r => r.Icao24Invalid, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.IsMilitary, null, false);
            TestUtilities.TestProperty(aircraftJson, r => r.IsTisb, null, false);
            TestUtilities.TestProperty(aircraftJson, r => r.Latitude, null, 1.234);
            TestUtilities.TestProperty(aircraftJson, r => r.Longitude, null, 1.234);
            TestUtilities.TestProperty(aircraftJson, r => r.Manufacturer, null, "Aa");
            TestUtilities.TestProperty(aircraftJson, r => r.Model, null, "Mm");
            TestUtilities.TestProperty(aircraftJson, r => r.NumberOfEngines, null, "C");
            TestUtilities.TestProperty(aircraftJson, r => r.OnGround, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.Operator, null, "Hj");
            TestUtilities.TestProperty(aircraftJson, r => r.OperatorIcao, null, "Ik");
            TestUtilities.TestProperty(aircraftJson, r => r.Origin, null, "Yh");
            TestUtilities.TestProperty(aircraftJson, r => r.PictureHeight, null, 1203);
            TestUtilities.TestProperty(aircraftJson, r => r.PictureWidth, null, 2048);
            TestUtilities.TestProperty(aircraftJson, r => r.PositionIsStale, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.PositionTime, null, 1234L);
            TestUtilities.TestProperty(aircraftJson, r => r.ReceiverId, null, 9931);
            TestUtilities.TestProperty(aircraftJson, r => r.Registration, null, "Fd");
            TestUtilities.TestProperty(aircraftJson, r => r.ResetTrail, false);
            TestUtilities.TestProperty(aircraftJson, r => r.ShortCoordinates, null, new List <double?>()
            {
                1.1, 2.2
            });
            TestUtilities.TestProperty(aircraftJson, r => r.SignalLevel, null, 123);
            TestUtilities.TestProperty(aircraftJson, r => r.Species, null, 12);
            TestUtilities.TestProperty(aircraftJson, r => r.Squawk, null, "4721");
            TestUtilities.TestProperty(aircraftJson, r => r.Stopovers, null, new List <string>()
            {
                "Hd"
            });
            TestUtilities.TestProperty(aircraftJson, r => r.TargetAltitude, null, 1);
            TestUtilities.TestProperty(aircraftJson, r => r.TargetTrack, null, 12.34F);
            TestUtilities.TestProperty(aircraftJson, r => r.Track, null, 12.34f);
            TestUtilities.TestProperty(aircraftJson, r => r.TrackIsHeading, null, true);
            TestUtilities.TestProperty(aircraftJson, r => r.TrailType, null, "a");
            TestUtilities.TestProperty(aircraftJson, r => r.TransponderType, null, 0);
            TestUtilities.TestProperty(aircraftJson, r => r.Type, null, "B747");
            TestUtilities.TestProperty(aircraftJson, r => r.UniqueId, 0, 12);
            TestUtilities.TestProperty(aircraftJson, r => r.UserNotes, null, "Abc");
            TestUtilities.TestProperty(aircraftJson, r => r.UserTag, null, "Abc");
            TestUtilities.TestProperty(aircraftJson, r => r.VerticalRate, null, -239);
            TestUtilities.TestProperty(aircraftJson, r => r.VerticalRateType, null, 1);
            TestUtilities.TestProperty(aircraftJson, r => r.WakeTurbulenceCategory, null, 7);
            TestUtilities.TestProperty(aircraftJson, r => r.YearBuilt, null, "1999");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Copies the aircraft from the snapshot to the JSON object.
        /// </summary>
        /// <param name="aircraftListJson"></param>
        /// <param name="aircraftListSnapshot"></param>
        /// <param name="args"></param>
        /// <param name="distances"></param>
        private void CopyAircraft(AircraftListJson aircraftListJson, List <IAircraft> aircraftListSnapshot, AircraftListJsonBuilderArgs args, Dictionary <int, double?> distances)
        {
            var now = _Provider.UtcNow;

            foreach (var aircraftSnapshot in aircraftListSnapshot)
            {
                double?distance;
                if (!distances.TryGetValue(aircraftSnapshot.UniqueId, out distance))
                {
                    distance = null;
                }

                var aircraftJson = new AircraftJson()
                {
                    BearingFromHere  = GreatCircleMaths.Bearing(args.BrowserLatitude, args.BrowserLongitude, aircraftSnapshot.Latitude, aircraftSnapshot.Longitude, null, false, true),
                    DistanceFromHere = distance == null ? (double?)null : Math.Round(distance.Value, 2),
                    UniqueId         = aircraftSnapshot.UniqueId,
                };
                if (aircraftJson.BearingFromHere != null)
                {
                    aircraftJson.BearingFromHere = Math.Round(aircraftJson.BearingFromHere.Value, 1);
                }

                bool firstTimeSeen = !args.PreviousAircraft.Contains(aircraftSnapshot.UniqueId);

                if (firstTimeSeen || aircraftSnapshot.AltitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Altitude = aircraftSnapshot.Altitude;
                }
                if (firstTimeSeen || aircraftSnapshot.CallsignChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Callsign = aircraftSnapshot.Callsign;
                }
                if (firstTimeSeen || aircraftSnapshot.CallsignIsSuspectChanged > args.PreviousDataVersion)
                {
                    aircraftJson.CallsignIsSuspect = aircraftSnapshot.CallsignIsSuspect;
                }
                if (firstTimeSeen || aircraftSnapshot.ConstructionNumberChanged > args.PreviousDataVersion)
                {
                    aircraftJson.ConstructionNumber = aircraftSnapshot.ConstructionNumber;
                }
                if (firstTimeSeen || aircraftSnapshot.CountMessagesReceivedChanged > args.PreviousDataVersion)
                {
                    aircraftJson.CountMessagesReceived = aircraftSnapshot.CountMessagesReceived;
                }
                if (firstTimeSeen || aircraftSnapshot.DestinationChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Destination = aircraftSnapshot.Destination;
                }
                if (firstTimeSeen || aircraftSnapshot.GroundSpeedChanged > args.PreviousDataVersion)
                {
                    aircraftJson.GroundSpeed = Round.GroundSpeed(aircraftSnapshot.GroundSpeed);
                }
                if (firstTimeSeen || aircraftSnapshot.EmergencyChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Emergency = aircraftSnapshot.Emergency;
                }
                if (firstTimeSeen || aircraftSnapshot.EngineTypeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.EngineType = (int)aircraftSnapshot.EngineType;
                }
                if (firstTimeSeen || aircraftSnapshot.FirstSeenChanged > args.PreviousDataVersion)
                {
                    aircraftJson.FirstSeen = aircraftSnapshot.FirstSeen;
                }
                if (firstTimeSeen || aircraftSnapshot.FlightsCountChanged > args.PreviousDataVersion)
                {
                    aircraftJson.FlightsCount = aircraftSnapshot.FlightsCount;
                }
                if (firstTimeSeen || aircraftSnapshot.PictureFileNameChanged > args.PreviousDataVersion)
                {
                    aircraftJson.HasPicture = !String.IsNullOrEmpty(aircraftSnapshot.PictureFileName);
                }
                if (firstTimeSeen || aircraftSnapshot.Icao24Changed > args.PreviousDataVersion)
                {
                    aircraftJson.Icao24 = aircraftSnapshot.Icao24;
                }
                if (firstTimeSeen || aircraftSnapshot.Icao24CountryChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Icao24Country = aircraftSnapshot.Icao24Country;
                }
                if (firstTimeSeen || aircraftSnapshot.Icao24InvalidChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Icao24Invalid = aircraftSnapshot.Icao24Invalid;
                }
                if (firstTimeSeen || aircraftSnapshot.IsMilitaryChanged > args.PreviousDataVersion)
                {
                    aircraftJson.IsMilitary = aircraftSnapshot.IsMilitary;
                }
                if (firstTimeSeen || aircraftSnapshot.IsInterestingChanged > args.PreviousDataVersion)
                {
                    aircraftJson.IsInteresting = aircraftSnapshot.IsInteresting;
                }
                if (firstTimeSeen || aircraftSnapshot.LatitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Latitude = Round.Coordinate(aircraftSnapshot.Latitude);
                }
                if (firstTimeSeen || aircraftSnapshot.LongitudeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Longitude = Round.Coordinate(aircraftSnapshot.Longitude);
                }
                if (firstTimeSeen || aircraftSnapshot.ModelChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Model = aircraftSnapshot.Model;
                }
                if (firstTimeSeen || aircraftSnapshot.NumberOfEnginesChanged > args.PreviousDataVersion)
                {
                    aircraftJson.NumberOfEngines = aircraftSnapshot.NumberOfEngines;
                }
                if (firstTimeSeen || aircraftSnapshot.OnGroundChanged > args.PreviousDataVersion)
                {
                    aircraftJson.OnGround = aircraftSnapshot.OnGround;
                }
                if (firstTimeSeen || aircraftSnapshot.OperatorChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Operator = aircraftSnapshot.Operator;
                }
                if (firstTimeSeen || aircraftSnapshot.OperatorIcaoChanged > args.PreviousDataVersion)
                {
                    aircraftJson.OperatorIcao = aircraftSnapshot.OperatorIcao;
                }
                if (firstTimeSeen || aircraftSnapshot.OriginChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Origin = aircraftSnapshot.Origin;
                }
                if (firstTimeSeen || aircraftSnapshot.PositionTimeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.PositionTime = aircraftSnapshot.PositionTime == null ? (long?)null : JavascriptHelper.ToJavascriptTicks(aircraftSnapshot.PositionTime.Value);
                }
                if (firstTimeSeen || aircraftSnapshot.RegistrationChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Registration = aircraftSnapshot.Registration;
                }
                if (firstTimeSeen || aircraftSnapshot.SpeciesChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Species = (int)aircraftSnapshot.Species;
                }
                if (firstTimeSeen || aircraftSnapshot.SpeedTypeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.SpeedType = (int)aircraftSnapshot.SpeedType;
                }
                if (firstTimeSeen || aircraftSnapshot.SquawkChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Squawk = String.Format("{0:0000}", aircraftSnapshot.Squawk);
                }
                if (firstTimeSeen || aircraftSnapshot.TrackChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Track = Round.Track(aircraftSnapshot.Track);
                }
                if (firstTimeSeen || aircraftSnapshot.TypeChanged > args.PreviousDataVersion)
                {
                    aircraftJson.Type = aircraftSnapshot.Type;
                }
                if (firstTimeSeen || aircraftSnapshot.UserTagChanged > args.PreviousDataVersion)
                {
                    aircraftJson.UserTag = aircraftSnapshot.UserTag;
                }
                if (firstTimeSeen || aircraftSnapshot.VerticalRateChanged > args.PreviousDataVersion)
                {
                    aircraftJson.VerticalRate = aircraftSnapshot.VerticalRate;
                }
                if (firstTimeSeen || aircraftSnapshot.WakeTurbulenceCategoryChanged > args.PreviousDataVersion)
                {
                    aircraftJson.WakeTurbulenceCategory = (int)aircraftSnapshot.WakeTurbulenceCategory;
                }

                if (aircraftSnapshot.Stopovers.Count > 0 && (firstTimeSeen || aircraftSnapshot.StopoversChanged > args.PreviousDataVersion))
                {
                    aircraftJson.Stopovers = new List <string>();
                    aircraftJson.Stopovers.AddRange(aircraftSnapshot.Stopovers);
                }

                aircraftJson.SecondsTracked = (long)((now - aircraftSnapshot.FirstSeen).TotalSeconds);

                if (args.ShowShortTrail)
                {
                    if (aircraftSnapshot.ShortCoordinates.Count > 0)
                    {
                        BuildCoordinatesList(true, firstTimeSeen, aircraftJson, aircraftSnapshot, args);
                    }
                }
                else
                {
                    if (aircraftSnapshot.FullCoordinates.Count > 0)
                    {
                        BuildCoordinatesList(false, firstTimeSeen, aircraftJson, aircraftSnapshot, args);
                    }
                }

                aircraftListJson.Aircraft.Add(aircraftJson);
            }
        }