| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="StatisticsExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using MyNet.Observable.Collections; |
| | | 9 | | using MyNet.Observable.Collections.Statistics; |
| | | 10 | | |
| | | 11 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 12 | | namespace MyNet.Observable; |
| | | 13 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Creates reactive statistics over an <see cref="ExtendedCollection{T}"/> filtered view. |
| | | 17 | | /// </summary> |
| | | 18 | | public static class StatisticsExtensions |
| | | 19 | | { |
| | | 20 | | extension<T>(ExtendedCollection<T> collection) |
| | | 21 | | where T : notnull |
| | | 22 | | { |
| | | 23 | | /// <summary> |
| | | 24 | | /// Tracks view metrics and numeric aggregates (sum, average, min, max) over the filtered view. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="valueSelector">Selects the numeric value for each item.</param> |
| | | 27 | | public CollectionStatistics<T, double> Statistics(Func<T, double> valueSelector) => |
| | 12 | 28 | | CollectionStatistics<T, double>.ForDouble(collection, valueSelector); |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Tracks view metrics and <see cref="TimeSpan"/> aggregates over the filtered view. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <param name="valueSelector">Selects the duration for each item.</param> |
| | | 34 | | public CollectionStatistics<T, TimeSpan> Statistics(Func<T, TimeSpan> valueSelector) => |
| | 3 | 35 | | CollectionStatistics<T, TimeSpan>.ForTimeSpan(collection, valueSelector); |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | |