Ejemplo n.º 1
0
        /// <summary>
        /// Determine the groups for the <paramref name="vehicleNumber"/> then increase
        /// the totals.
        /// </summary>
        /// <param name="vehicleNumber">current vehicle number</param>
        /// <param name="groups">group details</param>
        /// <param name="classTotals">class total array</param>
        private static void UpdateClassTotals(
            string vehicleNumber,
            List <GroupsType> groups,
            ReportCounterManager <YearCounter> classTotals,
            int month)
        {
            if (vehicleNumber == string.Empty)
            {
                return;
            }

            List <string> classIds =
                ClassReportFactory.GetClassAndFamilies(
                    groups,
                    vehicleNumber);

            if (classIds == null || classIds.Count == 0)
            {
                return;
            }

            foreach (string classId in classIds)
            {
                classTotals.AddOne(classId, month);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Loops through all month files in a year directory and analyses
        ///     each journey. It works out the class of each number in the
        ///     journey and updates the relevant arrays.
        ///   If singleCls is set then it is measuring all journeys for the
        ///     specified cls argument. If not set then it is measuring each
        ///     cls and counting examples per month.
        /// </summary>
        /// <param name="classTotals">class counter for the current search</param>
        /// <param name="year">year to update</param>
        /// <param name="cls">cls name</param>
        /// <returns name="success">is successful</returns>
        private static void UpdateClassesForYear(
            ReportCounterManager <ClassCounter> classTotals,
            List <GroupsType> groups,
            string year)
        {
            int yearInteger = 0;

            // Convert year string to an integer
            if (!int.TryParse(year, out yearInteger))
            {
                Logger.Instance.WriteLog("ReportBuilder: Can't convert year " + year);
                return;
            }

            for (int month = 1; month <= 12; ++month)
            {
                List <IJourneyDetailsType> journeysList =
                    DailyInputFactory.LoadMonth(
                        yearInteger,
                        month);

                foreach (IJourneyDetailsType currentJourneyDetails in journeysList)
                {
                    // Update the class totals for each unit in the journey.
                    foreach (string unit in currentJourneyDetails.Units)
                    {
                        ClassReportFactory.UpdateClassTotals(
                            unit,
                            groups,
                            classTotals);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Run a cls report based on the year. It counts the number of
        ///     each cls for each month in the given year.
        /// </summary>
        /// <param name="year">current year</param>
        /// <param name="fullList">fullList</param>
        /// <returns>is successful</returns>
        public static ReportCounterManager <YearCounter> RunYearReportForAllCls(
            IGroupsAndClassesIOController groupsAndClassesIoController,
            string year,
            bool fullList)
        {
            ReportCounterManager <YearCounter> classTotals =
                new ReportCounterManager <YearCounter>();

            List <GroupsType> groupsList =
                groupsAndClassesIoController.LoadFile();

            foreach (GroupsType group in groupsList)
            {
                classTotals.AddNewCounter(new YearCounter(group.Name));
            }

            //string writeName = $"ClsReport_{year}_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv";
            //string faultMessage = $"ReportBuilder: Failed to write Annual Cls Report for {year}.";

            ClassReportFactory.UpdateClassesForYear(
                classTotals,
                groupsList,
                year);

            if (!fullList)
            {
                classTotals.RemoveEmptyClasses();
            }

            return(classTotals);

            //classTotals.WriteCSVFile(
            //  writeName,
            //  faultMessage);
        }
Ejemplo n.º 4
0
        /// ---------- ---------- ---------- ---------- ---------- ----------
        /// <name>updateArraysBasedOnCls</name>
        /// <date>15/09/13</date>
        /// <summary>
        ///   If singleCls is set then use the currentJourney to update all
        ///    location arrays. If not set then update the cls array for the
        ///    current month.
        /// </summary>
        /// <param name="classId">class id</param>
        /// <param name="cls">cls name</param>
        /// <param name="currentJourneyDetails">current journey details</param>
        /// <param name="month">month to update</param>
        /// ---------- ---------- ---------- ---------- ---------- ----------
        private static void UpdateArraysBasedOnCls(
            string vehicleNumber,
            List <GroupsType> groups,
            ReportCounterManager <LocationCounter> locations,
            IJourneyDetailsType currentJourneyDetails,
            string cls)
        {
            if (vehicleNumber == string.Empty)
            {
                return;
            }

            List <string> classIds =
                ClassReportFactory.GetClassAndFamilies(
                    groups,
                    vehicleNumber);

            foreach (string classId in classIds)
            {
                if (classId == cls)
                {
                    locations.AddOne(
                        currentJourneyDetails.To,
                        currentJourneyDetails.From);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Run a general class report.
        /// This provides the count for each class across all records.
        /// </summary>
        /// <param name="fullList">
        /// return a full list of locations or just none zero ones.
        /// </param>
        /// <returns>success flag</returns>
        public static ReportCounterManager <ClassCounter> RunGeneralReportForAllCls(
            IGroupsAndClassesIOController groupsAndClassesIoController,
            bool fullList)
        {
            // Set up paths.
            string basePath =
                BasePathReader.GetBasePath();

            string[] dirNamesArray =
                System.IO.Directory.GetDirectories(
                    $"{basePath}{StaticResources.baPath}");

            // Load the groups and set up the report class with an entry for each group.
            List <GroupsType> groupsList =
                groupsAndClassesIoController.LoadFile();

            ReportCounterManager <ClassCounter> classTotals =
                new ReportCounterManager <ClassCounter>();

            foreach (GroupsType group in groupsList)
            {
                classTotals.AddNewCounter(
                    new ClassCounter(
                        group.Name));
            }

            // Loop through all paths.
            for (int directoryIndex = 0; directoryIndex < dirNamesArray.Count(); ++directoryIndex)
            {
                // get directory name from the path and convert it into it's integer value.
                string dirName =
                    dirNamesArray[directoryIndex].Substring(
                        dirNamesArray[directoryIndex].LastIndexOf('\\') + 1);
                ClassReportFactory.UpdateClassesForYear(
                    classTotals,
                    groupsList,
                    dirName);
            }

            if (!fullList)
            {
                classTotals.RemoveEmptyClasses();
            }

            return(classTotals);

            //classTotals.WriteCSVFile(
            //  $"ClsReport_Gen_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv",
            //  "ReportBuilder: Failed to write General Cls Report.");
        }
Ejemplo n.º 6
0
        /// ---------- ---------- ---------- ---------- ---------- ----------
        /// <name>getClass</name>
        /// <date>15/09/13</date>
        /// <summary>
        ///   Works out the cls based on the input string. If purely a
        ///     number it tries to work out what cls the number refers to,
        ///     otherwise it works out which cls the first letter
        ///     corresponds to.
        /// </summary>
        /// <param name="unitNumber">input string</param>
        /// <returns>class name</returns>
        /// ---------- ---------- ---------- ---------- ---------- ----------
        private static List <string> GetClassAndFamilies(
            List <GroupsType> groups,
            string unitNumber)
        {
            List <string> myclass = new List <string>();
            int           number  = 0;
            string        alpha   = string.Empty;

            if (unitNumber == string.Empty)
            {
                return(myclass);
            }
            else
            {
                if (int.TryParse(unitNumber, out number))
                {
                    return(ClassReportFactory.GetGetClassesWithNumber(number, groups));
                }
                else
                {
                    return(ClassReportFactory.GetClassesWithAlpha(unitNumber, groups));
                }
            }
        }
Ejemplo n.º 7
0
        /// ---------- ---------- ---------- ---------- ---------- ----------
        /// <name>runYearReportForSingleCls</name>
        /// <date>15/09/13</date>
        /// <summary>
        ///   Run a report based on a cls. It counts all the locations for
        ///     the cls across all records.
        /// </summary>
        /// <param name="cls">cls name</param>
        /// <param name="fullList">full list of locations</param>
        /// <returns>is successful</returns>
        /// ---------- ---------- ---------- ---------- ---------- ----------
        public static ReportCounterManager <LocationCounter> RunReportForASingleClass(
            IGroupsAndClassesIOController groupsAndClassesIoController,
            string cls,
            bool fullList,
            string year = "")
        {
            string faultMessage;
            string writeName;

            // Set up paths.
            string basePath =
                BasePathReader.GetBasePath();

            ReportCounterManager <LocationCounter> locationTotals =
                new ReportCounterManager <LocationCounter>();

            List <FirstExampleType> firstExampleList =
                Stats.FirstExampleIOController.GetInstance().GetFirstExampleListLocation();

            firstExampleList = firstExampleList.OrderBy(loc => loc.Item).ToList();

            foreach (FirstExampleType location in firstExampleList)
            {
                locationTotals.AddNewCounter(
                    new LocationCounter(
                        location.Item));
            }

            if (string.IsNullOrEmpty(year))
            {
                //writeName = $"{cls}_Report_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv";
                //faultMessage = "ReportBuilder: Failed to write General Cls Report.";

                string[] dirNamesArray =
                    System.IO.Directory.GetDirectories(
                        $"{basePath}{StaticResources.baPath}");

                // Loop through all paths.
                for (int directoryIndex = 0; directoryIndex < dirNamesArray.Count(); ++directoryIndex)
                {
                    // get directory name from the path and convert it into it's integer value.
                    string dirName =
                        dirNamesArray[directoryIndex].Substring(
                            dirNamesArray[directoryIndex].LastIndexOf('\\') + 1);
                    ClassReportFactory.UpdateLocationsForYear(
                        groupsAndClassesIoController,
                        dirName,
                        locationTotals,
                        cls);
                }
            }
            else
            {
                //writeName = $"{cls}_Report_{year}_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv";
                //faultMessage = $"ReportBuilder: Failed to write Single Year {year} Cls Report.";

                ClassReportFactory.UpdateLocationsForYear(
                    groupsAndClassesIoController,
                    year,
                    locationTotals,
                    cls);
            }

            if (!fullList)
            {
                locationTotals.RemoveEmptyClasses();
            }

            return(locationTotals);

            //locationTotals.WriteCSVFile(
            //  writeName,
            //  faultMessage);
        }