コード例 #1
0
        private void createMonthlyBreakdown(WeatherDataCollection daysForReport, StringBuilder report)
        {
            var highestTemp = daysForReport.GetDaysWithHighestTempForEachMonth();
            var lowestTemp  = daysForReport.GetDaysWithLowestTempForEachMonth();
            var averageHigh = daysForReport.GetAverageHighTempForEachMonth();
            var averageLow  = daysForReport.GetAverageLowTempForEachMonth();
            var monthCount  = 1;

            for (var i = 0; i < daysForReport.GroupByMonth().Count; i++)
            {
                while (highestTemp[i][0].Date.Month != monthCount && monthCount < 12)
                {
                    var prevMonthName        = DateTimeFormatInfo.CurrentInfo.GetMonthName(monthCount);
                    var prevMonthYear        = highestTemp[i][0].Date.Year;
                    var prevMonthsDaysOfData = " (0 days of data)";
                    report.Append(prevMonthName + $" {prevMonthYear}" + prevMonthsDaysOfData + Environment.NewLine);
                    report.Append(Environment.NewLine);
                    monthCount++;
                }

                var monthName  = highestTemp[i][0].Date.ToString("MMMM", CultureInfo.InvariantCulture);
                var year       = highestTemp[i][0].Date.Year;
                var daysOfData = $" ({daysForReport.GroupByMonth()[i].Count} days of data)";
                report.Append(monthName + $" {year}" + daysOfData + Environment.NewLine);

                this.formatHighestTempForMonths(highestTemp, i, report);
                this.formatLowestTempForMonths(lowestTemp, i, report);
                report.Append($"Average High: {averageHigh[i]:F}" + Environment.NewLine);
                report.Append($"Average Low: {averageLow[i]:F}" + Environment.NewLine);
                report.Append(Environment.NewLine);
                monthCount++;
            }
        }