private void CalculateWeatherDataFor(IEnumerable <WeatherDataFor> values, WeatherDataFor data) { data.FirstRecordedDate = values.Min(q => q.FirstRecordedDate); data.LastRecordedDate = values.Max(q => q.LastRecordedDate); data.TotalRainfall = values.Sum(q => q.TotalRainfall); data.DaysWithRainfall = values.Sum(q => q.DaysWithRainfall); data.DaysWithNoRainfall = values.Sum(q => q.DaysWithNoRainfall); data.AverageDailyRainfall = data.TotalRainfall / (data.DaysWithRainfall + data.DaysWithNoRainfall); }
private void CalculateWeatherDataFor(IEnumerable <KeyValuePair <DateTime, float?> > values, WeatherDataFor data) { data.FirstRecordedDate = values.Min(q => q.Key); data.LastRecordedDate = values.Max(q => q.Key); data.TotalRainfall = values.Sum(q => q.Value.Value); data.DaysWithRainfall = values.Where(q => q.Value.HasValue && q.Value != 0).Count(); data.DaysWithNoRainfall = values.Where(q => !q.Value.HasValue || q.Value == 0).Count(); data.AverageDailyRainfall = data.TotalRainfall / (data.DaysWithRainfall + data.DaysWithNoRainfall); }