Esempio n. 1
0
        /// <summary>
        /// Returns a list of AirportLists given a route.  "=>" is the separator between routes.  This hits the database exactly once, for efficiency, and excludes duplicates.
        /// </summary>
        /// <param name="rgRoutes">The array of routes.</param>
        /// <param name="aplMaster">The "master" airportlist (contains all of the airports)</param>
        /// <returns>A list of airportlists; each contains at least one airport</returns>
        public static ListsFromRoutesResults ListsFromRoutes(IEnumerable <string> rgRoutes)
        {
            List <AirportList> lst = new List <AirportList>();

            if (rgRoutes == null || !rgRoutes.Any())
            {
                return(new ListsFromRoutesResults(lst, new AirportList(string.Empty)));
            }

            // Create a single "worker" airportlist from which we will create the others.
            AirportList aplMaster = new AirportList(String.Join(" ", rgRoutes.ToArray()));

            Dictionary <string, AirportList> dictRoutes = new Dictionary <string, AirportList>();

            // Now create the resulting airport lists.  Exclude duplicate routes
            foreach (string szRoute in rgRoutes)
            {
                string[] rgApCodeNormal = AirportList.NormalizeAirportList(szRoute);
                string   szRouteKey     = String.Join("", rgApCodeNormal);

                // skip duplicate routes
                if (dictRoutes.ContainsKey(szRouteKey))
                {
                    continue;
                }

                AirportList al = aplMaster.CloneSubset(rgApCodeNormal);
                if (al.m_rgAirports.Count > 0)
                {
                    lst.Add(al);
                    dictRoutes.Add(szRouteKey, al);
                }
            }
            return(new ListsFromRoutesResults(lst, aplMaster));
        }
        public VisitedRoute(string szRoute) : this()
        {
            ListsFromRoutesResults result = AirportList.ListsFromRoutes(szRoute);

            Routes            = result.Result;
            MasterAirportList = result.MasterList;
        }
        /// <summary>
        /// Start the quiz.
        /// </summary>
        /// <param name="szDefaultAirportList">The list of airports to use</param>
        protected void BeginQuiz(IEnumerable <airport> rgAirports)
        {
            mvQuiz.SetActiveView(vwQuestions);

            // Strip any navaids from the list; not an issue for user airports, but an issue for US airports
            m_AirportQuiz.Init(AirportList.RemoveNavaids(rgAirports));
            NextQuestion();
        }
        protected void ShowMap(string szTLA)
        {
            // Create an airportlist object and initialize it with this airport string
            airport ap = new AirportList(szTLA).GetAirportList()[0];

            MfbGoogleMap1.Map.Options.MapCenter         = ap.LatLong;
            MfbGoogleMap1.Map.Options.ZoomFactor        = GMap_ZoomLevels.Airport;
            MfbGoogleMap1.Map.Options.MapType           = GMap_MapType.G_SATELLITE_MAP;
            MfbGoogleMap1.Map.StaticMapAdditionalParams = "style=feature:all|element:labels|visibility:off";
        }
        /// <summary>
        /// Returns a KML respresentation of all of the flights represented by the specified query
        /// </summary>
        /// <param name="fq">The flight query</param>
        /// <param name="s">The stream to which to write</param>
        /// <param name="error">Any error</param>
        /// <param name="lstIDs">The list of specific flight IDs to request</param>
        /// <returns>KML string for the matching flights.</returns>
        public static void AllFlightsAsKML(FlightQuery fq, Stream s, out string error, IEnumerable <int> lstIDs = null)
        {
            if (fq == null)
            {
                throw new ArgumentNullException(nameof(fq));
            }
            if (String.IsNullOrEmpty(fq.UserName) && (lstIDs == null || !lstIDs.Any()))
            {
                throw new MyFlightbookException("Don't get all flights as KML for an empty user!!");
            }

            if (lstIDs != null)
            {
                fq.EnumeratedFlights = lstIDs;
            }

            // Get the master airport list
            AirportList alMaster = AllFlightsAndNavaids(fq);

            using (KMLWriter kw = new KMLWriter(s))
            {
                kw.BeginKML();

                error = LookAtAllFlights(
                    fq,
                    LogbookEntryCore.LoadTelemetryOption.LoadAll,
                    (le) =>
                {
                    if (le.Telemetry.HasPath)
                    {
                        using (FlightData fd = new FlightData())
                        {
                            try
                            {
                                fd.ParseFlightData(le.Telemetry.RawData, le.Telemetry.MetaData);
                                if (fd.HasLatLongInfo)
                                {
                                    kw.AddPath(fd.GetTrajectory(), String.Format(CultureInfo.CurrentCulture, "{0:d} - {1}", le.Date, le.Comment), fd.SpeedFactor);
                                    return;
                                }
                            }
                            catch (Exception ex) when(!(ex is OutOfMemoryException))
                            {
                            }                                                                   // eat any error and fall through below
                        }
                    }
                    // No path was found above.
                    AirportList al = alMaster.CloneSubset(le.Route);
                    kw.AddRoute(al.GetNormalizedAirports(), String.Format(CultureInfo.CurrentCulture, "{0:d} - {1}", le.Date, le.Route));
                },
                    lstIDs != null && lstIDs.Any());
                kw.EndKML();
            }
        }
