public Aggregator(TextListSplitter textListSplitter) { IsAggregatorCalled = true; NoOfRows = textListSplitter.YearList.Count; IndexList = new List <int>(); Average = 0F; IsAggregatorCalled = true; CheckAverageDailyFootfallsInAWeek = false; CheckAverageFootfallsPerHourShownOverADay = false; CheckPeakDailyFootfallInTheLastMonth = false; }
static void Main(string[] args) { Console.WriteLine("For Average footfalls per hour, shown over a day-Enter Day(dd/mm/yyyy)"); Console.WriteLine("For Average daily footfalls in a week-Enter First Day of Week(dd/mm/yyyy)"); Console.WriteLine("For Peak Daily Foot fall In a Given Month Enter Month Year"); ConsoleReader consoleReader = new ConsoleReader(); consoleReader.readDataFromConsole(); TextListSplitter textListSplitter = new TextListSplitter(consoleReader.DataList); Aggregator aggregator = new Aggregator(textListSplitter); aggregator.AverageFootfallsPerHourShownOverADay(textListSplitter, consoleReader.EnteredDateForAverageFootfallsPerHour); aggregator.AverageDailyFootfallsInAWeek(textListSplitter, consoleReader.EnteredDateForAverageDailyFootfallsInAWeek); aggregator.PeakDailyFootfallInTheLastMonth(textListSplitter, consoleReader.MonthAndYear); }
//Average daily footfalls in a week public void AverageDailyFootfallsInAWeek(TextListSplitter textListSplitter, string enteredDate) { enteredDate = enteredDate.Trim(); string[] ddMmYyDate = enteredDate.Split('/'); int day = Int16.Parse(ddMmYyDate[0]); int month = Int16.Parse(ddMmYyDate[1]); int year = Int16.Parse(ddMmYyDate[2]); DateTime currentDate = Convert.ToDateTime(enteredDate); Dictionary <DateTime, int> dayVsCount = new Dictionary <DateTime, int>(); AggregatorSupporter aggregatorSupporter = new AggregatorSupporter(); dayVsCount.Add(currentDate, aggregatorSupporter.GetCountPerDay((int)currentDate.Day, (int)currentDate.Month, (int)currentDate.Year, textListSplitter, NoOfRows)); for (int startDay = 1; startDay <= 6; startDay++) { currentDate = currentDate.AddDays(1); dayVsCount.Add(currentDate, aggregatorSupporter.GetCountPerDay((int)currentDate.Day, (int)currentDate.Month, (int)currentDate.Year, textListSplitter, NoOfRows)); } Console.WriteLine("---------Average daily footfalls in a week---------------"); Console.WriteLine("Given Date : {0}", enteredDate); Console.WriteLine("_____________________________"); Console.WriteLine("Day Count"); Average = 0; //Prinitng to file string contentToBePrinted = ""; contentToBePrinted += "Given Date," + enteredDate + "\n"; contentToBePrinted += "Day,Count\n"; foreach (KeyValuePair <DateTime, int> dayAndFreq in dayVsCount) { Console.WriteLine("{0} {1}", dayAndFreq.Key.ToString("dd/MM/yyyy"), dayAndFreq.Value); Average += (float)dayAndFreq.Value; contentToBePrinted += dayAndFreq.Key.ToString("dd/MM/yyyy") + "," + dayAndFreq.Value + "\n"; } Console.WriteLine("Average FootFall Count : {0}", Average / 7); contentToBePrinted += "Average FootFall Count," + (Average / 7) + "\n"; Console.WriteLine("_____________________________"); CsvFileWriter csvFileWriter = new CsvFileWriter(); csvFileWriter.writeToCsvFile(contentToBePrinted, "AverageDailyFootfallsInAWeek"); CheckAverageDailyFootfallsInAWeek = true; }
//Peak daily footfall in the last month public void PeakDailyFootfallInTheLastMonth(TextListSplitter textListSplitter, string monthYear) { monthYear = monthYear.Trim(); string[] monthNYear = monthYear.Split(' '); int enteredMonth = Int32.Parse(monthNYear[0]); int enteredYear = Int32.Parse(monthNYear[1]); AggregatorSupporter aggregatorSupporter = new AggregatorSupporter(); IndexList = aggregatorSupporter.GetListOfGivenMonthAndYear(enteredMonth, enteredYear, textListSplitter, NoOfRows); //IndexList:which matches with given month and year Console.WriteLine(IndexList.Count); List <int> finalDayList = new List <int>(); for (int index = 0; index < IndexList.Count; index++) { finalDayList.Add(textListSplitter.DayList[IndexList[index]]); } Console.WriteLine("-------Peak Daily Footfall In The Month---------"); Console.WriteLine("Given Month : {0}", enteredMonth); Console.WriteLine("Given Year : {0}", enteredYear); Console.WriteLine("_____________________________"); Console.WriteLine("Day Count"); var valShowFreq = ShowFreq(finalDayList); Console.WriteLine("Average FootFall Count : {0}", Average); Console.WriteLine("Peak FootFall Count : {0}", PeakFootFallInAMonth); Console.WriteLine("_____________________________"); //Prinitng to file string contentToBePrinted = ""; contentToBePrinted += "Given Month," + enteredMonth + "\n"; contentToBePrinted += "Given Year," + enteredYear + "\n"; contentToBePrinted += "Day,Count" + "\n"; contentToBePrinted += valShowFreq; contentToBePrinted += "Average FootFall Count," + Average + "\n"; contentToBePrinted += "Peak FootFall Count," + PeakFootFallInAMonth + "\n"; CsvFileWriter csvFileWriter = new CsvFileWriter(); csvFileWriter.writeToCsvFile(contentToBePrinted, "PeakDailyFootfallInTheLastMonth"); CheckPeakDailyFootfallInTheLastMonth = true; }
public List <int> GetListOfGivenMonthAndYear(int month, int year, TextListSplitter textListSplitter, int noOfRows) { try { List <int> indexList = new List <int>(); for (int index = 0; index < noOfRows; index++) { if (month == textListSplitter.MonthList[index] && year == textListSplitter.YearList[index]) { indexList.Add(index); } } IsGetListOfGivenMonthAndYear = true; return(indexList); } catch (Exception e) { Console.WriteLine(e + " Check AggregatorSupporter-> GetListOfGivenMonthAndYear"); throw; } }
//Average footfalls per hour, shown over a day public void AverageFootfallsPerHourShownOverADay(TextListSplitter textListSplitter, string enteredDate) { enteredDate = enteredDate.Trim(); string[] ddMmYyDate = enteredDate.Split('/'); int day = Int16.Parse(ddMmYyDate[0]); int month = Int16.Parse(ddMmYyDate[1]); int year = Int16.Parse(ddMmYyDate[2]); AggregatorSupporter aggregatorSupporter = new AggregatorSupporter(); IndexList = aggregatorSupporter.GetIndex(day, month, year, textListSplitter, NoOfRows); List <int> finalHourList = new List <int>(); for (int index = 0; index < IndexList.Count; index++) { finalHourList.Add(textListSplitter.HourList[IndexList[index]]); } //printing to console Console.WriteLine("------------Average FootFall Per Hour-----------------"); Console.WriteLine("Given Date : {0}", enteredDate); Console.WriteLine("_____________________________"); Console.WriteLine("Hour Count"); var valueVsFreq = ShowFreq(finalHourList); Console.WriteLine("Average FootFall Count : {0}", Average); Console.WriteLine("_____________________________"); //Prinitng to file string contentToBePrinted = ""; contentToBePrinted += "Given Date," + enteredDate + "\n"; contentToBePrinted += "Hour,Count\n"; contentToBePrinted += valueVsFreq; contentToBePrinted += "Average FootFall Count," + Average + "\n"; CsvFileWriter csvFileWriter = new CsvFileWriter(); csvFileWriter.writeToCsvFile(contentToBePrinted, "AverageFootfallsPerHourShownOverADay"); CheckAverageFootfallsPerHourShownOverADay = true; }
public int GetCountPerDay(int day, int month, int year, TextListSplitter textListSplitter, int noOfRows) { try { int count = 0; for (int index = 0; index < noOfRows; index++) { if (day == textListSplitter.DayList[index] && month == textListSplitter.MonthList[index] && year == textListSplitter.YearList[index]) { count++; } } IsGetCountPerDayWorks = true; return(count); } catch (Exception e) { Console.WriteLine(e + " Check AggregatorSupporter"); throw; } }