Add aggregate API

This commit is contained in:
2020-07-23 20:36:20 -04:00
parent f8a6c71dd0
commit e810c4a240
4 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ChrisKaczor.HomeMonitor.Weather.Models;
using JetBrains.Annotations;
namespace ChrisKaczor.HomeMonitor.Weather.Service.Models
{
[PublicAPI]
public class ReadingAggregate
{
public decimal Min { get; set; }
public decimal Max { get; set; }
public decimal Average { get; set; }
public ReadingAggregate(IEnumerable<WeatherReading> readings, Func<WeatherReading, decimal> selector, int decimalPlaces)
{
Min = readings.Min(selector);
Max = readings.Max(selector);
Average = readings.Average(selector).Truncate(decimalPlaces);
}
}
}