Esempio n. 6
0
        public void CheckStatus(AirportList al = null)
        {
            if (al == null)
            {
                al = new AirportList(String.Format(CultureInfo.CurrentCulture, "{0} {1} {2}", IATA, ICAO, FAA));
            }

            airport[] rgap = al.GetAirportList();

            MatchStatusFAA  = GetStatus(FAA, rgap, out m_MatchedFAAName, out m_FAAMatch);
            MatchStatusIATA = GetStatus(IATA, rgap, out m_MatchedIATAName, out m_IATAMatch);
            MatchStatusICAO = GetStatus(ICAO, rgap, out m_MatchedICAOName, out m_ICAOMatch);
        }
Esempio n. 7
0
        /// <summary>
        /// Pass in an array of airports and get back the latitude/longitude bounding box of all of the airports
        /// </summary>
        /// <returns>A LatLongBox.</returns>
        public LatLongBox LatLongBox(bool fAirportsOnly = false)
        {
            airport[] rgap = fAirportsOnly ? AirportList.RemoveNavaids(m_rgAirports) : m_rgAirports.ToArray();
            if (rgap.Length == 0)
            {
                return(new LatLongBox(new LatLong(0.0, 0.0)));
            }

            LatLongBox llb = new LatLongBox(((airport)rgap[0]).LatLong);

            foreach (airport ap in rgap)
            {
                llb.ExpandToInclude(ap.LatLong);
            }

            return(llb);
        }
        /// <summary>
        /// Estimates the total distance flown by the user for the subset of flights described by the query
        /// </summary>
        /// <param name="fq">The flight query</param>
        /// <param name="fAutofillDistanceFlown">True to autofill the distance flown property if not found.</param>
        /// <param name="error">Any error</param>
        /// <returns>Distance flown, in nm</returns>
        public static double DistanceFlownByUser(FlightQuery fq, bool fAutofillDistanceFlown, out string error)
        {
            if (fq == null)
            {
                throw new ArgumentNullException(nameof(fq));
            }
            if (String.IsNullOrEmpty(fq.UserName))
            {
                throw new MyFlightbookException("Don't estimate distance for an empty user!!");
            }

            double distance = 0.0;

            // Get the master airport list
            AirportList alMaster = AllFlightsAndNavaids(fq);

            error = LookAtAllFlights(
                fq,
                LogbookEntryCore.LoadTelemetryOption.MetadataOrDB,
                (le) =>
            {
                double distThisFlight = 0;

                // If the trajectory had a distance, use it; otherwise, use airport-to-airport.
                double dPath = le.Telemetry.Distance();
                if (dPath > 0)
                {
                    distThisFlight = dPath;
                }
                else if (!String.IsNullOrEmpty(le.Route))
                {
                    distThisFlight = alMaster.CloneSubset(le.Route).DistanceForRoute();
                }

                distance += distThisFlight;

                if (fAutofillDistanceFlown && distThisFlight > 0 && !le.CustomProperties.PropertyExistsWithID(CustomPropertyType.KnownProperties.IDPropDistanceFlown))
                {
                    le.CustomProperties.Add(CustomFlightProperty.PropertyWithValue(CustomPropertyType.KnownProperties.IDPropDistanceFlown, (decimal)distThisFlight));
                    le.FCommit();
                }
            });

            return(distance);
        }
