@@ -46,10 +46,25 @@ public record OpenSource(ConcurrentDictionary<string, HashSet<string>> Authors,
4646 {
4747 }
4848
49+ public OrderedOpenSource ToOrdered ( ) => new (
50+ ToSortedDictionary ( Authors , static values => values . Order ( StringComparer . Ordinal ) . ToList ( ) ) ,
51+ ToSortedDictionary ( Repositories , static values => values . Order ( StringComparer . Ordinal ) . ToList ( ) ) ,
52+ ToSortedDictionary ( Packages , static values => ToSortedDictionary ( values , static value => value ) ) ) ;
53+
4954 public OpenSourceSummary Summary => summary ??= new ( Totals ) ;
5055
5156 public OpenSourceTotals Totals => totals ??= new ( this ) ;
5257
58+ static SortedDictionary < string , TValue > ToSortedDictionary < TSource , TValue > ( IEnumerable < KeyValuePair < string , TSource > > source , Func < TSource , TValue > valueSelector )
59+ {
60+ var ordered = new SortedDictionary < string , TValue > ( StringComparer . Ordinal ) ;
61+
62+ foreach ( var ( key , value ) in source )
63+ ordered [ key ] = valueSelector ( value ) ;
64+
65+ return ordered ;
66+ }
67+
5368 public class OpenSourceTotals ( OpenSource source )
5469 {
5570 public double Authors => source . Authors . Count ;
@@ -65,6 +80,32 @@ public class OpenSourceSummary(OpenSourceTotals totals)
6580 public string Packages => totals . Packages . ToMetric ( decimals : 1 ) ;
6681 public string Downloads => totals . Downloads . ToMetric ( decimals : 1 ) ;
6782 }
83+
84+ public record OrderedOpenSource ( SortedDictionary < string , List < string > > Authors , SortedDictionary < string , List < string > > Repositories , SortedDictionary < string , SortedDictionary < string , long > > Packages )
85+ {
86+ OrderedOpenSourceSummary ? summary ;
87+ OrderedOpenSourceTotals ? totals ;
88+
89+ public OrderedOpenSourceSummary Summary => summary ??= new ( Totals ) ;
90+
91+ public OrderedOpenSourceTotals Totals => totals ??= new ( this ) ;
92+
93+ public class OrderedOpenSourceTotals ( OrderedOpenSource source )
94+ {
95+ public double Authors => source . Authors . Count ;
96+ public double Repositories => source . Repositories . Count ;
97+ public double Packages => source . Packages . Sum ( x => x . Value . Count ) ;
98+ public double Downloads => source . Packages . Sum ( x => x . Value . Sum ( y => y . Value ) ) ;
99+ }
100+
101+ public class OrderedOpenSourceSummary ( OrderedOpenSourceTotals totals )
102+ {
103+ public string Authors => totals . Authors . ToMetric ( decimals : 1 ) ;
104+ public string Repositories => totals . Repositories . ToMetric ( decimals : 1 ) ;
105+ public string Packages => totals . Packages . ToMetric ( decimals : 1 ) ;
106+ public string Downloads => totals . Downloads . ToMetric ( decimals : 1 ) ;
107+ }
108+ }
68109}
69110
70111public record Rate ( RateLimit General , RateLimit GraphQL ) ;
0 commit comments