@@ -26,25 +26,23 @@ public class StatisticsAuthor(User user, int count)
2626
2727 public class StatisticsReport
2828 {
29- public static readonly string [ ] WEEKDAYS = [ "SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" ] ;
30-
3129 public int Total { get ; set ; } = 0 ;
32- public List < StatisticsAuthor > Authors { get ; set ; } = new List < StatisticsAuthor > ( ) ;
33- public List < ISeries > Series { get ; set ; } = new List < ISeries > ( ) ;
34- public List < Axis > XAxes { get ; set ; } = new List < Axis > ( ) ;
35- public List < Axis > YAxes { get ; set ; } = new List < Axis > ( ) ;
30+ public List < StatisticsAuthor > Authors { get ; set ; } = new ( ) ;
31+ public List < ISeries > Series { get ; set ; } = new ( ) ;
32+ public List < Axis > XAxes { get ; set ; } = new ( ) ;
33+ public List < Axis > YAxes { get ; set ; } = new ( ) ;
3634 public StatisticsAuthor SelectedAuthor { get => _selectedAuthor ; set => ChangeAuthor ( value ) ; }
3735
3836 public StatisticsReport ( StatisticsMode mode , DateTime start )
3937 {
4038 _mode = mode ;
4139
42- YAxes = [ new Axis ( )
40+ YAxes . Add ( new Axis ( )
4341 {
4442 TextSize = 10 ,
4543 MinLimit = 0 ,
4644 SeparatorsPaint = new SolidColorPaint ( new SKColor ( 0x40808080 ) ) { StrokeThickness = 1 }
47- } ] ;
45+ } ) ;
4846
4947 if ( mode == StatisticsMode . ThisWeek )
5048 {
@@ -72,7 +70,7 @@ public void AddCommit(DateTime time, User author)
7270 {
7371 Total ++ ;
7472
75- var normalized = DateTime . MinValue ;
73+ DateTime normalized ;
7674 if ( _mode == StatisticsMode . ThisWeek || _mode == StatisticsMode . ThisMonth )
7775 normalized = time . Date ;
7876 else
@@ -172,26 +170,27 @@ public void ChangeAuthor(StatisticsAuthor author)
172170 ChangeColor ( _fillColor ) ;
173171 }
174172
175- private StatisticsMode _mode = StatisticsMode . All ;
176- private Dictionary < User , int > _mapUsers = new Dictionary < User , int > ( ) ;
177- private Dictionary < DateTime , int > _mapSamples = new Dictionary < DateTime , int > ( ) ;
178- private Dictionary < User , Dictionary < DateTime , int > > _mapUserSamples = new Dictionary < User , Dictionary < DateTime , int > > ( ) ;
173+ private static readonly string [ ] WEEKDAYS = [ "SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" ] ;
174+ private StatisticsMode _mode ;
175+ private Dictionary < User , int > _mapUsers = new ( ) ;
176+ private Dictionary < DateTime , int > _mapSamples = new ( ) ;
177+ private Dictionary < User , Dictionary < DateTime , int > > _mapUserSamples = new ( ) ;
179178 private StatisticsAuthor _selectedAuthor = null ;
180179 private uint _fillColor = 255 ;
181180 }
182181
183182 public class Statistics
184183 {
185- public StatisticsReport All { get ; set ; }
186- public StatisticsReport Month { get ; set ; }
187- public StatisticsReport Week { get ; set ; }
184+ public StatisticsReport All { get ; }
185+ public StatisticsReport Month { get ; }
186+ public StatisticsReport Week { get ; }
188187
189188 public Statistics ( )
190189 {
191- _today = DateTime . Now . ToLocalTime ( ) . Date ;
192- var weekOffset = ( 7 + ( int ) _today . DayOfWeek - ( int ) CultureInfo . CurrentCulture . DateTimeFormat . FirstDayOfWeek ) % 7 ;
193- _thisWeekStart = _today . AddDays ( - weekOffset ) ;
194- _thisMonthStart = _today . AddDays ( 1 - _today . Day ) ;
190+ var today = DateTime . Now . ToLocalTime ( ) . Date ;
191+ var weekOffset = ( 7 + ( int ) today . DayOfWeek - ( int ) CultureInfo . CurrentCulture . DateTimeFormat . FirstDayOfWeek ) % 7 ;
192+ _thisWeekStart = today . AddDays ( - weekOffset ) ;
193+ _thisMonthStart = today . AddDays ( 1 - today . Day ) ;
195194
196195 All = new StatisticsReport ( StatisticsMode . All , DateTime . MinValue ) ;
197196 Month = new StatisticsReport ( StatisticsMode . ThisMonth , _thisMonthStart ) ;
@@ -200,7 +199,13 @@ public Statistics()
200199
201200 public void AddCommit ( string author , double timestamp )
202201 {
203- var user = User . FindOrAdd ( author ) ;
202+ var emailIdx = author . IndexOf ( '±' , StringComparison . Ordinal ) ;
203+ var email = author . Substring ( emailIdx + 1 ) . ToLower ( CultureInfo . CurrentCulture ) ;
204+ if ( ! _users . TryGetValue ( email , out var user ) )
205+ {
206+ user = User . FindOrAdd ( author ) ;
207+ _users . Add ( email , user ) ;
208+ }
204209
205210 var time = DateTime . UnixEpoch . AddSeconds ( timestamp ) . ToLocalTime ( ) ;
206211 if ( time >= _thisWeekStart )
@@ -214,13 +219,15 @@ public void AddCommit(string author, double timestamp)
214219
215220 public void Complete ( )
216221 {
222+ _users . Clear ( ) ;
223+
217224 All . Complete ( ) ;
218225 Month . Complete ( ) ;
219226 Week . Complete ( ) ;
220227 }
221-
222- private readonly DateTime _today ;
228+
223229 private readonly DateTime _thisMonthStart ;
224230 private readonly DateTime _thisWeekStart ;
231+ private readonly Dictionary < string , User > _users = new ( ) ;
225232 }
226233}
0 commit comments