Exemplo n.º 1
0
    protected void RefreshData(bool fForceRefresh)
    {
        mfbSearchForm1.Restriction.UserName = User.Identity.Name;
        mfbSearchForm1.Restriction.Refresh();

        if (fForceRefresh || CurrentVisitedAirports == null)
        {
            CurrentVisitedAirports = VisitedAirport.VisitedAirportsForQuery(mfbSearchForm1.Restriction);
        }

        gvAirports.DataSource = CurrentVisitedAirports;
        gvAirports.DataBind();

        IEnumerable <VisitedRegion> d = VisitedAirport.VisitedCountriesAndAdmins(CurrentVisitedAirports);

        rptRegions.DataSource = d;
        rptRegions.DataBind();
        lblNone.Visible = !d.Any();

        mfbGoogleMapManager1.Visible = CurrentVisitedAirports.Length > 0;   //  Avoid excessive map loads.

        AirportList alMatches = new AirportList(CurrentVisitedAirports);

        // get an airport list of the airports
        mfbGoogleMapManager1.Map.SetAirportList(alMatches);

        bool fIncludeRoutes = util.GetIntParam(Request, "path", 0) != 0;

        if (mfbGoogleMapManager1.Map.Options.fShowRoute = fIncludeRoutes)
        {
            List <AirportList> lst = new List <AirportList>();

            DBHelper dbh = new DBHelper(LogbookEntry.QueryCommand(mfbSearchForm1.Restriction, lto: LogbookEntry.LoadTelemetryOption.None));
            dbh.ReadRows((comm) => { }, (dr) =>
            {
                object o       = dr["Route"];
                string szRoute = (string)(o == System.DBNull.Value ? string.Empty : o);

                if (!String.IsNullOrEmpty(szRoute))
                {
                    lst.Add(alMatches.CloneSubset(szRoute));
                }
            });
            mfbGoogleMapManager1.Map.Airports = lst;
        }

        lnkZoomOut.NavigateUrl = mfbGoogleMapManager1.ZoomToFitScript;
        lnkZoomOut.Visible     = (CurrentVisitedAirports.Length > 0);

        lblNumAirports.Text = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.VisitedAirportsNumAirports, CurrentVisitedAirports.Length);
    }
Exemplo n.º 2
0
        public override string CSVFromDataTable(DataTable dt)
        {
            // We ignore the data table passed in - we have our data from Matches, which was initialized in CanParse.

            // Build up the list of CrewTrac objects first; we'll then fill in cross-country time.
            List <CrewTrac> lstCt = new List <CrewTrac>();

            foreach (Match ctMatch in Matches)
            {
                GroupCollection gc = ctMatch.Groups;

                string szEmployees = gc["employees"].Value;
                // replace runs of 2 or more spaces with a tab for better finding boundaries (e.g., multiple employees).
                while (szEmployees.Contains("  "))
                {
                    szEmployees = szEmployees.Replace("  ", "\t");
                }

                MatchCollection mcEmployees = regCrewMember.Matches(szEmployees);

                List <CrewTracEmployee> lst = new List <CrewTracEmployee>();
                foreach (Match empMatch in mcEmployees)
                {
                    GroupCollection gcEmployee = empMatch.Groups;
                    if (!Enum.TryParse <CrewTracEmployee.CrewTracRole>(gcEmployee["pos"].Value, out CrewTracEmployee.CrewTracRole role))
                    {
                        role = CrewTracEmployee.CrewTracRole.CA;
                    }
                    lst.Add(new CrewTracEmployee()
                    {
                        Role = role, Name = gcEmployee["empname"].Value
                    });
                }

                try
                {
                    CrewTrac ct = new CrewTrac()
                    {
                        FlightNumber = String.IsNullOrEmpty(gc["flightnum"].Value) ? 0 : Convert.ToInt32(gc["flightnum"].Value, CultureInfo.CurrentCulture),
                        Date         = Convert.ToDateTime(gc["date"].Value, CultureInfo.CurrentCulture),
                        From         = gc["from"].Value,
                        To           = gc["to"].Value,
                        BlockHours   = gc["block"].Value.DecimalFromHHMM(),
                        Tail         = gc["tail"].Value,
                        Model        = gc["model"].Value,
                        Landings     = String.IsNullOrEmpty(gc["landings"].Value) ? 0 : Convert.ToInt32(gc["landings"].Value, CultureInfo.CurrentCulture),
                        Employees    = lst
                    };
                    lstCt.Add(ct);
                }
                catch (Exception ex) when(ex is FormatException)
                {
                }
            }

            // Build up a list of airports so that we can determine cross-country time.
            StringBuilder sbRoutes = new StringBuilder();

            foreach (CrewTrac ct in lstCt)
            {
                sbRoutes.AppendFormat(CultureInfo.CurrentCulture, " {0} {1}", ct.From, ct.To);
            }
            AirportList alRoutes = new AirportList(sbRoutes.ToString());

            foreach (CrewTrac ct in lstCt)
            {
                AirportList alFlight = alRoutes.CloneSubset(ct.From + " " + ct.To);
                if (alFlight.MaxDistanceForRoute() > 50.0)
                {
                    ct.CrossCountry = ct.BlockHours;
                }
            }

            using (DataTable dtDst = new DataTable())
            {
                dtDst.Locale = CultureInfo.CurrentCulture;
                CSVImporter.InitializeDataTable(dtDst);
                foreach (CrewTrac ct in lstCt)
                {
                    CSVImporter.WriteEntryToDataTable(ct.ToLogbookEntry(), dtDst);
                }
                return(CsvWriter.WriteToString(dtDst, true, true));
            }
        }