Esempio n. 9
0
        /// <summary>
        /// Returns a new AirportList that is a subset of the current ones, using airports out of the array of codes (from NormalizeAirportList)
        /// </summary>
        /// <param name="rgApCodeNormal">The array of airport codes (call NormalizeAirportList on a route to get this)</param>
        /// <param name="fPortsOnly">Indicates whether we should ONLY include ports (vs navaids)</param>
        /// <returns>A new airportList object that is the intersection of the source object and the specified codes</returns>
        private AirportList CloneSubset(string[] rgApCodeNormal, bool fPortsOnly = false)
        {
            AirportList al = new AirportList()
            {
                m_rgAirports         = new List <airport>(),
                m_rgszAirportsNormal = rgApCodeNormal
            };

            foreach (string sz in al.m_rgszAirportsNormal)
            {
                airport ap = GetAirportByCode(sz);
                if (ap != null && (ap.IsPort || !fPortsOnly))
                {
                    al.m_htAirportsByCode[sz] = ap;
                    al.m_rgAirports.Add(ap);
                }
            }
            return(al);
        }
Esempio n. 10
0
 public VisitedRoute()
 {
     Routes            = new List <AirportList>();
     MasterAirportList = new AirportList();
     FlownSegments     = new Dictionary <string, FlownSegment>();
 }
Esempio n. 11
0
        private static Dictionary <string, VisitedAirport> PopulateAirports(DBHelperCommandArgs commandArgs)
        {
            Dictionary <string, VisitedAirport> dictVA = new Dictionary <string, VisitedAirport>();

            DBHelper dbh = new DBHelper(commandArgs);

            dbh.ReadRows(
                (comm) => { },
                (dr) =>
            {
                // ignore anything not in a real aircraft.
                AircraftInstanceTypes instanceType = (AircraftInstanceTypes)Convert.ToInt32(dr["InstanceType"], CultureInfo.InvariantCulture);
                if (instanceType != AircraftInstanceTypes.RealAircraft)
                {
                    return;
                }

                DateTime dtFlight = Convert.ToDateTime(dr["date"], CultureInfo.InvariantCulture);
                string szRoute    = dr["route"].ToString();
                int idFlight      = Convert.ToInt32(dr["idflight"], CultureInfo.InvariantCulture);

                decimal total = Convert.ToDecimal(util.ReadNullableField(dr, "totalFlightTime", 0.0M), CultureInfo.InvariantCulture);
                decimal PIC   = Convert.ToDecimal(util.ReadNullableField(dr, "PIC", 0.0M), CultureInfo.InvariantCulture);
                decimal SIC   = Convert.ToDecimal(util.ReadNullableField(dr, "SIC", 0.0M), CultureInfo.InvariantCulture);
                decimal CFI   = Convert.ToDecimal(util.ReadNullableField(dr, "CFI", 0.0M), CultureInfo.InvariantCulture);
                decimal Dual  = Convert.ToDecimal(util.ReadNullableField(dr, "dualReceived", 0.0M), CultureInfo.InvariantCulture);

                // ignore any flight with no time logged.
                if (total + PIC + SIC + CFI + Dual == 0)
                {
                    return;
                }

                // we want to defer any db hit to the airport list until later, so we create an uninitialized airportlist
                // We then visit each airport in the flight.
                string[] rgszapFlight = AirportList.NormalizeAirportList(szRoute);

                for (int iAp = 0; iAp < rgszapFlight.Length; iAp++)
                {
                    string szap = rgszapFlight[iAp].ToUpperInvariant();

                    // If it's explicitly a navaid, ignore it
                    if (szap.StartsWith(airport.ForceNavaidPrefix, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    VisitedAirport va = dictVA.ContainsKey(szap) ? dictVA[szap] : null;

                    // Heuristic: if the flight only has a single airport, we visit that airport
                    // BUT if the flight has multiple airport codes, ignore the first airport in the list
                    // UNLESS we've never seen that airport before.  (E.g., fly commercial to Stockton to pick up 40FG).
                    if (iAp == 0 && va != null && rgszapFlight.Length > 1)
                    {
                        continue;
                    }

                    // for now, the key holds the airport code, since the airport itself within the visited airport is still null
                    if (va == null)
                    {
                        dictVA[szap] = va = new VisitedAirport(dtFlight)
                        {
                            FlightIDOfFirstVisit = idFlight
                        }
                    }
                    ;
                    else
                    {
                        va.VisitAirport(dtFlight, idFlight);
                    }
                }
            });

            return(dictVA);
        }
Esempio n. 12
0
 public ListsFromRoutesResults(IEnumerable <AirportList> result, AirportList master)
 {
     Result     = new List <AirportList>(result);
     MasterList = master;
 }