Exemplo n.º 1
0
        public async Task <MonthlyAggregates> GetMonthlyBomDataAsync(string month, string year, IReadOnlyCollection <IBomData> bomFilteredMonthData)
        {
            _logger.LogDebug($"GetMonthlyBomData Invoked For Month {month}, Year {year}");

            var monthlyAggregates = new MonthlyAggregates()
            {
                WeatherDataForMonth = new WeatherDataForMonth
                {
                    Month                = DateTimeHelper.GetMonthName(Convert.ToInt16(month)),
                    FirstRecordedDate    = bomFilteredMonthData.GetFirstRecordedDate(),
                    LastRecordedDate     = bomFilteredMonthData.GetLastRecordedDate(),
                    TotalRainfall        = bomFilteredMonthData.GetTotalRainFall(),
                    AverageDailyRainfall = bomFilteredMonthData.AverageDailyRainFall(),
                    MedianDailyRainfall  = bomFilteredMonthData.GetMedianDailyRainFall(),
                    DaysWithRainfall     = bomFilteredMonthData.GetDaysWithRainfall(),
                    DaysWithNoRainfall   = bomFilteredMonthData.GetDaysWithNoRainfall(),
                }
            };

            return(await Task.FromResult(monthlyAggregates));
        }
        private MonthlyAggregates GetMonthlyAggregates(IEnumerable <WeatherDataModel> wdm)
        {
            var monthlyAggregates = new MonthlyAggregates();

            var weatherDataForMonth = from c in wdm
                                      group c by c.Month
                                      into grouped
                                      select new WeatherDataForMonth
            {
                Month                = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(int.Parse(grouped.Key)),
                FirstRecordedDate    = grouped.Min(c => c.FullDate),
                LastRecordedDate     = grouped.Max(c => c.FullDate),
                TotalRainfall        = grouped.Sum(c => decimal.Parse(c.RainfallAmount)),
                AverageDailyRainfall = Math.Round(grouped.Average(c => decimal.Parse(c.RainfallAmount)), 3),
                DaysWithNoRainfall   = DaysWithNoRainfall(grouped),
                DaysWithRainfall     = DaysWithRainfall(grouped),
                MedianDailyRainfall  = (decimal)FindMedianOfWeatherData(grouped)
            };

            monthlyAggregates.WeatherDataForMonth = weatherDataForMonth;

            return(monthlyAggregates);
        }