-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathThroughputDataExtensions.cs
More file actions
44 lines (34 loc) · 1.46 KB
/
ThroughputDataExtensions.cs
File metadata and controls
44 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
namespace Particular.LicensingComponent;
using Contracts;
static class ThroughputDataExtensions
{
public static IEnumerable<EndpointDailyThroughput> FromSource(this List<ThroughputData> throughputs, ThroughputSource source) => throughputs
.Where(td => td.ThroughputSource == source)
.SelectMany(td => td)
.Select(kvp => new EndpointDailyThroughput(kvp.Key, kvp.Value));
public static long Sum(this List<ThroughputData> throughputs) => throughputs.SelectMany(t => t).Sum(kvp => kvp.Value);
public static long MaxDailyThroughput(this List<ThroughputData> throughputs)
{
var items = throughputs.SelectMany(t => t).ToArray();
if (items.Any())
{
return items.Max(kvp => kvp.Value);
}
return 0;
}
public static long MaxMonthlyThroughput(this List<ThroughputData> throughputs)
{
var monthlySums = throughputs
.SelectMany(data => data)
.GroupBy(kvp => $"{kvp.Key.Year}-{kvp.Key.Month}")
.Select(group => group.Sum(kvp => kvp.Value))
.ToArray();
if (monthlySums.Any())
{
return monthlySums.Max();
}
return 0;
}
public static bool HasDataFromSource(this IDictionary<string, IEnumerable<ThroughputData>> throughputPerQueue, ThroughputSource source) =>
throughputPerQueue.Any(queueName => queueName.Value.Any(data => data.ThroughputSource == source && data.Count > 0));
}