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

moosetechnology / GitProjectHealth / 10450728540

19 Aug 2024 09:23AM UTC coverage: 18.867%. First build
10450728540

Pull #29

github

web-flow
Merge 1045c3745 into 7a6969e8a
Pull Request #29: refactor: define over in the generateAnalysis method

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

1585 of 8401 relevant lines covered (18.87%)

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 overA: aDateWeekMonthOrYear [
×
13

×
14
        | commits commitSortedByDate commits1 commits2 differences groupedByDate dateOver |
×
15
        groupedByDate := self
×
16
                                 setupGroupedDateFrom: since
×
17
                                 to: until
×
18
                                 over: aDateWeekMonthOrYear.
×
NEW
19

×
20
        gitAnalyzer := GitAnalyzer new
×
21
                               onModel: glhModel;
×
22
                               glhImporter: glhImporter.
×
23

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

×
32
        commitSortedByDate := commits sorted: [ :commit1 :commit2 |
×
33
                                      commit1 committed_date
×
34
                                      < commit2 committed_date ].
×
NEW
35

×
NEW
36
        commitSortedByDate do: [ :commit |
×
NEW
37
                dateOver := self
×
NEW
38
                                    transformDate: commit committed_date
×
39
                                    to: aDateWeekMonthOrYear.
×
40

×
NEW
41
                groupedByDate
×
NEW
42
                        at: dateOver printString
×
NEW
43
                        ifPresent: [ :value | value add: commit ] ].
×
44

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

×
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.
×
52

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

×
NEW
57
                                 differences average asDuration ].
×
NEW
58

×
NEW
59

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

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

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

×
96

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

×
242

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

×
248

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

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

×
267

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

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

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

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

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

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

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

×
307

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

318
{ #category : #metrics }
319
GitMetric4User >> commitsProducedOnProject: projectId since: sinceDate until: untilDate [
×
320

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

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

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

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

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

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

×
375
        ^ aggregatedFrequencies
×
376
]
×
377

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

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

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

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

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

×
402

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

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

×
419

×
420

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

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

×
438

×
439

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

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

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

×
454

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

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

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

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

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

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

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

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

×
502

×
503

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

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

×
521

×
522

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

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

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

×
537

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

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

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

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

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

×
565
        ^ analyzingCommits
×
566
]
×
567

