|
1 | 1 | using System.Collections.Concurrent;
|
2 | 2 | using System.ComponentModel;
|
| 3 | +using System.Security.Cryptography; |
| 4 | +using Humanizer; |
3 | 5 |
|
4 | 6 | namespace Devlooped.Sponsors;
|
5 | 7 |
|
@@ -37,13 +39,26 @@ public record FundedRepository(string OwnerRepo, string[] Sponsorables);
|
37 | 39 |
|
38 | 40 | public record OpenSource(ConcurrentDictionary<string, HashSet<string>> Authors, ConcurrentDictionary<string, HashSet<string>> Repositories, ConcurrentDictionary<string, ConcurrentDictionary<string, long>> Packages)
|
39 | 41 | {
|
40 |
| - public OpenSourceSummary Totals => new(this); |
| 42 | + OpenSourceSummary? summary; |
| 43 | + OpenSourceTotals? totals; |
41 | 44 |
|
42 |
| - public class OpenSourceSummary(OpenSource source) |
| 45 | + public OpenSourceSummary Summary => summary ??= new(Totals); |
| 46 | + |
| 47 | + public OpenSourceTotals Totals => totals ??= new(this); |
| 48 | + |
| 49 | + public class OpenSourceTotals(OpenSource source) |
| 50 | + { |
| 51 | + public double Authors => source.Authors.Count; |
| 52 | + public double Repositories => source.Repositories.Count; |
| 53 | + public double Packages => source.Packages.Sum(x => x.Value.Count); |
| 54 | + public double Downloads => source.Packages.Sum(x => x.Value.Sum(y => y.Value)); |
| 55 | + } |
| 56 | + |
| 57 | + public class OpenSourceSummary(OpenSourceTotals totals) |
43 | 58 | {
|
44 |
| - public long Authors => source.Authors.Count; |
45 |
| - public long Repositories => source.Repositories.Count; |
46 |
| - public long Packages => source.Packages.Sum(x => x.Value.Count); |
47 |
| - public long Downloads => source.Packages.Sum(x => x.Value.Sum(y => y.Value)); |
| 59 | + public string Authors => totals.Authors.ToMetric(decimals: 1); |
| 60 | + public string Repositories => totals.Repositories.ToMetric(decimals: 1); |
| 61 | + public string Packages => totals.Packages.ToMetric(decimals: 1); |
| 62 | + public string Downloads => totals.Packages.ToMetric(decimals: 1); |
48 | 63 | }
|
49 | 64 | }
|
0 commit comments