• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / GitProjectHealth / 10420596471

16 Aug 2024 01:17PM UTC coverage: 19.048%. First build
10420596471

Pull #27

github

web-flow
Merge 57d5a387a into 7ae7aaeb7
Pull Request #27: feat(metrics): average time between commits

0 of 74 new or added lines in 3 files covered. (0.0%)

1585 of 8321 relevant lines covered (19.05%)

0.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/GitLabHealth-Model-Analysis/GitMetric4User.class.st
1
Class {
2
        #name : #GitMetric4User,
3
        #superclass : #GitMetric,
4
        #instVars : [
5
                'itsCommits',
6
                'itsMergeRequests'
7
        ],
8
        #category : #'GitLabHealth-Model-Analysis'
9
}
10

11
{ #category : #metrics }
NEW
12
GitMetric4User >> averageTimeBetweenCommitSince: since until: until over: aDateWeekMonthOrYear [
×
NEW
13

×
NEW
14
        | commits commitSortedByDate commits1 commits2 differences groupedByDate dateOver |
×
NEW
15
        
×
NEW
16
        groupedByDate := self
×
NEW
17
                                 setupGroupedDateFrom: since
×
NEW
18
                                 to: until
×
NEW
19
                                 over: aDateWeekMonthOrYear.
×
NEW
20
        
×
NEW
21
        gitAnalyzer := GitAnalyzer new
×
NEW
22
                               onModel: glhModel;
×
NEW
23
                               glhImporter: glhImporter.
×
NEW
24

×
NEW
25
        glhImporter withCommitDiffs: false.
×
NEW
26
        commits := self
×
NEW
27
                           loadCommitsFromProjectsIds: itsProjects keys
×
NEW
28
                           since: since
×
NEW
29
                           until: until.
×
NEW
30
        glhImporter withCommitDiffs: true.
×
NEW
31
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
NEW
32

×
NEW
33
        commitSortedByDate := commits sorted: [ :commit1 :commit2 |
×
NEW
34
                                      commit1 committed_date
×
NEW
35
                                      < commit2 committed_date ].
×
NEW
36
                        
×
NEW
37
        commitSortedByDate do: [ :commit | 
×
NEW
38
                 dateOver := self
×
NEW
39
                                    transformDate: commit committed_date 
×
NEW
40
                                    to: aDateWeekMonthOrYear.
×
NEW
41
                
×
NEW
42
                groupedByDate at: dateOver printString ifPresent: [ :value | value add: commit ].
×
NEW
43
        ].
×
NEW
44

×
NEW
45
        groupedByDate := groupedByDate select:  [ :group | group size >= 2 ].
×
NEW
46
        
×
NEW
47

×
NEW
48
        groupedByDate := groupedByDate collect: [ :group | 
×
NEW
49
                differences := (1 to: group size - 1) collect: [ :i |
×
NEW
50
                               commits1 := group at: i.
×
NEW
51
                               commits2 := group at: i + 1.
×
NEW
52

×
NEW
53
                               (commits2 committed_date - commits1 committed_date) asSeconds ].
×
NEW
54

×
NEW
55
                differences average asDuration.    
×
NEW
56
        ].
×
NEW
57
        
×
NEW
58

×
NEW
59
        ^{
×
NEW
60
                  (#overEach -> aDateWeekMonthOrYear name).
×
NEW
61
                  (#forOver -> (groupedByDate keys size printString
×
NEW
62
                    , aDateWeekMonthOrYear printString)).
×
NEW
63
                  (#average -> groupedByDate average).
×
NEW
64
                  (#details -> groupedByDate).
×
NEW
65
                  (#userCommits -> commits size) } asDictionary.
×
NEW
66
]
×
67

68
{ #category : #churn }
69
GitMetric4User >> codeChurnSince: since until: until onACommitWindowOf: commitLimit overA: aDateWeekMonthOrYear [
×
70

×
71
        | commits res groupedByDate totalContributions userCommits |
×
72
        "for each commit, we get its churn result (a dictionnary)"
×
73
        'GitMetric4User: code churn' recordInfo.
×
74
        totalContributions := OrderedCollection new.
×
75
        groupedByDate := self
×
76
                                 setupGroupedDateFrom: since
×
77
                                 to: until
×
78
                                 over: aDateWeekMonthOrYear.
×
79
        gitAnalyzer := GitAnalyzer new
×
80
                               glhImporter: glhImporter;
×
81
                               onModel: glhModel;
×
82
                               maxChildCommit: commitLimit.
×
83
        glhImporter withCommitDiffs: false.
×
84
        commits := self
×
85
                           loadCommitsFromProjectsIds: itsProjects keys
×
86
                           since: since
×
87
                           until: until.
×
88
        glhImporter withCommitDiffs: true.
×
89
        userCommits := commits reject: [ :commit |
×
90
                               commit commitCreator ~= user ].
×
91
        commits := self
×
92
                           foundSuccessorOf: userCommits
×
93
                           andCompleteImportForMax: commitLimit.
×
94

×
95

×
96
        res := commits collect: [ :commit |
×
97
                       commit -> (gitAnalyzer
×
98
                                fromCommit: commit;
×
99
                                analyseChurn) ].
×
100
        res do: [ :commits4Churns |
×
101
                | commit allChurnsInCommit sumChurnInCommit overDate contribution churnOnCommit |
×
102
                commit := commits4Churns key.
×
103
                allChurnsInCommit := commits4Churns value.
×
104
                sumChurnInCommit := (allChurnsInCommit at: #churns) sum: [ :churn |
×
105
                                            | numerator |
×
106
                                            numerator := churn value at: #churnLoC.
×
107
                                            numerator ].
×
108
                contribution := allChurnsInCommit at: #totalContribution.
×
109
                totalContributions add: contribution.
×
110
                churnOnCommit := {
×
111
                                         (#churnOnCommit -> sumChurnInCommit).
×
112
                                         (#LoCOnCommit -> contribution) } asDictionary.
×
113
                overDate := self
×
114
                                    transformDate: commit created_at
×
115
                                    to: aDateWeekMonthOrYear.
×
116
                groupedByDate
×
117
                        at: overDate printString
×
118
                        ifPresent: [ :array | array add: churnOnCommit ]
×
119
                        ifAbsentPut: [
×
120
                                OrderedCollection new
×
121
                                        add: churnOnCommit;
×
122
                                        yourself ] ].
×
123
        groupedByDate := groupedByDate collect: [ :churnsAtDate |
×
124
                                 | totalChurn totalContribution percentage |
×
125
                                 totalChurn := churnsAtDate sum: [ :churn |
×
126
                                                       churn at: #churnOnCommit ].
×
127
                                 totalContribution := churnsAtDate sum: [ :churn |
×
128
                                                              churn at: #LoCOnCommit ].
×
129
                                 totalContribution = 0
×
130
                                         ifTrue: [ percentage := 0 asFloat ]
×
131
                                         ifFalse: [
×
132
                                         percentage := (totalChurn * 100
×
133
                                                        / totalContribution) asFloat ].
×
134
                                 {
×
135
                                         (#churn -> totalChurn).
×
136
                                         (#contribution -> totalContribution).
×
137
                                         (#percentage -> percentage) } asDictionary ].
×
138
        ^ {
×
139
                  (#details -> groupedByDate).
×
140
                  (#totalContribution -> (totalContributions
×
141
                            ifEmpty: [ 0 ]
×
142
                            ifNotEmpty: [ totalContributions sum ])).
×
143
                  (#totalChurn -> (groupedByDate sum: [ :date | date at: #churn ])).
×
144
                  (#churn
×
145
                   ->
×
146
                   (groupedByDate collect: [ :date | date at: #percentage ]) average).
×
147
                  (#overEach -> aDateWeekMonthOrYear name).
×
148
                  (#forOver -> (groupedByDate keys size printString
×
149
                    , aDateWeekMonthOrYear printString)).
×
150
                  (#userCommits -> commits size).
×
151
                  (#churnWindow -> commitLimit) } asDictionary
×
152
]
×
153

154
{ #category : #metrics }
155
GitMetric4User >> codeContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
156

×
157
        | commits contributions groupedByDate |
×
158
        'GitMetric4User: code contribution' recordInfo.
×
159

×
160
        groupedByDate := self
×
161
                                 setupGroupedDateFrom: since
×
162
                                 to: until
×
163
                                 over: aDateWeekMonthOrYear.
×
164

×
165
        gitAnalyzer := GitAnalyzer new
×
166
                               onModel: glhModel;
×
167
                               glhImporter: glhImporter.
×
168

×
169
        glhImporter withCommitDiffs: false.
×
170
        commits := self
×
171
                           loadCommitsFromProjectsIds: itsProjects keys
×
172
                           since: since
×
173
                           until: until.
×
174
        glhImporter withCommitDiffs: true.
×
175
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
176

×
177
        contributions := commits collect: [ :commit |
×
178
                                 commit -> (gitAnalyzer
×
179
                                          fromCommit: commit;
×
180
                                          analyseCommitContribution) ].
×
181

×
182
        contributions do: [ :assoc |
×
183
                | dateOver |
×
184
                dateOver := self
×
185
                                    transformDate: assoc key created_at
×
186
                                    to: aDateWeekMonthOrYear.
×
187
                groupedByDate
×
188
                        at: dateOver printString
×
189
                        ifPresent: [ :v | v add: assoc value ]
×
190
                        ifAbsentPut: [
×
191
                                OrderedCollection new
×
192
                                        add: assoc value;
×
193
                                        yourself ] ].
×
194

×
195
        groupedByDate := groupedByDate collect: [ :contribs |
×
196
                                 | totalAdd totalDele |
×
197
                                 totalAdd := contribs sum: [ :v | v at: #addition ].
×
198
                                 totalDele := contribs sum: [ :v | v at: #deletion ].
×
199
                                 {
×
200
                                         (#addition -> totalAdd).
×
201
                                         (#deletion -> totalDele) } asDictionary ].
×
202

×
203
        ^ {
×
204
                  (#overEach -> aDateWeekMonthOrYear name).
×
205
                  (#forOver -> (groupedByDate keys size printString
×
206
                    , aDateWeekMonthOrYear printString)).
×
207
                  (#avgAddition
×
208
                   ->
×
209
                   (groupedByDate collect: [ :d | d at: #addition ]) average asFloat).
×
210
                  (#avgDeletion
×
211
                   ->
×
212
                   (groupedByDate collect: [ :d | d at: #deletion ]) average asFloat).
×
213
                  (#details -> groupedByDate).
×
214
                  (#userCommits -> commits size) } asDictionary
×
215
]
×
216

217
{ #category : #metrics }
218
GitMetric4User >> commentsContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
219

×
220
        | commits contributions groupedByDate |
×
221
        'GitMetric4User: comment contribution' recordInfo.
×
222

×
223
        groupedByDate := self
×
224
                                 setupGroupedDateFrom: since
×
225
                                 to: until
×
226
                                 over: aDateWeekMonthOrYear.
×
227

×
228
        gitAnalyzer := GitAnalyzer new
×
229
                               onModel: glhModel;
×
230
                               glhImporter: glhImporter.
×
231

×
232
        glhImporter withCommitDiffs: false.
×
233
        commits := self
×
234
                           loadCommitsFromProjectsIds: itsProjects keys
×
235
                           since: since
×
236
                           until: until.
×
237
        glhImporter withCommitDiffs: true.
×
238
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
239
        commits do: [ :commit | glhImporter completeImportedCommit: commit ].
×
240

×
241

×
242
        contributions := commits collect: [ :commit |
×
243
                                 commit -> (gitAnalyzer
×
244
                                          fromCommit: commit;
×
245
                                          analyseCommentContribution) ].
×
246

×
247

×
248
        contributions do: [ :assoc |
×
249
                | dateOver |
×
250
                dateOver := self
×
251
                                    transformDate: assoc key created_at
×
252
                                    to: aDateWeekMonthOrYear.
×
253
                groupedByDate
×
254
                        at: dateOver printString
×
255
                        ifPresent: [ :v | v add: assoc value ]
×
256
                        ifAbsentPut: [
×
257
                                OrderedCollection new
×
258
                                        add: assoc value;
×
259
                                        yourself ] ].
×
260

×
261
        groupedByDate := groupedByDate collect: [ :contribs |
×
262
                                 contribs
×
263
                                         ifNotEmpty: [ contribs sum ]
×
264
                                         ifEmpty: [ 0 ] ].
×
265

×
266

×
267
        ^ {
×
268
                  (#details -> groupedByDate).
×
269
                  (#totalComments -> groupedByDate values sum).
×
270
                  (#avgComments -> groupedByDate values average asFloat).
×
271
                  (#overEach -> aDateWeekMonthOrYear name).
×
272
                  (#forOver -> (groupedByDate keys size printString
×
273
                    , aDateWeekMonthOrYear printString)).
×
274
                  (#userCommits -> commits size) } asDictionary
×
275
]
×
276

277
{ #category : #metrics }
278
GitMetric4User >> commitFrequencySince: since until: until overA: aDateWeekMonthOrYear [
×
279

×
280
        | periods total groupedByDate userCommits |
×
281
        'GitMetric4User: commit frequency' recordInfo.
×
282

×
283
        groupedByDate := self
×
284
                                 setupGroupedDateFrom: since
×
285
                                 to: until
×
286
                                 over: aDateWeekMonthOrYear.
×
287

×
288
        glhImporter withCommitDiffs: false.
×
289
        userCommits := self
×
290
                               loadCommitsFromProjectsIds: itsProjects keys
×
291
                               since: since
×
292
                               until: until.
×
293
        glhImporter withCommitDiffs: true.
×
294
        userCommits := userCommits reject: [ :c | c commitCreator ~= user ].
×
295

×
296
        userCommits do: [ :c |
×
297
                | dateOver |
×
298
                dateOver := self
×
299
                                    transformDate: c created_at
×
300
                                    to: aDateWeekMonthOrYear.
×
301
                groupedByDate at: dateOver printString ifPresent: [ :v | v add: c ] ].
×
302

×
303
        periods := groupedByDate keys size.
×
304
        total := groupedByDate values sum: [ :commits | commits size ].
×
305

×
306

×
307
        ^ {
×
308
                  (#averageFrac -> (total / periods)).
×
309
                  (#averageFloat -> (total / periods) asFloat).
×
310
                  (#userCommit -> total).
×
311
                  (#forOver -> (groupedByDate keys size printString
×
312
                    , aDateWeekMonthOrYear printString)).
×
313
                  (#periode -> aDateWeekMonthOrYear name).
×
314
                  (#details -> groupedByDate) } asOrderedDictionary
×
315
]
×
316

317
{ #category : #'as yet unclassified' }
318
GitMetric4User >> commitsProducedOnProject: projectId since: sinceDate until: untilDate [
×
319

×
320
        | frequencies |
×
321
        
×
322
        
×
323
        gitAnalyzer := GitAnalyzer new 
×
324
        glhImporter: glhImporter; 
×
325
        onModel: glhModel.
×
326
         
×
327
        frequencies := gitAnalyzer
×
328
                               onProject: (itsProjects at: projectId);
×
329
                               analyseCommitFrequencySince: sinceDate
×
330
                               until: untilDate. 
×
331
        
×
332
        "complete each commit "
×
333
        frequencies values flattened do: [ :commit |
×
334
                glhImporter completeImportedCommit: commit.
×
335
                 ].
×
336
        
×
337
        "Filter the associations in the 'frequencies' collection, removing any commits not created by the specified 'user'. "
×
338
        frequencies associations do: [ :assoc |
×
339
                |commits| 
×
340
                commits := assoc value.
×
341
                assoc value: (commits reject: [ :commit | commit commitCreator ~= user ]). 
×
342
        ].
×
343
        
×
344
        ^ frequencies 
×
345
]
×
346

347
{ #category : #metrics }
348
GitMetric4User >> commitsProducedOnProject: aProjectId since: since until: until overA: aWeekOrMonthOrYear [
×
349
        "'aWeekOrMonthOrYear' should be the class of Data, Week, Month or Year"
×
350

×
351
        | frequency aggregatedFrequencies |
×
352
        aggregatedFrequencies := self
×
353
                                         setupGroupedDateFrom: since
×
354
                                         to: until
×
355
                                         over: aWeekOrMonthOrYear.
×
356

×
357
        frequency := self
×
358
                             commitsProducedOnProject: aProjectId
×
359
                             since: since
×
360
                             until: until.
×
361

×
362
        frequency associations do: [ :assoc |
×
363
                | date commits overDate |
×
364
                date := assoc key.
×
365
                commits := assoc value.
×
366

×
367
                commits ifNotEmpty: [ " convert the date as its week date. For some english reason, the week start in sunday so we should add a + 1 day "
×
368
                        overDate := self transformDate: date to: aWeekOrMonthOrYear.
×
369
                        aggregatedFrequencies
×
370
                                at: overDate printString
×
371
                                ifPresent: [ :collection | collection addAll: commits ]
×
372
                                ifAbsentPut: [ commits ] ] ].
×
373

×
374
        ^ aggregatedFrequencies
×
375
]
×
376

377
{ #category : #churn }
378
GitMetric4User >> delayUntilFirstChurnSince: since until: until onACommitWindowOf: maxCommitWindow overA: aDateWeekMonthOrYear [
×
379

×
380
        | commits groupedByDate res avg userCommits |
×
381
        'GitMetric4User: delay until first churn' recordInfo.
×
382

×
383
        groupedByDate := self
×
384
                                 setupGroupedDateFrom: since
×
385
                                 to: until
×
386
                                 over: aDateWeekMonthOrYear.
×
387

×
388
        glhImporter withCommitDiffs: false.
×
389
        commits := self
×
390
                           loadCommitsFromProjectsIds: itsProjects keys
×
391
                           since: since
×
392
                           until: until.
×
393
        glhImporter withCommitDiffs: true.
×
394

×
395
        userCommits := commits reject: [ :commit |
×
396
                               commit commitCreator ~= user ].
×
397
        commits := self
×
398
                           foundSuccessorOf: userCommits
×
399
                           andCompleteImportForMax: maxCommitWindow.
×
400

×
401

×
402
        "class commit by dates, filter none user commits"
×
403
        commits do: [ :commit |
×
404
                commit commitCreator = user ifTrue: [
×
405
                        | overDate |
×
406
                        overDate := self
×
407
                                            transformDate: commit created_at
×
408
                                            to: aDateWeekMonthOrYear.
×
409

×
410
                        groupedByDate
×
411
                                at: overDate printString
×
412
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
413
                                ifAbsentPut: [
×
414
                                        OrderedCollection new
×
415
                                                add: commit;
×
416
                                                yourself ] ] ].
×
417

×
418

×
419

×
420
        res := groupedByDate collect: [ :commits4Date |
×
421
                       | durationFromA2B |
×
422
                       commits4Date collect: [ :commitA |
×
423
                               | commitB |
×
424
                               commitB := GitAnalyzer new
×
425
                                                  glhImporter: glhImporter;
×
426
                                                  onModel: glhModel;
×
427
                                                  fromCommit: commitA;
×
428
                                                  maxChildCommit: maxCommitWindow;
×
429
                                                  analyseDelayUntilFirstChurn.
×
430

×
431
                               durationFromA2B := commitB
×
432
                                                          ifNil: [ 0 ]
×
433
                                                          ifNotNil: [
×
434
                                                          commitB created_at - commitA created_at ].
×
435
                               durationFromA2B ] ].
×
436

×
437

×
438

×
439
        res := res collect: [ :durationsByDate |
×
440
                       | filtered |
×
441
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
442
                       filtered isEmpty
×
443
                               ifTrue: [ nil ]
×
444
                               ifFalse: [
×
445
                               (filtered sum: [ :v | v asDuration asSeconds]) / filtered size ] ].
×
446

×
447
        res := res reject: #isNil.
×
448

×
449
        res
×
450
                ifEmpty: [ avg := nil ]
×
451
                ifNotEmpty: [ avg := res values average asFloat ].
×
452

×
453

×
454
        ^ {
×
455
                  (#avgDelay -> avg).
×
456
                  (#overEach -> aDateWeekMonthOrYear name).
×
457
                  (#forOver -> (groupedByDate keys size printString
×
458
                    , aDateWeekMonthOrYear printString)).
×
459
                  (#details -> groupedByDate) } asDictionary
×
460
]
×
461

462
{ #category : #churn }
463
GitMetric4User >> delayUntilFirstChurnSince: since until: until overA: aDateWeekMonthOrYear [
×
464

×
465
        | commits groupedByDate res avg |
×
466
        self
×
467
                deprecated:
×
468
                'Use #delayUntilFirstChurnSince:until:onACommitWindowOf:overA: instead'
×
469
                on: '1 July 2024'
×
470
                in:
×
471
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
472

×
473
        'GitMetric4User: delay until first churn' recordInfo.
×
474

×
475
        groupedByDate := self
×
476
                                 setupGroupedDateFrom: since
×
477
                                 to: until
×
478
                                 over: aDateWeekMonthOrYear.
×
479

×
480
        commits := self
×
481
                           loadCommitsFromProjectsIds: itsProjects keys
×
482
                           since: since
×
483
                           until: until.
×
484

×
485
        "class commit by dates, filter none user commits"
×
486
        commits do: [ :commit |
×
487
                commit commitCreator = user ifTrue: [
×
488
                        | overDate |
×
489
                        overDate := self
×
490
                                            transformDate: commit created_at
×
491
                                            to: aDateWeekMonthOrYear.
×
492

×
493
                        groupedByDate
×
494
                                at: overDate printString
×
495
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
496
                                ifAbsentPut: [
×
497
                                        OrderedCollection new
×
498
                                                add: commit;
×
499
                                                yourself ] ] ].
×
500

×
501

×
502

×
503
        res := groupedByDate collect: [ :commits4Date |
×
504
                       | durationFromA2B |
×
505
                       commits4Date collect: [ :commitA |
×
506
                               | commitB |
×
507
                               commitB := GitAnalyzer new
×
508
                                                  glhImporter: glhImporter;
×
509
                                                  onModel: glhModel;
×
510
                                                  fromCommit: commitA;
×
511
                                                  maxChildCommit: 5;
×
512
                                                  analyseDelayUntilFirstChurn.
×
513

×
514
                               durationFromA2B := commitB
×
515
                                                          ifNil: [ 0 ]
×
516
                                                          ifNotNil: [
×
517
                                                          commitB created_at - commitA created_at ].
×
518
                               durationFromA2B ] ].
×
519

×
520

×
521

×
522
        res := res collect: [ :durationsByDate |
×
523
                       | filtered |
×
524
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
525
                       filtered isEmpty
×
526
                               ifTrue: [ nil ]
×
527
                               ifFalse: [
×
528
                               (filtered sum: [ :v | v asDuration ]) / filtered size ] ].
×
529

×
530
        res := res reject: #isNil.
×
531

×
532
        res
×
533
                ifEmpty: [ avg := nil ]
×
534
                ifNotEmpty: [ avg := res values sum / res keys size ].
×
535

×
536

×
537
        ^ {
×
538
                  (#avgDelay -> avg).
×
539
                  (#overEach -> aDateWeekMonthOrYear name).
×
540
                  (#forOver -> (groupedByDate keys size printString
×
541
                    , aDateWeekMonthOrYear printString)).
×
542
                  (#details -> groupedByDate) } asDictionary
×
543
]
×
544

545
{ #category : #churn }
546
GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitLimit [
×
547

×
548
        | analyzingCommits i size|
×
549
        analyzingCommits := Set new.
×
550
        glhImporter withCommitDiffs: true.
×
551

×
552
        userCommits do: [ :c |
×
553
                gitAnalyzer
×
554
                        visitChildCommits: c childCommits
×
555
                        toStoreThemIn: analyzingCommits
×
556
                        upto: commitLimit ].
×
557

×
558
        i := 0.
×
559
        size := analyzingCommits size. 
×
560
        analyzingCommits do: [ :c |
×
561
                ('import complete commits  [' , (i:=i+1) printString, '/', size printString , ']'  ) recordInfo.
×
562
                glhImporter completeImportedCommit: c ].
×
563

×
564
        ^ analyzingCommits
×
565
]
×
566

567
{ #category : #'as yet unclassified' }
568
GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWindows: maxCommitWindow [
×
569

×
NEW
570
        | contribution codeAddition codeDeletion commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn averageTimeBetweenCommits |
×
571
        
×
572
        contribution := self
×
573
                                codeContributionsSince: (period at: #since)
×
574
                                until: (period at: #until)
×
575
                                overA: over.
×
576
        codeAddition := contribution at: #avgAddition.
×
577
        codeDeletion := contribution at: #avgDeletion.
×
578

×
579
        commitFrequency := (self
×
580
                                    commitFrequencySince: (period at: #since)
×
581
                                    until: (period at: #until)
×
582
                                    overA: over) at: #averageFloat.
×
583

×
584
        commentContribution := (self
×
585
                                        commentsContributionsSince:
×
586
                                        (period at: #since)
×
587
                                        until: (period at: #until)
×
588
                                        overA: over) at: #avgComments.
×
589

×
590
        mergeRequestDuration := (self
×
591
                                         mergeRequestDurationSince:
×
592
                                         (period at: #since)
×
593
                                         until: (period at: #until)
×
594
                                         overA: over) at: #avgDuration.
×
595

×
596
        codeChurn := (self
×
597
                              codeChurnSince: (period at: #since)
×
598
                              until: (period at: #until)
×
599
                              onACommitWindowOf: maxCommitWindow
×
600
                              overA: over) at: #churn.
×
601

×
602
        delayUntilFirstChurn := (self
×
603
                                         delayUntilFirstChurnSince:
×
604
                                         (period at: #since)
×
605
                                         until: (period at: #until)
×
606
                                         onACommitWindowOf: maxCommitWindow
×
607
                                         overA: over) at: #avgDelay.
×
NEW
608
                
×
NEW
609
        averageTimeBetweenCommits := (self averageTimeBetweenCommitSince: (period at: #since) until: (period at: #until) over: over) at: #average.
×
610

×
611
        ^ AnalysisReport new
×
612
                  username: self user name;
×
613
                  period: period;
×
614
                  codeAddition: codeAddition;
×
615
                  codeDeletion: codeDeletion;
×
616
                  commitFrequency: commitFrequency;
×
617
                  commentContribution: commentContribution;
×
618
                  mergeRequestDuration: mergeRequestDuration;
×
619
                  codeChurn: codeChurn;
×
NEW
620
                  delayUntilFirstChurn: delayUntilFirstChurn;
×
NEW
621
                  averageTimeBetweenCommits: averageTimeBetweenCommits.
×
622
]
×
623

624
{ #category : #initialization }
625
GitMetric4User >> initialize [
×
626

×
627
        user := GLHUser new.
×
628
        itsProjects := Dictionary new.
×
629
        itsCommits := Dictionary new.
×
630
        itsMergeRequests := Dictionary new
×
631
]
×
632

633
{ #category : #accessing }
634
GitMetric4User >> itsProjects: projects [
×
635
        itsProjects := projects .
×
636
]
×
637

638
{ #category : #churn }
639
GitMetric4User >> loadCommitOfProjects: aCollection since: aTimespan [
×
640
        |commits|
×
641
        
×
642
        commits := (aCollection collect: [ :id |
×
643
                 glhImporter
×
644
                        importCommitsOProject: (itsProjects at: id)
×
645
                        since: aTimespan
×
646
                        until: nil ]) flattened.
×
647

×
648
        commits do: [ :commit |
×
649
                glhImporter completeImportedCommit: commit. 
×
650
                 ].
×
651

×
652
        ^ self userCommits.
×
653
]
×
654

655
{ #category : #metrics }
656
GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeekMonthOrYear [
×
657

×
658
        | mergeRequest res groupedByDate filterGroups avg |
×
659
        groupedByDate := self
×
660
                                 setupGroupedDateFrom: since
×
661
                                 to: until
×
662
                                 over: aDateWeekMonthOrYear.
×
663

×
664
        gitAnalyzer := GitAnalyzer new
×
665
                               glhImporter: glhImporter;
×
666
                               onModel: glhModel.
×
667

×
668
        glhImporter withCommitDiffs: false.
×
669
        mergeRequest := self
×
670
                                loadMergeRequestsFromProjectsIds: itsProjects keys
×
671
                                since: since
×
672
                                until: until.
×
673
        glhImporter withCommitDiffs: true.
×
674

×
675
        mergeRequest ifEmpty: [
×
676
                ^ {
×
677
                          (#avgDuration -> nil).
×
678
                          (#overEach -> aDateWeekMonthOrYear name).
×
679
                          (#forOver -> (groupedByDate keys size printString
×
680
                            , aDateWeekMonthOrYear printString)).
×
681
                          (#totalMergeRequest -> 0).
×
682
                          (#details -> nil) } asDictionary ].
×
683

×
684
        res := mergeRequest collect: [ :mr |
×
685
                       gitAnalyzer analyseMergeResquestValidation: mr ].
×
686

×
687

×
688
        res do: [ :dic |
×
689
                | overDate |
×
690
                overDate := self
×
691
                                    transformDate: (dic at: #created_at)
×
692
                                    to: aDateWeekMonthOrYear.
×
693

×
694
                groupedByDate
×
695
                        at: overDate printString
×
696
                        ifPresent: [ :durations | durations add: (dic at: #duration) ]
×
697
                        ifAbsentPut: [
×
698
                                OrderedCollection new
×
699
                                        add: (dic at: #duration);
×
700
                                        yourself ] ].
×
701

×
702

×
703
        filterGroups := groupedByDate reject: [ :array | array isEmpty ].
×
704

×
705
        filterGroups associations do: [ :assoc |
×
706
                | sum denominator |
×
707
                denominator := assoc value size.
×
708

×
709
                sum := assoc value sum: [ :v |
×
710
                               v ifNil: [
×
711
                                       denominator := denominator - 1.
×
712
                                       0 asDuration ] ].
×
713
                denominator = 0 ifTrue: [ denominator := 1 ].
×
714

×
715
                filterGroups at: assoc key put: sum / denominator ].
×
716

×
717

×
718
        filterGroups keys
×
719
                ifEmpty: [ avg := 0 ]
×
720
                ifNotEmpty: [
×
721
                avg := filterGroups values sum / filterGroups keys size ].
×
722

×
723

×
724
        ^ {
×
725
                  (#avgDuration -> avg).
×
726
                  (#overEach -> aDateWeekMonthOrYear name).
×
727
                  (#forOver -> (groupedByDate keys size printString
×
728
                    , aDateWeekMonthOrYear printString)).
×
729
                  (#totalMergeRequest -> mergeRequest size).
×
730
                  (#details -> groupedByDate) } asDictionary
×
731
]
×
732

733
{ #category : #accessing }
734
GitMetric4User >> user [
×
735
        ^ user
×
736
]
×
737

738
{ #category : #accessing }
739
GitMetric4User >> user: anUser [
×
740
        user := anUser. 
×
741
]
×
742

743
{ #category : #accessing }
744
GitMetric4User >> userCommits [
×
745
        ^ user commits
×
746
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc