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

moosetechnology / GitProjectHealth / 10417352781

16 Aug 2024 08:53AM UTC coverage: 19.039%. First build
10417352781

Pull #27

github

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

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

1585 of 8325 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 select:  [ :group | group size >= 2 ].
×
NEW
50
        
×
NEW
51

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

×
NEW
57
                               (commits2 committed_date - commits1 committed_date) asSeconds ].
×
NEW
58

×
NEW
59
                differences average asDuration.    
×
NEW
60
        ].
×
NEW
61
        
×
NEW
62

×
NEW
63
        ^{
×
NEW
64
                  (#overEach -> aDateWeekMonthOrYear name).
×
NEW
65
                  (#forOver -> (groupedByDate keys size printString
×
NEW
66
                    , aDateWeekMonthOrYear printString)).
×
NEW
67
                  (#average -> groupedByDate average).
×
NEW
68
                  (#details -> groupedByDate).
×
NEW
69
                  (#userCommits -> commits size) } asDictionary.
×
NEW
70
]
×
71

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

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

×
99

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

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

×
161
        | commits contributions groupedByDate |
×
162
        'GitMetric4User: code contribution' recordInfo.
×
163

×
164
        groupedByDate := self
×
165
                                 setupGroupedDateFrom: since
×
166
                                 to: until
×
167
                                 over: aDateWeekMonthOrYear.
×
168

×
169
        gitAnalyzer := GitAnalyzer new
×
170
                               onModel: glhModel;
×
171
                               glhImporter: glhImporter.
×
172

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

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

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

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

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

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

×
224
        | commits contributions groupedByDate |
×
225
        'GitMetric4User: comment contribution' recordInfo.
×
226

×
227
        groupedByDate := self
×
228
                                 setupGroupedDateFrom: since
×
229
                                 to: until
×
230
                                 over: aDateWeekMonthOrYear.
×
231

×
232
        gitAnalyzer := GitAnalyzer new
×
233
                               onModel: glhModel;
×
234
                               glhImporter: glhImporter.
×
235

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

×
245

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

×
251

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

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

×
270

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

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

×
284
        | periods total groupedByDate userCommits |
×
285
        'GitMetric4User: commit frequency' recordInfo.
×
286

×
287
        groupedByDate := self
×
288
                                 setupGroupedDateFrom: since
×
289
                                 to: until
×
290
                                 over: aDateWeekMonthOrYear.
×
291

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

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

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

×
310

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

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

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

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

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

×
361
        frequency := self
×
362
                             commitsProducedOnProject: aProjectId
×
363
                             since: since
×
364
                             until: until.
×
365

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

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

×
378
        ^ aggregatedFrequencies
×
379
]
×
380

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

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

×
387
        groupedByDate := self
×
388
                                 setupGroupedDateFrom: since
×
389
                                 to: until
×
390
                                 over: aDateWeekMonthOrYear.
×
391

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

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

×
405

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

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

×
422

×
423

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

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

×
441

×
442

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

×
451
        res := res reject: #isNil.
×
452

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

×
457

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

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

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

×
477
        'GitMetric4User: delay until first churn' recordInfo.
×
478

×
479
        groupedByDate := self
×
480
                                 setupGroupedDateFrom: since
×
481
                                 to: until
×
482
                                 over: aDateWeekMonthOrYear.
×
483

×
484
        commits := self
×
485
                           loadCommitsFromProjectsIds: itsProjects keys
×
486
                           since: since
×
487
                           until: until.
×
488

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

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

×
505

×
506

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

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

×
524

×
525

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

×
534
        res := res reject: #isNil.
×
535

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

×
540

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

549
{ #category : #churn }
550
GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitLimit [
×
551

×
552
        | analyzingCommits i size|
×
553
        analyzingCommits := Set new.
×
554
        glhImporter withCommitDiffs: true.
×
555

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

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

×
568
        ^ analyzingCommits
×
569
]
×
570

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

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

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

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

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

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

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

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

628
{ #category : #initialization }
629
GitMetric4User >> initialize [
×
630

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

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

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

×
652
        commits do: [ :commit |
×
653
                glhImporter completeImportedCommit: commit. 
×
654
                 ].
×
655

×
656
        ^ self userCommits.
×
657
]
×
658

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

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

×
668
        gitAnalyzer := GitAnalyzer new
×
669
                               glhImporter: glhImporter;
×
670
                               onModel: glhModel.
×
671

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

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

×
688
        res := mergeRequest collect: [ :mr |
×
689
                       gitAnalyzer analyseMergeResquestValidation: mr ].
×
690

×
691

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

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

×
706

×
707
        filterGroups := groupedByDate reject: [ :array | array isEmpty ].
×
708

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

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

×
719
                filterGroups at: assoc key put: sum / denominator ].
×
720

×
721

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

×
727

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

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

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

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