11
11
12
12
namespace SourceGit . Models
13
13
{
14
- public enum StaticsticsMode
14
+ public enum StatisticsMode
15
15
{
16
16
All ,
17
17
ThisMonth ,
18
18
ThisWeek ,
19
19
}
20
20
21
- public class StaticsticsAuthor ( User user , int count )
21
+ public class StatisticsAuthor ( User user , int count )
22
22
{
23
23
public User User { get ; set ; } = user ;
24
24
public int Count { get ; set ; } = count ;
25
25
}
26
26
27
- public class StaticsticsSample ( DateTime time , int count )
28
- {
29
- public DateTime Time { get ; set ; } = time ;
30
- public int Count { get ; set ; } = count ;
31
- }
32
-
33
27
public class StatisticsReport
34
28
{
35
29
public static readonly string [ ] WEEKDAYS = [ "SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" ] ;
36
30
37
31
public int Total { get ; set ; } = 0 ;
38
- public List < StaticsticsAuthor > Authors { get ; set ; } = new List < StaticsticsAuthor > ( ) ;
32
+ public List < StatisticsAuthor > Authors { get ; set ; } = new List < StatisticsAuthor > ( ) ;
39
33
public List < ISeries > Series { get ; set ; } = new List < ISeries > ( ) ;
40
34
public List < Axis > XAxes { get ; set ; } = new List < Axis > ( ) ;
41
35
public List < Axis > YAxes { get ; set ; } = new List < Axis > ( ) ;
36
+ public StatisticsAuthor SelectedAuthor { get => _selectedAuthor ; set => ChangeAuthor ( value ) ; }
42
37
43
- public StatisticsReport ( StaticsticsMode mode , DateTime start )
38
+ public StatisticsReport ( StatisticsMode mode , DateTime start )
44
39
{
45
40
_mode = mode ;
46
41
@@ -51,14 +46,14 @@ public StatisticsReport(StaticsticsMode mode, DateTime start)
51
46
SeparatorsPaint = new SolidColorPaint ( new SKColor ( 0x40808080 ) ) { StrokeThickness = 1 }
52
47
} ] ;
53
48
54
- if ( mode == StaticsticsMode . ThisWeek )
49
+ if ( mode == StatisticsMode . ThisWeek )
55
50
{
56
51
for ( int i = 0 ; i < 7 ; i ++ )
57
52
_mapSamples . Add ( start . AddDays ( i ) , 0 ) ;
58
53
59
54
XAxes . Add ( new DateTimeAxis ( TimeSpan . FromDays ( 1 ) , v => WEEKDAYS [ ( int ) v . DayOfWeek ] ) { TextSize = 10 } ) ;
60
55
}
61
- else if ( mode == StaticsticsMode . ThisMonth )
56
+ else if ( mode == StatisticsMode . ThisMonth )
62
57
{
63
58
var now = DateTime . Now ;
64
59
var maxDays = DateTime . DaysInMonth ( now . Year , now . Month ) ;
@@ -78,7 +73,7 @@ public void AddCommit(DateTime time, User author)
78
73
Total ++ ;
79
74
80
75
var normalized = DateTime . MinValue ;
81
- if ( _mode == StaticsticsMode . ThisWeek || _mode == StaticsticsMode . ThisMonth )
76
+ if ( _mode == StatisticsMode . ThisWeek || _mode == StatisticsMode . ThisMonth )
82
77
normalized = time . Date ;
83
78
else
84
79
normalized = new DateTime ( time . Year , time . Month , 1 ) . ToLocalTime ( ) ;
@@ -92,10 +87,30 @@ public void AddCommit(DateTime time, User author)
92
87
_mapUsers [ author ] = vu + 1 ;
93
88
else
94
89
_mapUsers . Add ( author , 1 ) ;
90
+
91
+ if ( _mapUserSamples . TryGetValue ( author , out var vus ) )
92
+ {
93
+ if ( vus . TryGetValue ( normalized , out var n ) )
94
+ vus [ normalized ] = n + 1 ;
95
+ else
96
+ vus . Add ( normalized , 1 ) ;
97
+ }
98
+ else
99
+ {
100
+ _mapUserSamples . Add ( author , new Dictionary < DateTime , int >
101
+ {
102
+ { normalized , 1 }
103
+ } ) ;
104
+ }
95
105
}
96
106
97
107
public void Complete ( )
98
108
{
109
+ foreach ( var kv in _mapUsers )
110
+ Authors . Add ( new StatisticsAuthor ( kv . Key , kv . Value ) ) ;
111
+
112
+ Authors . Sort ( ( l , r ) => r . Count - l . Count ) ;
113
+
99
114
var samples = new List < DateTimePoint > ( ) ;
100
115
foreach ( var kv in _mapSamples )
101
116
samples . Add ( new DateTimePoint ( kv . Key , kv . Value ) ) ;
@@ -110,24 +125,59 @@ public void Complete()
110
125
}
111
126
) ;
112
127
113
- foreach ( var kv in _mapUsers )
114
- Authors . Add ( new StaticsticsAuthor ( kv . Key , kv . Value ) ) ;
115
-
116
- Authors . Sort ( ( l , r ) => r . Count - l . Count ) ;
117
-
118
128
_mapUsers . Clear ( ) ;
119
129
_mapSamples . Clear ( ) ;
120
130
}
121
131
122
132
public void ChangeColor ( uint color )
123
133
{
124
- if ( Series is [ ColumnSeries < DateTimePoint > series ] )
125
- series . Fill = new SolidColorPaint ( new SKColor ( color ) ) ;
134
+ _fillColor = color ;
135
+
136
+ var fill = new SKColor ( color ) ;
137
+
138
+ if ( Series . Count > 0 && Series [ 0 ] is ColumnSeries < DateTimePoint > total )
139
+ total . Fill = new SolidColorPaint ( _selectedAuthor == null ? fill : fill . WithAlpha ( 51 ) ) ;
140
+
141
+ if ( Series . Count > 1 && Series [ 1 ] is ColumnSeries < DateTimePoint > user )
142
+ user . Fill = new SolidColorPaint ( fill ) ;
143
+ }
144
+
145
+ public void ChangeAuthor ( StatisticsAuthor author )
146
+ {
147
+ if ( author == _selectedAuthor )
148
+ return ;
149
+
150
+ _selectedAuthor = author ;
151
+ Series . RemoveRange ( 1 , Series . Count - 1 ) ;
152
+ if ( author == null || ! _mapUserSamples . TryGetValue ( author . User , out var userSamples ) )
153
+ {
154
+ ChangeColor ( _fillColor ) ;
155
+ return ;
156
+ }
157
+
158
+ var samples = new List < DateTimePoint > ( ) ;
159
+ foreach ( var kv in userSamples )
160
+ samples . Add ( new DateTimePoint ( kv . Key , kv . Value ) ) ;
161
+
162
+ Series . Add (
163
+ new ColumnSeries < DateTimePoint > ( )
164
+ {
165
+ Values = samples ,
166
+ Stroke = null ,
167
+ Fill = null ,
168
+ Padding = 1 ,
169
+ }
170
+ ) ;
171
+
172
+ ChangeColor ( _fillColor ) ;
126
173
}
127
174
128
- private StaticsticsMode _mode = StaticsticsMode . All ;
175
+ private StatisticsMode _mode = StatisticsMode . All ;
129
176
private Dictionary < User , int > _mapUsers = new Dictionary < User , int > ( ) ;
130
177
private Dictionary < DateTime , int > _mapSamples = new Dictionary < DateTime , int > ( ) ;
178
+ private Dictionary < User , Dictionary < DateTime , int > > _mapUserSamples = new Dictionary < User , Dictionary < DateTime , int > > ( ) ;
179
+ private StatisticsAuthor _selectedAuthor = null ;
180
+ private uint _fillColor = 255 ;
131
181
}
132
182
133
183
public class Statistics
@@ -143,9 +193,9 @@ public Statistics()
143
193
_thisWeekStart = _today . AddDays ( - weekOffset ) ;
144
194
_thisMonthStart = _today . AddDays ( 1 - _today . Day ) ;
145
195
146
- All = new StatisticsReport ( StaticsticsMode . All , DateTime . MinValue ) ;
147
- Month = new StatisticsReport ( StaticsticsMode . ThisMonth , _thisMonthStart ) ;
148
- Week = new StatisticsReport ( StaticsticsMode . ThisWeek , _thisWeekStart ) ;
196
+ All = new StatisticsReport ( StatisticsMode . All , DateTime . MinValue ) ;
197
+ Month = new StatisticsReport ( StatisticsMode . ThisMonth , _thisMonthStart ) ;
198
+ Week = new StatisticsReport ( StatisticsMode . ThisWeek , _thisWeekStart ) ;
149
199
}
150
200
151
201
public void AddCommit ( string author , double timestamp )
0 commit comments