568
{ #category : #analysis }
NEW
569
GitMetric4User >> generateAnalysisForPeriod: period over: aDateWeekMonthOrYear withMaxCommitWindows: maxCommitWindow [
×
570

×
NEW
571
        | contribution commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn averageTimeBetweenCommits numberOfProjectWithCommit |
×
572
        contribution := self
×
573
                                codeContributionsSince: (period at: #since)
×
574
                                until: (period at: #until)
×
NEW
575
                                overA: aDateWeekMonthOrYear.
×
576

×
NEW
577
        commitFrequency := self
×
NEW
578
                                   commitFrequencySince: (period at: #since)
×
NEW
579
                                   until: (period at: #until)
×
NEW
580
                                   overA: aDateWeekMonthOrYear.
×
581

×
NEW
582
        commentContribution := self
×
NEW
583
                                       commentsContributionsSince:
×
NEW
584
                                       (period at: #since)
×
NEW
585
                                       until: (period at: #until)
×
NEW
586
                                       overA: aDateWeekMonthOrYear.
×
NEW
587

×
NEW
588
        mergeRequestDuration := self
×
NEW
589
                                        mergeRequestDurationSince:
×
590
                                        (period at: #since)
×
591
                                        until: (period at: #until)
×
NEW
592
                                        overA: aDateWeekMonthOrYear.
×
NEW
593

×
NEW
594
        codeChurn := self
×
NEW
595
                             codeChurnSince: (period at: #since)
×
NEW
596
                             until: (period at: #until)
×
NEW
597
                             onACommitWindowOf: maxCommitWindow
×
NEW
598
                             overA: aDateWeekMonthOrYear.
×
NEW
599

×
NEW
600
        delayUntilFirstChurn := self
×
NEW
601
                                        delayUntilFirstChurnSince:
×
NEW
602
                                        (period at: #since)
×
NEW
603
                                        until: (period at: #until)
×
NEW
604
                                        onACommitWindowOf: maxCommitWindow
×
NEW
605
                                        overA: aDateWeekMonthOrYear.
×
NEW
606

×
NEW
607
        numberOfProjectWithCommit := self
×
NEW
608
                                             numberOfProjectWithCommitSince:
×
NEW
609
                                             (period at: #since)
×
NEW
610
                                             until: (period at: #until)
×
NEW
611
                                             overA: aDateWeekMonthOrYear.
×
NEW
612
        averageTimeBetweenCommits := self
×
NEW
613
                                             averageTimeBetweenCommitSince:
×
NEW
614
                                             (period at: #since)
×
NEW
615
                                             until: (period at: #until)
×
NEW
616
                                             overA: aDateWeekMonthOrYear.
×
617

×
618
        ^ AnalysisReport new
×
619
                  username: self user name;
×
620
                  period: period;
×
NEW
621
                  over: aDateWeekMonthOrYear asString;
×
NEW
622
                  codeAddition: (contribution at: #avgAddition);
×
NEW
623
                  codeDeletion: (contribution at: #avgDeletion);
×
NEW
624
                  commitFrequency: (commitFrequency at: #averageFloat);
×
NEW
625
                  commentContribution: (commentContribution at: #avgComments);
×
NEW
626
                  mergeRequestDuration: (mergeRequestDuration at: #avgDuration);
×
NEW
627
                  codeChurn: (codeChurn at: #churn);
×
NEW
628
                  delayUntilFirstChurn: (delayUntilFirstChurn at: #avgDelay);
×
NEW
629
                  numberOfProjectWithCommit:
×
NEW
630
                          (numberOfProjectWithCommit at: #average);
×
NEW
631
                  averageTimeBetweenCommits:
×
NEW
632
                          (averageTimeBetweenCommits at: #average)
×
633
]
×
634

635
{ #category : #initialization }
636
GitMetric4User >> initialize [
×
637

×
638
        user := GLHUser new.
×
639
        itsProjects := Dictionary new.
×
640
        itsCommits := Dictionary new.
×
641
        itsMergeRequests := Dictionary new
×
642
]
×
643

644
{ #category : #accessing }
645
GitMetric4User >> itsProjects: projects [
×
646
        itsProjects := projects .
×
647
]
×
648

649
{ #category : #churn }
650
GitMetric4User >> loadCommitOfProjects: aCollection since: aTimespan [
×
651
        |commits|
×
652
        
×
653
        commits := (aCollection collect: [ :id |
×
654
                 glhImporter
×
655
                        importCommitsOProject: (itsProjects at: id)
×
656
                        since: aTimespan
×
657
                        until: nil ]) flattened.
×
658

×
659
        commits do: [ :commit |
×
660
                glhImporter completeImportedCommit: commit. 
×
661
                 ].
×
662

×
663
        ^ self userCommits.
×
664
]
×
665

666
{ #category : #metrics }
667
GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeekMonthOrYear [
×
668

×
669
        | mergeRequest res groupedByDate filterGroups avg |
×
670
        groupedByDate := self
×
671
                                 setupGroupedDateFrom: since
×
672
                                 to: until
×
673
                                 over: aDateWeekMonthOrYear.
×
674

×
675
        gitAnalyzer := GitAnalyzer new
×
676
                               glhImporter: glhImporter;
×
677
                               onModel: glhModel.
×
678

×
679
        glhImporter withCommitDiffs: false.
×
680
        mergeRequest := self
×
681
                                loadMergeRequestsFromProjectsIds: itsProjects keys
×
682
                                since: since
×
683
                                until: until.
×
684
        glhImporter withCommitDiffs: true.
×
685

×
686
        mergeRequest ifEmpty: [
×
687
                ^ {
×
688
                          (#avgDuration -> nil).
×
689
                          (#overEach -> aDateWeekMonthOrYear name).
×
690
                          (#forOver -> (groupedByDate keys size printString
×
691
                            , aDateWeekMonthOrYear printString)).
×
692
                          (#totalMergeRequest -> 0).
×
693
                          (#details -> nil) } asDictionary ].
×
694

×
695
        res := mergeRequest collect: [ :mr |
×
696
                       gitAnalyzer analyseMergeResquestValidation: mr ].
×
697

×
698

×
699
        res do: [ :dic |
×
700
                | overDate |
×
701
                overDate := self
×
702
                                    transformDate: (dic at: #created_at)
×
703
                                    to: aDateWeekMonthOrYear.
×
704

×
705
                groupedByDate
×
706
                        at: overDate printString
×
707
                        ifPresent: [ :durations | durations add: (dic at: #duration) ]
×
708
                        ifAbsentPut: [
×
709
                                OrderedCollection new
×
710
                                        add: (dic at: #duration);
×
711
                                        yourself ] ].
×
712

×
713

×
714
        filterGroups := groupedByDate reject: [ :array | array isEmpty ].
×
715

×
716
        filterGroups associations do: [ :assoc |
×
717
                | sum denominator |
×
718
                denominator := assoc value size.
×
719

×
720
                sum := assoc value sum: [ :v |
×
721
                               v ifNil: [
×
722
                                       denominator := denominator - 1.
×
723
                                       0 asDuration ] ].
×
724
                denominator = 0 ifTrue: [ denominator := 1 ].
×
725

×
726
                filterGroups at: assoc key put: sum / denominator ].
×
727

×
728

×
729
        filterGroups keys
×
730
                ifEmpty: [ avg := 0 ]
×
731
                ifNotEmpty: [
×
732
                avg := filterGroups values sum / filterGroups keys size ].
×
733

×
734

×
735
        ^ {
×
736
                  (#avgDuration -> avg).
×
737
                  (#overEach -> aDateWeekMonthOrYear name).
×
738
                  (#forOver -> (groupedByDate keys size printString
×
739
                    , aDateWeekMonthOrYear printString)).
×
740
                  (#totalMergeRequest -> mergeRequest size).
×
741
                  (#details -> groupedByDate) } asDictionary
×
742
]
×
743

744
{ #category : #metrics }
745
GitMetric4User >> numberOfProjectWithCommitSince: since until: until overA: aDateWeekMonthOrYear [
×
746
        | groupedByDate commits userCommits dateOver projects |
×
747
        groupedByDate := self
×
748
                                 setupGroupedDateFrom: since
×
749
                                 to: until
×
750
                                 over: aDateWeekMonthOrYear.
×
751
                
×
752
        gitAnalyzer := GitAnalyzer new
×
753
                               onModel: glhModel;
×
754
                               glhImporter: glhImporter.
×
755

×
756
        glhImporter withCommitDiffs: false.
×
757
        commits := self
×
758
                           loadCommitsFromProjectsIds: itsProjects keys
×
759
                           since: since
×
760
                           until: until.
×
761
        glhImporter withCommitDiffs: true.
×
762
        userCommits := commits reject: [ :commit | commit commitCreator ~= user ].
×
763
        
×
764

×
765
        userCommits do: [ :userCommit |
×
766
                 dateOver := self
×
767
                                    transformDate: userCommit committed_date 
×
768
                                    to: aDateWeekMonthOrYear.
×
769
                        
×
770
                groupedByDate at: dateOver printString ifPresent: [ :value | value add: (userCommit repository project) ].
×
771
        ].
×
772

×
773
        groupedByDate := groupedByDate collect: [ :group |                 
×
774
                projects := Set newFrom: group.                
×
775
                projects size.
×
776
        ].
×
777

×
778
        ^ {
×
779
                  (#overEach -> aDateWeekMonthOrYear name).
×
780
                  (#forOver -> (groupedByDate keys size printString
×
781
                    , aDateWeekMonthOrYear printString)).
×
782
                  (#average
×
783
                   ->
×
784
                   groupedByDate average asFloat).
×
785
                  (#details -> groupedByDate).
×
786
                  (#userCommits -> commits size) } asDictionary
×
787

×
788
]
×
789

790
{ #category : #accessing }
791
GitMetric4User >> user [
×
792
        ^ user
×
793
]
×
794

795
{ #category : #accessing }
796
GitMetric4User >> user: anUser [
×
797
        user := anUser. 
×
798
]
×
799

800
{ #category : #accessing }
801
GitMetric4User >> userCommits [
×
802
        ^ user commits
×
803
]
×
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