Exemplo n.º 3
0
        // Handle the slower queries.  Spawns a new thread; don't bother waiting for result.
        private void RefreshSlowData()
        {
            m_lstAirports.Clear();

            HashSet <string> hsAirportCodes = new HashSet <string>();
            HashSet <string> hsCountries    = new HashSet <string>();
            Dictionary <string, AirportStats> dictVisited = new Dictionary <string, AirportStats>();

            new Thread(() =>
            {
                Refresh30DayPublicFlights();
                RefreshUserCounts();
                RefreshAircraftAndModels();

                // Get all of the airports recorded for the last 30 days
                DBHelper dbh = new DBHelper(@"SELECT 
    f.route,
    f.username,
    ac.tailnumber,
    CONCAT(man.manufacturer,
            ' ',
            IF(m.typename = '',
                IF(m.family = '', m.model, m.family),
                m.typename)) AS family
FROM
    flights f
        INNER JOIN
    aircraft ac ON f.idaircraft = ac.idaircraft
        INNER JOIN
    models m ON ac.idmodel = m.idmodel
        INNER JOIN
    manufacturers man ON m.idmanufacturer = man.idmanufacturer
WHERE f.Date > ?dateMin AND f.Date < ?dateMax AND ac.InstanceType = 1");
                dbh.ReadRows((comm) =>
                {
                    comm.Parameters.AddWithValue("dateMin", DateTime.Now.AddDays(-MaxDays));
                    comm.Parameters.AddWithValue("dateMax", DateTime.Now.AddDays(1));
                },
                             (dr) =>
                {
                    foreach (string szCode in airport.SplitCodes(util.ReadNullableString(dr, "route").ToUpperInvariant()))
                    {
                        hsAirportCodes.Add(szCode);
                    }
                });

                // OK, now we have all of the airport codes - get the actual airports
                AirportList alMaster = new AirportList(String.Join(" ", hsAirportCodes));

                foreach (airport ap in alMaster.GetAirportList())
                {
                    if (!ap.IsPort)
                    {
                        continue;
                    }

                    dictVisited[ap.GeoHashKey] = new AirportStats(ap);

                    if (!String.IsNullOrWhiteSpace(ap.Country))
                    {
                        hsCountries.Add(ap.Country);
                    }
                }

                CountriesVisited = hsCountries.Count;

                // Now go through the flights a 2nd time and find longest route and the furthest route.
                dbh.ReadRows((comm) =>
                {
                    comm.Parameters.AddWithValue("dateMin", DateTime.Now.AddDays(-MaxDays));
                    comm.Parameters.AddWithValue("dateMax", DateTime.Now.AddDays(1));
                },
                             (dr) =>
                {
                    string szRoute  = util.ReadNullableString(dr, "route").ToUpperInvariant();
                    string szUser   = util.ReadNullableString(dr, "username");
                    string szTail   = util.ReadNullableString(dr, "tailnumber");
                    string szFamily = util.ReadNullableString(dr, "family");

                    AirportList al = alMaster.CloneSubset(szRoute, true);

                    foreach (airport ap in al.UniqueAirports)
                    {
                        if (dictVisited.ContainsKey(ap.GeoHashKey))
                        {
                            dictVisited[ap.GeoHashKey].Visit(szUser, szFamily, szTail);
                        }
                    }
                });

                m_lstAirports.Clear();
                m_lstAirports.AddRange(dictVisited.Values);

                // Sort the list by number of visits, descending, and remove anything that never matched to an airport.
                m_lstAirports.Sort((ap1, ap2) => { return(dictVisited[ap2.GeoHashKey].Visits.CompareTo(dictVisited[ap1.GeoHashKey].Visits)); });

                // Popular models
                const string szPopularModels = @"SELECT 
                    man.manufacturer, IF(m.typename='', IF(m.family = '', m.model, m.family), m.typename) AS icao, COUNT(f.idflight) AS num
                FROM
                    flights f
                        INNER JOIN
                    aircraft ac ON f.idaircraft = ac.idaircraft
                        INNER JOIN
                    models m ON ac.idmodel = m.idmodel
                        INNER JOIN
                    manufacturers man ON m.idmanufacturer = man.idmanufacturer
                WHERE
                    f.date > ?dateMin AND f.date <= ?dateMax
                        AND ac.InstanceType = 1
                GROUP BY icao
                ORDER BY num DESC
                LIMIT 30";

                m_lstPopularModels.Clear();
                dbh.CommandText = szPopularModels;
                dbh.ReadRows(
                    (comm) =>
                {
                    comm.Parameters.AddWithValue("dateMin", DateTime.Now.AddDays(-MaxDays));
                    comm.Parameters.AddWithValue("dateMax", DateTime.Now.AddDays(1));
                },
                    (dr) => { m_lstPopularModels.Add(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.DefaultPageRecentStatsModelInfo, dr["manufacturer"], dr["icao"], dr["num"])); });

                HasSlowInformation = true;
            }).Start();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Checks flights for various potential issues
        /// </summary>
        /// <param name="rgle">An enumerable of flights.  MUST BE IN ASCENDING CHRONOLOGICAL ORDER</param>
        /// <param name="options">A bitmask of LintOptions flags</param>
        /// <param name="szUser">The name of the user (necessary to get their aircraft, other preferences</param>
        /// <param name="dtMinDate">Ignore any issues with flights on or before this date</param>
        /// <returns></returns>
        public IEnumerable <FlightWithIssues> CheckFlights(IEnumerable <LogbookEntryBase> rgle, string szUser, UInt32 options, DateTime?dtMinDate = null)
        {
            if (rgle == null)
            {
                throw new ArgumentNullException(nameof(rgle));
            }

            if (szUser == null)
            {
                throw new ArgumentNullException(nameof(szUser));
            }

            if (options == 0)
            {
                return(Array.Empty <FlightWithIssues>());
            }

            List <FlightWithIssues> lstFlights = new List <FlightWithIssues>();

            userAircraft = new UserAircraft(szUser);

            seenCheckrides = new HashSet <int>();

            StringBuilder sb = new StringBuilder();

            foreach (LogbookEntryBase le in rgle)
            {
                sb.AppendFormat(CultureInfo.CurrentCulture, "{0} ", le.Route);
            }
            alMaster = new AirportList(sb.ToString());

            // context for sequential flight issues
            previousFlight  = null;
            dutyStart       = dutyEnd = null;
            flightDutyStart = flightDutyEnd = null;


            foreach (LogbookEntryBase le in rgle)
            {
                currentIssues = new List <FlightIssue>();

                // If the flight has any actual errors, add those first
                if (!String.IsNullOrEmpty(le.ErrorString))
                {
                    currentIssues.Add(new FlightIssue()
                    {
                        IssueDescription = le.ErrorString
                    });
                }

                // ignore deadhead flights
                if (le.CustomProperties.PropertyExistsWithID(CustomPropertyType.KnownProperties.IDPropDeadhead))
                {
                    continue;
                }

                currentAircraft = userAircraft.GetUserAircraftByID(le.AircraftID);

                if (currentAircraft == null)
                {
                    currentIssues.Add(new FlightIssue(LintOptions.MiscIssues, Resources.FlightLint.warningSIMAircraftNotFound));
                    continue;
                }

                currentModel = MakeModel.GetModel(currentAircraft.ModelID);

                currentCatClassID = (le.CatClassOverride == 0 ? currentModel.CategoryClassID : (CategoryClass.CatClassID)le.CatClassOverride);

                if (alMaster != null)
                {
                    alSubset = alMaster.CloneSubset(le.Route);
                }

                if ((options & (UInt32)LintOptions.SimIssues) != 0)
                {
                    CheckSimIssues(le);
                }

                if ((options & (UInt32)LintOptions.IFRIssues) != 0)
                {
                    CheckIFRIssues(le);
                }

                if ((options & (UInt32)LintOptions.AirportIssues) != 0)
                {
                    CheckAirportIssues(le);
                }

                if ((options & (UInt32)LintOptions.XCIssues) != 0)
                {
                    CheckXCIssues(le);
                }

                if ((options & (UInt32)LintOptions.PICSICDualMath) != 0)
                {
                    CheckPICSICDualIssues(le);
                }

                if ((options & (UInt32)LintOptions.TimeIssues) != 0)
                {
                    CheckTimeIssues(le);
                }

                if ((options & (UInt32)LintOptions.DateTimeIssues) != 0)
                {
                    CheckDateTimeIssues(le);
                }

                if ((options & (UInt32)LintOptions.MiscIssues) != 0)
                {
                    CheckMiscIssues(le);
                }

                if (currentIssues.Count > 0 && (dtMinDate == null || (dtMinDate.HasValue && le.Date.CompareTo(dtMinDate.Value) > 0)))
                {
                    lstFlights.Add(new FlightWithIssues(le, currentIssues));
                }

                previousFlight = le;
            }

            return(lstFlights);
        }
Exemplo n.º 5
0
        public override string CSVFromDataTable(DataTable dt)
        {
            // We ignore the data table passed in - we have our data from Matches, which was initialized in CanParse.

            // Build up the list of CrewTrac objects first; we'll then fill in cross-country time.
            List <AAScheduler> lstAA = new List <AAScheduler>();

            foreach (Match aaMatch in Matches)
            {
                GroupCollection gc = aaMatch.Groups;

                try
                {
                    DateTime    dtDep = Convert.ToDateTime(String.Format(CultureInfo.CurrentCulture, "{0} {1}", gc["startdate"].Value, gc["starttime"].Value), CultureInfo.CurrentCulture);
                    DateTime    dtArr = Convert.ToDateTime(String.Format(CultureInfo.CurrentCulture, "{0} {1}", gc["enddate"].Value, gc["endtime"].Value), CultureInfo.CurrentCulture);
                    AAScheduler aas   = new AAScheduler()
                    {
                        ScheduledDeparture = dtDep,
                        ScheduledArrival   = dtArr,
                        BlockTime          = gc["blocktime"].Value.DecimalFromHHMM(),
                        FlightNumber       = gc["flightnum"].Value,
                        Deadhead           = !String.IsNullOrEmpty(gc["deadhead"].Value),
                        From     = gc["from"].Value,
                        To       = gc["to"].Value,
                        Sequence = gc["seq"].Value,
                        Leg      = String.IsNullOrEmpty(gc["leg"].Value) ? 0 : Convert.ToInt32(gc["leg"].Value, CultureInfo.CurrentCulture)
                    };
                    lstAA.Add(aas);
                }
                catch (Exception ex) when(ex is FormatException)
                {
                }

                // Build up a list of airports so that we can determine cross-country time.
                StringBuilder sbRoutes = new StringBuilder();
                foreach (AAScheduler aas in lstAA)
                {
                    sbRoutes.AppendFormat(CultureInfo.CurrentCulture, " {0} {1}", aas.From, aas.To);
                }
                AirportList alRoutes = new AirportList(sbRoutes.ToString());

                foreach (AAScheduler aas in lstAA)
                {
                    AirportList alFlight = alRoutes.CloneSubset(aas.From + " " + aas.To);
                    if (alFlight.MaxDistanceForRoute() > 50.0)
                    {
                        aas.CrossCountry = aas.BlockTime;
                    }
                }
            }

            using (DataTable dtDst = new DataTable())
            {
                dtDst.Locale = CultureInfo.CurrentCulture;
                CSVImporter.InitializeDataTable(dtDst);
                foreach (AAScheduler aa in lstAA)
                {
                    CSVImporter.WriteEntryToDataTable(aa.ToLogbookEntry(), dtDst);
                }
                return(CsvWriter.WriteToString(dtDst, true, true));
            }
        }