Exemple #1
0
        }     //public static RemoveProximity()

        public static async Task GenerateProximity()
        {
            var AllKeys = Keys();

            foreach (String FromKey in AllKeys)
            {
                DroneDataProcessor ProximityFromFlight = Flight(FromKey);
                GPSPoint           FromPosition        = ProximityFromFlight.GetPosition();
                int FromFlightID = ProximityFromFlight.GetFlightID();
                foreach (String ToKey in AllKeys)
                {
                    if (FromKey != ToKey)
                    {
                        DroneDataProcessor ProximityToFlight = Flight(ToKey);
                        GPSPoint           ToPosition        = ProximityToFlight.GetPosition();
                        int    ToFlightID = ProximityToFlight.GetFlightID();
                        Double Distance   = GPSCalc.GetDistance(FromPosition, ToPosition);
                        ProximityFromFlight.ProximityAdd(new Proximity {
                            FlightID    = ToFlightID,
                            Lat         = ToPosition.lat,
                            Lng         = ToPosition.lng,
                            Distance    = Distance,
                            DroneName   = ProximityToFlight.GetProperty("DroneName").ToString(),
                            AccountID   = (int)ProximityToFlight.GetProperty("AccountID"),
                            AccountName = ProximityToFlight.GetProperty("AccountName").ToString(),
                            Altitude    = ProximityToFlight.Altitude,
                            PilotID     = ProximityToFlight.PilotID,
                            PilotName   = ProximityToFlight.PilotName
                        });
                        //Console.WriteLine($"From: {FromKey}({FromFlightID}) -> To: {ToKey}({ToFlightID}),  Distance: {Distance}");
                    } //if(FromKey != ToKey)
                }     //foreach (String ToKey in AllKeys)
                await ProximityFromFlight.GenerateProximityAlerts();
            }         //foreach(String FromKey in AllKeys)
        }             //public static void UpdateProximity()
        public bool ProcessDroneData()
        {
            GPSPoint ThisPosition = new GPSPoint((float)_FlightMapData.Latitude, (float)_FlightMapData.Longitude);

            LastUpdatedOn = DateTime.Now;

            if (_LastFlightMapData != null)
            {
                //Fix sudden change in heading
                Double ChangeInHeading = (Double)_LastFlightMapData.Heading - (Double)_FlightMapData.Heading;
                if (ChangeInHeading > 20 || ChangeInHeading < -20)
                {
                    if (_LastFlightMapData.Heading > 340 && _FlightMapData.Heading < 10)
                    {
                        //then we leave it to rotate
                    }
                    else
                    {
                        _FlightMapData.Heading = _LastFlightMapData.Heading + (ChangeInHeading > 0 ? 1 : -1) * 20;
                        if (_FlightMapData.Heading > 360)
                        {
                            _FlightMapData.Heading = _FlightMapData.Heading - 360;
                        }
                        if (_FlightMapData.Heading < 0)
                        {
                            _FlightMapData.Heading = -1 * _FlightMapData.Heading;
                        }
                    }
                }

                if (_FlightMapData.Altitude >= _MinFieldValue || _FlightMapData.Speed >= _MinFieldValue)
                {
                    DateTime StartTime = (DateTime)(_LastFlightMapData.ReadTime);
                    DateTime EndTime   = (DateTime)(_FlightMapData.ReadTime);
                    _TotalFlightTime += (Decimal)Math.Abs(EndTime.Subtract(StartTime).TotalSeconds);

                    //Distance between Last point and this point
                    GPSPoint LastLocation = new GPSPoint((float)_LastFlightMapData.Latitude, (float)_LastFlightMapData.Longitude);
                    _FlightMapData.PointDistance = (Decimal)GPSCalc.GetDistance(ThisPosition, LastLocation);
                    _TotalDistance += (Decimal)_FlightMapData.PointDistance;
                }
            }

            SatelliteSummary.AddTo((Double)_FlightMapData.Satellites);
            SpeedSummary.AddTo((Double)_FlightMapData.Speed);
            AltitudeSummary.AddTo((Double)_FlightMapData.Altitude);

            _FlightMapData.TotalFlightTime = _TotalFlightTime;
            _FlightMapData.Distance        = _TotalDistance;

            _FlightMapData.avg_Altitude   = (Decimal)AltitudeSummary.Avg;
            _FlightMapData.Max_Altitude   = (Decimal)AltitudeSummary.Max;
            _FlightMapData.Min_Altitude   = (Decimal)AltitudeSummary.Min;
            _FlightMapData.Avg_Satellites = (Decimal)SatelliteSummary.Avg;
            _FlightMapData.Max_Satellites = (Decimal)SatelliteSummary.Max;
            _FlightMapData.Min_Satellites = (Decimal)SatelliteSummary.Min;
            _FlightMapData.Avg_Speed      = (Decimal)SpeedSummary.Avg;
            _FlightMapData.Max_Speed      = (Decimal)SpeedSummary.Max;
            _FlightMapData.Min_Speed      = (Decimal)SpeedSummary.Min;


            _DroneFlight.Longitude         = _FlightMapData.Longitude;
            _DroneFlight.Latitude          = _FlightMapData.Latitude;
            _ExtDroneFlight.Altitude       = (Double)_FlightMapData.Altitude;
            _ExtDroneFlight.LastFlightDate = _ReadTime;

            //Save the last point for the reference
            _LastFlightMapData = Cloner <FlightMapData> .Clone(_FlightMapData);

            return(true);
        }