private void lowestNumberOfTotalTestsMonthly(StackedStringArray givenList, MonthlyCovidStatistics statisticsToWriteTo) { List <string> unformattedDateOfCurrentLowest = new List <string>(); int currentLowestNumberOfTests = int.MaxValue; foreach (List <string> currentList in givenList.getListOfList()) { if (int.Parse(currentList.ElementAt(PositiveIncrease)) + int.Parse(currentList.ElementAt(NegativeIncrease)) < currentLowestNumberOfTests) { unformattedDateOfCurrentLowest.Clear(); unformattedDateOfCurrentLowest.Add(currentList.ElementAt(Date)); currentLowestNumberOfTests = int.Parse(currentList.ElementAt(PositiveIncrease)) + int.Parse(currentList.ElementAt(NegativeIncrease)); } else if (int.Parse(currentList.ElementAt(PositiveIncrease)) + int.Parse(currentList.ElementAt(NegativeIncrease)) < currentLowestNumberOfTests) { unformattedDateOfCurrentLowest.Add(currentList.ElementAt(Date)); } } if (currentLowestNumberOfTests == int.MaxValue) { statisticsToWriteTo.NumberLowestTotalTests = "-1"; } else { statisticsToWriteTo.NumberLowestTotalTests = currentLowestNumberOfTests.ToString(); statisticsToWriteTo.DateLowestTotalTests = unformattedDateOfCurrentLowest; } }
private void iterateThroughEachMonth() { int monthOfFirstTest = this.getMonthValue(this.firstTestDate); for (int currentMonth = monthOfFirstTest; currentMonth <= 12; currentMonth++) { StackedStringArray currentMonthCovidInformationList = new StackedStringArray(); MonthlyCovidStatistics currentMonthlyCovidStatistics = new MonthlyCovidStatistics(currentMonth, 2020); foreach (List <string> currentList in this.getStackedStringList()) { if (int.TryParse(currentList.ElementAt(Date), out _) && this.getMonthValue(currentList.ElementAt(Date)) == currentMonth && int.Parse(currentList.ElementAt(Date)) >= int.Parse(this.firstTestDate)) { currentMonthCovidInformationList.addListToList(currentList); currentMonthlyCovidStatistics.NumberOfDaysContainingData++; } } if (currentMonthlyCovidStatistics.NumberOfDaysContainingData > 0) { this.highestNumberOfPositiveTestsMonthly(currentMonthCovidInformationList, currentMonthlyCovidStatistics); this.lowestNumberOfPositiveTestsMonthly(currentMonthCovidInformationList, currentMonthlyCovidStatistics); this.highestNumberOfTotalTestsMonthly(currentMonthCovidInformationList, currentMonthlyCovidStatistics); this.highestNumberOfTotalTestsMonthly(currentMonthCovidInformationList, currentMonthlyCovidStatistics); this.lowestNumberOfTotalTestsMonthly(currentMonthCovidInformationList, currentMonthlyCovidStatistics); this.averageNumberOfPositiveTestsPerDayMonthly(currentMonthCovidInformationList, currentMonthlyCovidStatistics); this.averageNumberOfTotalTestsPerDayMonthly(currentMonthCovidInformationList, currentMonthlyCovidStatistics); this.theProcessedMonthlyCovidStatisticses.Add(currentMonthlyCovidStatistics); } } }
private string formatMonthlyStatistics() { string outputString = ""; for (int currentMonthIndex = 0; currentMonthIndex < this.theCovidInformation.getNumberOfMonthsInData(); currentMonthIndex++) { MonthlyCovidStatistics currentMonthlyCovidStatistics = this.theCovidInformation.getMonthlyCovidStatistics(currentMonthIndex); outputString += Environment.NewLine + Environment.NewLine + getMonthStringFromInt(currentMonthlyCovidStatistics.Month) + " " + currentMonthlyCovidStatistics.Year + " (" + currentMonthlyCovidStatistics.NumberOfDaysContainingData + " days of data):"; outputString += Environment.NewLine + "Highest number of positive tests: " + thousandsCommaPlacer(currentMonthlyCovidStatistics.NumberHighestPositiveTests) + " occurred on the " + multipleDaysFormat(currentMonthlyCovidStatistics.DateHighestPositiveTests) + "."; outputString += Environment.NewLine + "Lowest number of positive tests: " + thousandsCommaPlacer(currentMonthlyCovidStatistics.NumberLowestPositiveTests) + " occurred on the " + multipleDaysFormat(currentMonthlyCovidStatistics.DateLowestPositiveTests) + "."; outputString += Environment.NewLine + "Highest number of total tests: " + thousandsCommaPlacer(currentMonthlyCovidStatistics.NumberHighestTotalTests) + " occurred on the " + multipleDaysFormat(currentMonthlyCovidStatistics.DateHighestTotalTests) + "."; outputString += Environment.NewLine + "Lowest number of total tests: " + thousandsCommaPlacer(currentMonthlyCovidStatistics.NumberLowestTotalTests) + " occurred on the " + multipleDaysFormat(currentMonthlyCovidStatistics.DateLowestTotalTests) + "."; outputString += Environment.NewLine + "Average number of positive tests: " + thousandsCommaPlacer(currentMonthlyCovidStatistics.NumberAveragePositiveTests); outputString += Environment.NewLine + "Average number of all tests: " + thousandsCommaPlacer(currentMonthlyCovidStatistics.NumberAverageTotalTests); } return(outputString); }
private void averageNumberOfTotalTestsPerDayMonthly(StackedStringArray givenList, MonthlyCovidStatistics statisticsToWriteTo) { int totalNumberOfTotalTests = 0; int numberOfDaysCounted = 0; foreach (List <string> currentList in givenList.getListOfList()) { totalNumberOfTotalTests += int.Parse(currentList.ElementAt(PositiveIncrease)) + int.Parse(currentList.ElementAt(NegativeIncrease)); numberOfDaysCounted++; } if (numberOfDaysCounted == 0) { statisticsToWriteTo.NumberAverageTotalTests = "-1"; } else { double averageNumberOfTotalTests = Convert.ToDouble(totalNumberOfTotalTests) / Convert.ToDouble(numberOfDaysCounted); statisticsToWriteTo.NumberAverageTotalTests = averageNumberOfTotalTests.ToString(CultureInfo.InvariantCulture); } }