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

moosetechnology / GitProjectHealth / 10387476411

14 Aug 2024 12:23PM UTC coverage: 19.044%. First build
10387476411

Pull #27

github

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

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

1585 of 8323 relevant lines covered (19.04%)

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
        dateOver := self
×
NEW
38
                                    transformDate: (commitSortedByDate at: 1) committed_date 
×
NEW
39
                                    to: aDateWeekMonthOrYear.
×
NEW
40
                        
×
NEW
41
        commitSortedByDate do: [ :commit | 
×
NEW
42
                 dateOver := self
×
NEW
43
                                    transformDate: commit committed_date 
×
NEW
44
                                    to: aDateWeekMonthOrYear.
×
NEW
45
                
×
NEW
46
                groupedByDate at: dateOver printString ifPresent: [ :value | value add: commit ].
×
NEW
47
        ].
×
NEW
48

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

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

×
NEW
56
                differences := differences ifEmpty: [differences ] ifNotEmpty: [differences average asDuration].    
×
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
×
NEW
64
                   ->
×
NEW
65
                   (groupedByDate at: (groupedByDate keys first))).
×
NEW
66
                  (#details -> groupedByDate).
×
NEW
67
                  (#userCommits -> commits size) } asDictionary.
×
NEW
68
]
×
69

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

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

×
97

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

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

×
159
        | commits contributions groupedByDate |
×
160
        'GitMetric4User: code contribution' recordInfo.
×
161

×
162
        groupedByDate := self
×
163
                                 setupGroupedDateFrom: since
×
164
                                 to: until
×
165
                                 over: aDateWeekMonthOrYear.
×
166

×
167
        gitAnalyzer := GitAnalyzer new
×
168
                               onModel: glhModel;
×
169
                               glhImporter: glhImporter.
×
170

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

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

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

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

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

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

×
222
        | commits contributions groupedByDate |
×
223
        'GitMetric4User: comment contribution' recordInfo.
×
224

×
225
        groupedByDate := self
×
226
                                 setupGroupedDateFrom: since
×
227
                                 to: until
×
228
                                 over: aDateWeekMonthOrYear.
×
229

×
230
        gitAnalyzer := GitAnalyzer new
×
231
                               onModel: glhModel;
×
232
                               glhImporter: glhImporter.
×
233

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

×
243

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

×
249

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

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

×
268

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

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

×
282
        | periods total groupedByDate userCommits |
×
283
        'GitMetric4User: commit frequency' recordInfo.
×
284

×
285
        groupedByDate := self
×
286
                                 setupGroupedDateFrom: since
×
287
                                 to: until
×
288
                                 over: aDateWeekMonthOrYear.
×
289

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

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

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

×
308

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

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

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

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

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

×
359
        frequency := self
×
360
                             commitsProducedOnProject: aProjectId
×
361
                             since: since
×
362
                             until: until.
×
363

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

×
369
                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 "
×
370
                        overDate := self transformDate: date to: aWeekOrMonthOrYear.
×
371
                        aggregatedFrequencies
×
372
                                at: overDate printString
×
373
                                ifPresent: [ :collection | collection addAll: commits ]
×
374
                                ifAbsentPut: [ commits ] ] ].
×
375

×
376
        ^ aggregatedFrequencies
×
377
]
×
378

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

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

×
385
        groupedByDate := self
×
386
                                 setupGroupedDateFrom: since
×
387
                                 to: until
×
388
                                 over: aDateWeekMonthOrYear.
×
389

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

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

×
403

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

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

×
420

×
421

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

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

×
439

×
440

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

×
449
        res := res reject: #isNil.
×
450

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

×
455

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

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

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

×
475
        'GitMetric4User: delay until first churn' recordInfo.
×
476

×
477
        groupedByDate := self
×
478
                                 setupGroupedDateFrom: since
×
479
                                 to: until
×
480
                                 over: aDateWeekMonthOrYear.
×
481

×
482
        commits := self
×
483
                           loadCommitsFromProjectsIds: itsProjects keys
×
484
                           since: since
×
485
                           until: until.
×
486

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

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

×
503

×
504

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

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

×
522

×
523

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

×
532
        res := res reject: #isNil.
×
533

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

×
538

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

547
{ #category : #churn }
548
GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitLimit [
×
549

×
550
        | analyzingCommits i size|
×
551
        analyzingCommits := Set new.
×
552
        glhImporter withCommitDiffs: true.
×
553

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

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

×
566
        ^ analyzingCommits
×
567
]
×
568

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

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

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

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

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

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

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

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

626
{ #category : #initialization }
627
GitMetric4User >> initialize [
×
628

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

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

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

×
650
        commits do: [ :commit |
×
651
                glhImporter completeImportedCommit: commit. 
×
652
                 ].
×
653

×
654
        ^ self userCommits.
×
655
]
×
656

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

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

×
666
        gitAnalyzer := GitAnalyzer new
×
667
                               glhImporter: glhImporter;
×
668
                               onModel: glhModel.
×
669

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

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

×
686
        res := mergeRequest collect: [ :mr |
×
687
                       gitAnalyzer analyseMergeResquestValidation: mr ].
×
688

×
689

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

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

×
704

×
705
        filterGroups := groupedByDate reject: [ :array | array isEmpty ].
×
706

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

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

×
717
                filterGroups at: assoc key put: sum / denominator ].
×
718

×
719

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

×
725

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

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

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

745
{ #category : #accessing }
746
GitMetric4User >> userCommits [
×
747
        ^ user commits
×
748
]
×
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