/// <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); } }
/// <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); } } } }
/// ---------- ---------- ---------- ---------- ---------- ---------- /// <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); } } }
/// <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); }
/// <summary> /// Run a report based on a stn. It counts the number of other /// stns visited from the given stn across all records. /// </summary> /// <param name="stn">stn name</param> /// <param name="fullList">full list of locations</param> /// <returns>is successful</returns> public static ReportCounterManager <LocationCounter> RunSingleStnGeneralReport( string stn, bool fullList) { string[] dirNamesArray = System.IO.Directory.GetDirectories( BasePathReader.GetBasePath() + StaticResources.baPath); ReportCounterManager <LocationCounter> locationTotals = LocationReportFactory.CreateLocations(); for (int i = 0; i < dirNamesArray.Count(); ++i) { // get directory name from the path and convert it into it's integer value. string dirName = dirNamesArray[i].Substring(dirNamesArray[i].LastIndexOf('\\') + 1); LocationReportFactory.UpdateStnsForYear( locationTotals, dirName, stn); } if (!fullList) { locationTotals.RemoveEmptyClasses(); } return(locationTotals); //string writeName = $"{stn}_Report_Gen_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv"; //string faultMessage = $"ReportBuilder: ReportBuilder: Failed to write General Stn Report for {stn}."; //locationTotals.WriteCSVFile( // writeName, // faultMessage); }
/// <summary> /// Run a stn report. It counts the number of occurrences of each /// stn in the given year. /// </summary> /// <param name="year">chosen year</param> /// <param name="fullList">fullList</param> /// <returns>success flag</returns> public static ReportCounterManager <LocationCounter> RunStnAnnualReport( string year, bool fullList) { ReportCounterManager <LocationCounter> locationTotals = LocationReportFactory.CreateLocations(); LocationReportFactory.UpdateStnsForYear( locationTotals, year); if (!fullList) { locationTotals.RemoveEmptyClasses(); } return(locationTotals); //string writeName = $"StnReport_{year}_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv"; //string faultMessage = $"ReportBuilder: ReportBuilder: Failed to write Annual Stn Report for {year}."; //locationTotals.WriteCSVFile( // writeName, // faultMessage); }
/// <summary> /// Run a stn report. It counts the number of occurrences of each /// stn across all records. /// </summary> /// <returns>is successful</returns> public static ReportCounterManager <LocationCounter> RunStnGeneralReport() { string[] dirNamesArray = System.IO.Directory.GetDirectories( $"{BasePathReader.GetBasePath()}{StaticResources.baPath}"); ReportCounterManager <LocationCounter> locationTotals = LocationReportFactory.CreateLocations(); for (int index = 0; index < dirNamesArray.Count(); ++index) { // get directory name from the path and convert it into it's integer value. string dirName = dirNamesArray[index].Substring( dirNamesArray[index].LastIndexOf('\\') + 1); LocationReportFactory.UpdateStnsForYear( locationTotals, dirName); } return(locationTotals); //locationTotals.WriteCSVFile( // $"StnReport_Gen_{DateTime.Now.ToString(ReportFactoryCommon.DatePattern)}.csv", // "ReportBuilder: Failed to write General Stn Report."); }
/// <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."); }
/// <summary> /// Takes a stn and a journey, if the stn and the journey to stn /// match then increase the toLocation arrays. Similar for the /// from stn. /// </summary> /// <param name="stn">stn name</param> /// <param name="currentJourneyDetails">current jny details</param> private static void UpdateArraysForSingleStn( ReportCounterManager <LocationCounter> locations, string stn, IJourneyDetailsType currentJourneyDetails) { if (currentJourneyDetails.To == stn) { locations.AddFrom(currentJourneyDetails.From); } else if (currentJourneyDetails.From == stn) { locations.AddTo(currentJourneyDetails.To); } }
/// ---------- ---------- ---------- ---------- ---------- ---------- /// <name>updateClassesForYear</name> /// <date>15/09/13</date> /// <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="year">year to update</param> /// <param name="singleCls">single cls</param> /// <param name="cls">cls name</param> /// <returns name="success">is successful</returns> /// ---------- ---------- ---------- ---------- ---------- ---------- public static void UpdateLocationsForYear( IGroupsAndClassesIOController groupsAndClassesIoController, string year, ReportCounterManager <LocationCounter> locations, string cls) { // Load the groups and set up the report class with an entry for each group. List <GroupsType> groups = groupsAndClassesIoController.LoadFile(); 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; } // loop through months for (int month = 1; month <= 12; ++month) { List <IJourneyDetailsType> journeysList = DailyInputFactory.LoadMonth( yearInteger, month); // loop through everything in the month //foreach (string currentJourney in journeysList) foreach (IJourneyDetailsType currentJourneyDetails in journeysList) { foreach (string unit in currentJourneyDetails.Units) { UpdateArraysBasedOnCls( unit, groups, locations, currentJourneyDetails, cls); } } } }
/// <summary> /// /// </summary> /// <returns></returns> private static ReportCounterManager <LocationCounter> CreateLocations() { 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)); } return(locationTotals); }
/// <summary> /// Loops through all month files in a year directory and analyses /// each journey. It updates the relevant arrays. /// If singleStn is set then it is measuring all journeys for the /// specified stn argument. If not set then it is counting all /// stns. /// </summary> /// <param name="year">year to update</param> /// <param name="singleStn">single stn flag</param> /// <param name="stn">stn name</param> /// <returns name="success">success flag</returns> private static void UpdateStnsForYear( ReportCounterManager <LocationCounter> locations, string year, string stn = "") { int yearInteger = 0; string monthNumber = string.Empty; // Convert year into 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) { if (string.IsNullOrEmpty(stn)) { locations.AddOne( currentJourneyDetails.To, currentJourneyDetails.From); } else { LocationReportFactory.UpdateArraysForSingleStn( locations, stn, currentJourneyDetails); } } } }
/// ---------- ---------- ---------- ---------- ---------- ---------- /// <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); }