@@ -26,25 +26,23 @@ public class StatisticsAuthor(User user, int count)
26
26
27
27
public class StatisticsReport
28
28
{
29
- public static readonly string [ ] WEEKDAYS = [ "SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" ] ;
30
-
31
29
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 ( ) ;
36
34
public StatisticsAuthor SelectedAuthor { get => _selectedAuthor ; set => ChangeAuthor ( value ) ; }
37
35
38
36
public StatisticsReport ( StatisticsMode mode , DateTime start )
39
37
{
40
38
_mode = mode ;
41
39
42
- YAxes = [ new Axis ( )
40
+ YAxes . Add ( new Axis ( )
43
41
{
44
42
TextSize = 10 ,
45
43
MinLimit = 0 ,
46
44
SeparatorsPaint = new SolidColorPaint ( new SKColor ( 0x40808080 ) ) { StrokeThickness = 1 }
47
- } ] ;
45
+ } ) ;
48
46
49
47
if ( mode == StatisticsMode . ThisWeek )
50
48
{
@@ -72,7 +70,7 @@ public void AddCommit(DateTime time, User author)
72
70
{
73
71
Total ++ ;
74
72
75
- var normalized = DateTime . MinValue ;
73
+ DateTime normalized ;
76
74
if ( _mode == StatisticsMode . ThisWeek || _mode == StatisticsMode . ThisMonth )
77
75
normalized = time . Date ;
78
76
else
@@ -172,26 +170,27 @@ public void ChangeAuthor(StatisticsAuthor author)
172
170
ChangeColor ( _fillColor ) ;
173
171
}
174
172
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 ( ) ;
179
178
private StatisticsAuthor _selectedAuthor = null ;
180
179
private uint _fillColor = 255 ;
181
180
}
182
181
183
182
public class Statistics
184
183
{
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 ; }
188
187
189
188
public Statistics ( )
190
189
{
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 ) ;
195
194
196
195
All = new StatisticsReport ( StatisticsMode . All , DateTime . MinValue ) ;
197
196
Month = new StatisticsReport ( StatisticsMode . ThisMonth , _thisMonthStart ) ;
@@ -200,7 +199,13 @@ public Statistics()
200
199
201
200
public void AddCommit ( string author , double timestamp )
202
201
{
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
+ }
204
209
205
210
var time = DateTime . UnixEpoch . AddSeconds ( timestamp ) . ToLocalTime ( ) ;
206
211
if ( time >= _thisWeekStart )
@@ -214,13 +219,15 @@ public void AddCommit(string author, double timestamp)
214
219
215
220
public void Complete ( )
216
221
{
222
+ _users . Clear ( ) ;
223
+
217
224
All . Complete ( ) ;
218
225
Month . Complete ( ) ;
219
226
Week . Complete ( ) ;
220
227
}
221
-
222
- private readonly DateTime _today ;
228
+
223
229
private readonly DateTime _thisMonthStart ;
224
230
private readonly DateTime _thisWeekStart ;
231
+ private readonly Dictionary < string , User > _users = new ( ) ;
225
232
}
226
233
}
0 commit comments