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

moosetechnology / GitProjectHealth / 10421973120

16 Aug 2024 02:59PM UTC coverage: 19.071%. First build
10421973120

Pull #30

github

web-flow
Merge c20de74b0 into 7ae7aaeb7
Pull Request #30: feat(metrics): number of project with a commit of the user

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

1585 of 8311 relevant lines covered (19.07%)

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 : #churn }
12
GitMetric4User >> codeChurnSince: since until: until onACommitWindowOf: commitLimit overA: aDateWeekMonthOrYear [
×
13

×
14
        | commits res groupedByDate totalContributions userCommits |
×
15
        "for each commit, we get its churn result (a dictionnary)"
×
16
        'GitMetric4User: code churn' recordInfo.
×
17
        totalContributions := OrderedCollection new.
×
18
        groupedByDate := self
×
19
                                 setupGroupedDateFrom: since
×
20
                                 to: until
×
21
                                 over: aDateWeekMonthOrYear.
×
22
        gitAnalyzer := GitAnalyzer new
×
23
                               glhImporter: glhImporter;
×
24
                               onModel: glhModel;
×
25
                               maxChildCommit: commitLimit.
×
26
        glhImporter withCommitDiffs: false.
×
27
        commits := self
×
28
                           loadCommitsFromProjectsIds: itsProjects keys
×
29
                           since: since
×
30
                           until: until.
×
31
        glhImporter withCommitDiffs: true.
×
32
        userCommits := commits reject: [ :commit |
×
33
                               commit commitCreator ~= user ].
×
34
        commits := self
×
35
                           foundSuccessorOf: userCommits
×
36
                           andCompleteImportForMax: commitLimit.
×
37

×
38

×
39
        res := commits collect: [ :commit |
×
40
                       commit -> (gitAnalyzer
×
41
                                fromCommit: commit;
×
42
                                analyseChurn) ].
×
43
        res do: [ :commits4Churns |
×
44
                | commit allChurnsInCommit sumChurnInCommit overDate contribution churnOnCommit |
×
45
                commit := commits4Churns key.
×
46
                allChurnsInCommit := commits4Churns value.
×
47
                sumChurnInCommit := (allChurnsInCommit at: #churns) sum: [ :churn |
×
48
                                            | numerator |
×
49
                                            numerator := churn value at: #churnLoC.
×
50
                                            numerator ].
×
51
                contribution := allChurnsInCommit at: #totalContribution.
×
52
                totalContributions add: contribution.
×
53
                churnOnCommit := {
×
54
                                         (#churnOnCommit -> sumChurnInCommit).
×
55
                                         (#LoCOnCommit -> contribution) } asDictionary.
×
56
                overDate := self
×
57
                                    transformDate: commit created_at
×
58
                                    to: aDateWeekMonthOrYear.
×
59
                groupedByDate
×
60
                        at: overDate printString
×
61
                        ifPresent: [ :array | array add: churnOnCommit ]
×
62
                        ifAbsentPut: [
×
63
                                OrderedCollection new
×
64
                                        add: churnOnCommit;
×
65
                                        yourself ] ].
×
66
        groupedByDate := groupedByDate collect: [ :churnsAtDate |
×
67
                                 | totalChurn totalContribution percentage |
×
68
                                 totalChurn := churnsAtDate sum: [ :churn |
×
69
                                                       churn at: #churnOnCommit ].
×
70
                                 totalContribution := churnsAtDate sum: [ :churn |
×
71
                                                              churn at: #LoCOnCommit ].
×
72
                                 totalContribution = 0
×
73
                                         ifTrue: [ percentage := 0 asFloat ]
×
74
                                         ifFalse: [
×
75
                                         percentage := (totalChurn * 100
×
76
                                                        / totalContribution) asFloat ].
×
77
                                 {
×
78
                                         (#churn -> totalChurn).
×
79
                                         (#contribution -> totalContribution).
×
80
                                         (#percentage -> percentage) } asDictionary ].
×
81
        ^ {
×
82
                  (#details -> groupedByDate).
×
83
                  (#totalContribution -> (totalContributions
×
84
                            ifEmpty: [ 0 ]
×
85
                            ifNotEmpty: [ totalContributions sum ])).
×
86
                  (#totalChurn -> (groupedByDate sum: [ :date | date at: #churn ])).
×
87
                  (#churn
×
88
                   ->
×
89
                   (groupedByDate collect: [ :date | date at: #percentage ]) average).
×
90
                  (#overEach -> aDateWeekMonthOrYear name).
×
91
                  (#forOver -> (groupedByDate keys size printString
×
92
                    , aDateWeekMonthOrYear printString)).
×
93
                  (#userCommits -> commits size).
×
94
                  (#churnWindow -> commitLimit) } asDictionary
×
95
]
×
96

97
{ #category : #metrics }
98
GitMetric4User >> codeContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
99

×
100
        | commits contributions groupedByDate |
×
101
        'GitMetric4User: code contribution' recordInfo.
×
102

×
103
        groupedByDate := self
×
104
                                 setupGroupedDateFrom: since
×
105
                                 to: until
×
106
                                 over: aDateWeekMonthOrYear.
×
107

×
108
        gitAnalyzer := GitAnalyzer new
×
109
                               onModel: glhModel;
×
110
                               glhImporter: glhImporter.
×
111

×
112
        glhImporter withCommitDiffs: false.
×
113
        commits := self
×
114
                           loadCommitsFromProjectsIds: itsProjects keys
×
115
                           since: since
×
116
                           until: until.
×
117
        glhImporter withCommitDiffs: true.
×
118
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
119

×
120
        contributions := commits collect: [ :commit |
×
121
                                 commit -> (gitAnalyzer
×
122
                                          fromCommit: commit;
×
123
                                          analyseCommitContribution) ].
×
124

×
125
        contributions do: [ :assoc |
×
126
                | dateOver |
×
127
                dateOver := self
×
128
                                    transformDate: assoc key created_at
×
129
                                    to: aDateWeekMonthOrYear.
×
130
                groupedByDate
×
131
                        at: dateOver printString
×
132
                        ifPresent: [ :v | v add: assoc value ]
×
133
                        ifAbsentPut: [
×
134
                                OrderedCollection new
×
135
                                        add: assoc value;
×
136
                                        yourself ] ].
×
137

×
138
        groupedByDate := groupedByDate collect: [ :contribs |
×
139
                                 | totalAdd totalDele |
×
140
                                 totalAdd := contribs sum: [ :v | v at: #addition ].
×
141
                                 totalDele := contribs sum: [ :v | v at: #deletion ].
×
142
                                 {
×
143
                                         (#addition -> totalAdd).
×
144
                                         (#deletion -> totalDele) } asDictionary ].
×
145

×
146
        ^ {
×
147
                  (#overEach -> aDateWeekMonthOrYear name).
×
148
                  (#forOver -> (groupedByDate keys size printString
×
149
                    , aDateWeekMonthOrYear printString)).
×
150
                  (#avgAddition
×
151
                   ->
×
152
                   (groupedByDate collect: [ :d | d at: #addition ]) average asFloat).
×
153
                  (#avgDeletion
×
154
                   ->
×
155
                   (groupedByDate collect: [ :d | d at: #deletion ]) average asFloat).
×
156
                  (#details -> groupedByDate).
×
157
                  (#userCommits -> commits size) } asDictionary
×
158
]
×
159

160
{ #category : #metrics }
161
GitMetric4User >> commentsContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
162

×
163
        | commits contributions groupedByDate |
×
164
        'GitMetric4User: comment contribution' recordInfo.
×
165

×
166
        groupedByDate := self
×
167
                                 setupGroupedDateFrom: since
×
168
                                 to: until
×
169
                                 over: aDateWeekMonthOrYear.
×
170

×
171
        gitAnalyzer := GitAnalyzer new
×
172
                               onModel: glhModel;
×
173
                               glhImporter: glhImporter.
×
174

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

×
184

×
185
        contributions := commits collect: [ :commit |
×
186
                                 commit -> (gitAnalyzer
×
187
                                          fromCommit: commit;
×
188
                                          analyseCommentContribution) ].
×
189

×
190

×
191
        contributions do: [ :assoc |
×
192
                | dateOver |
×
193
                dateOver := self
×
194
                                    transformDate: assoc key created_at
×
195
                                    to: aDateWeekMonthOrYear.
×
196
                groupedByDate
×
197
                        at: dateOver printString
×
198
                        ifPresent: [ :v | v add: assoc value ]
×
199
                        ifAbsentPut: [
×
200
                                OrderedCollection new
×
201
                                        add: assoc value;
×
202
                                        yourself ] ].
×
203

×
204
        groupedByDate := groupedByDate collect: [ :contribs |
×
205
                                 contribs
×
206
                                         ifNotEmpty: [ contribs sum ]
×
207
                                         ifEmpty: [ 0 ] ].
×
208

×
209

×
210
        ^ {
×
211
                  (#details -> groupedByDate).
×
212
                  (#totalComments -> groupedByDate values sum).
×
213
                  (#avgComments -> groupedByDate values average asFloat).
×
214
                  (#overEach -> aDateWeekMonthOrYear name).
×
215
                  (#forOver -> (groupedByDate keys size printString
×
216
                    , aDateWeekMonthOrYear printString)).
×
217
                  (#userCommits -> commits size) } asDictionary
×
218
]
×
219

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

×
223
        | periods total groupedByDate userCommits |
×
224
        'GitMetric4User: commit frequency' recordInfo.
×
225

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

×
231
        glhImporter withCommitDiffs: false.
×
232
        userCommits := self
×
233
                               loadCommitsFromProjectsIds: itsProjects keys
×
234
                               since: since
×
235
                               until: until.
×
236
        glhImporter withCommitDiffs: true.
×
237
        userCommits := userCommits reject: [ :c | c commitCreator ~= user ].
×
238

×
239
        userCommits do: [ :c |
×
240
                | dateOver |
×
241
                dateOver := self
×
242
                                    transformDate: c created_at
×
243
                                    to: aDateWeekMonthOrYear.
×
244
                groupedByDate at: dateOver printString ifPresent: [ :v | v add: c ] ].
×
245

×
246
        periods := groupedByDate keys size.
×
247
        total := groupedByDate values sum: [ :commits | commits size ].
×
248

×
249

×
250
        ^ {
×
251
                  (#averageFrac -> (total / periods)).
×
252
                  (#averageFloat -> (total / periods) asFloat).
×
253
                  (#userCommit -> total).
×
254
                  (#forOver -> (groupedByDate keys size printString
×
255
                    , aDateWeekMonthOrYear printString)).
×
256
                  (#periode -> aDateWeekMonthOrYear name).
×
257
                  (#details -> groupedByDate) } asOrderedDictionary
×
258
]
×
259

260
{ #category : #'as yet unclassified' }
261
GitMetric4User >> commitsProducedOnProject: projectId since: sinceDate until: untilDate [
×
262

×
263
        | frequencies |
×
264
        
×
265
        
×
266
        gitAnalyzer := GitAnalyzer new 
×
267
        glhImporter: glhImporter; 
×
268
        onModel: glhModel.
×
269
         
×
270
        frequencies := gitAnalyzer
×
271
                               onProject: (itsProjects at: projectId);
×
272
                               analyseCommitFrequencySince: sinceDate
×
273
                               until: untilDate. 
×
274
        
×
275
        "complete each commit "
×
276
        frequencies values flattened do: [ :commit |
×
277
                glhImporter completeImportedCommit: commit.
×
278
                 ].
×
279
        
×
280
        "Filter the associations in the 'frequencies' collection, removing any commits not created by the specified 'user'. "
×
281
        frequencies associations do: [ :assoc |
×
282
                |commits| 
×
283
                commits := assoc value.
×
284
                assoc value: (commits reject: [ :commit | commit commitCreator ~= user ]). 
×
285
        ].
×
286
        
×
287
        ^ frequencies 
×
288
]
×
289

290
{ #category : #metrics }
291
GitMetric4User >> commitsProducedOnProject: aProjectId since: since until: until overA: aWeekOrMonthOrYear [
×
292
        "'aWeekOrMonthOrYear' should be the class of Data, Week, Month or Year"
×
293

×
294
        | frequency aggregatedFrequencies |
×
295
        aggregatedFrequencies := self
×
296
                                         setupGroupedDateFrom: since
×
297
                                         to: until
×
298
                                         over: aWeekOrMonthOrYear.
×
299

×
300
        frequency := self
×
301
                             commitsProducedOnProject: aProjectId
×
302
                             since: since
×
303
                             until: until.
×
304

×
305
        frequency associations do: [ :assoc |
×
306
                | date commits overDate |
×
307
                date := assoc key.
×
308
                commits := assoc value.
×
309

×
310
                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 "
×
311
                        overDate := self transformDate: date to: aWeekOrMonthOrYear.
×
312
                        aggregatedFrequencies
×
313
                                at: overDate printString
×
314
                                ifPresent: [ :collection | collection addAll: commits ]
×
315
                                ifAbsentPut: [ commits ] ] ].
×
316

×
317
        ^ aggregatedFrequencies
×
318
]
×
319

320
{ #category : #churn }
321
GitMetric4User >> delayUntilFirstChurnSince: since until: until onACommitWindowOf: maxCommitWindow overA: aDateWeekMonthOrYear [
×
322

×
323
        | commits groupedByDate res avg userCommits |
×
324
        'GitMetric4User: delay until first churn' recordInfo.
×
325

×
326
        groupedByDate := self
×
327
                                 setupGroupedDateFrom: since
×
328
                                 to: until
×
329
                                 over: aDateWeekMonthOrYear.
×
330

×
331
        glhImporter withCommitDiffs: false.
×
332
        commits := self
×
333
                           loadCommitsFromProjectsIds: itsProjects keys
×
334
                           since: since
×
335
                           until: until.
×
336
        glhImporter withCommitDiffs: true.
×
337

×
338
        userCommits := commits reject: [ :commit |
×
339
                               commit commitCreator ~= user ].
×
340
        commits := self
×
341
                           foundSuccessorOf: userCommits
×
342
                           andCompleteImportForMax: maxCommitWindow.
×
343

×
344

×
345
        "class commit by dates, filter none user commits"
×
346
        commits do: [ :commit |
×
347
                commit commitCreator = user ifTrue: [
×
348
                        | overDate |
×
349
                        overDate := self
×
350
                                            transformDate: commit created_at
×
351
                                            to: aDateWeekMonthOrYear.
×
352

×
353
                        groupedByDate
×
354
                                at: overDate printString
×
355
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
356
                                ifAbsentPut: [
×
357
                                        OrderedCollection new
×
358
                                                add: commit;
×
359
                                                yourself ] ] ].
×
360

×
361

×
362

×
363
        res := groupedByDate collect: [ :commits4Date |
×
364
                       | durationFromA2B |
×
365
                       commits4Date collect: [ :commitA |
×
366
                               | commitB |
×
367
                               commitB := GitAnalyzer new
×
368
                                                  glhImporter: glhImporter;
×
369
                                                  onModel: glhModel;
×
370
                                                  fromCommit: commitA;
×
371
                                                  maxChildCommit: maxCommitWindow;
×
372
                                                  analyseDelayUntilFirstChurn.
×
373

×
374
                               durationFromA2B := commitB
×
375
                                                          ifNil: [ 0 ]
×
376
                                                          ifNotNil: [
×
377
                                                          commitB created_at - commitA created_at ].
×
378
                               durationFromA2B ] ].
×
379

×
380

×
381

×
382
        res := res collect: [ :durationsByDate |
×
383
                       | filtered |
×
384
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
385
                       filtered isEmpty
×
386
                               ifTrue: [ nil ]
×
387
                               ifFalse: [
×
388
                               (filtered sum: [ :v | v asDuration asSeconds]) / filtered size ] ].
×
389

×
390
        res := res reject: #isNil.
×
391

×
392
        res
×
393
                ifEmpty: [ avg := nil ]
×
394
                ifNotEmpty: [ avg := res values average asFloat ].
×
395

×
396

×
397
        ^ {
×
398
                  (#avgDelay -> avg).
×
399
                  (#overEach -> aDateWeekMonthOrYear name).
×
400
                  (#forOver -> (groupedByDate keys size printString
×
401
                    , aDateWeekMonthOrYear printString)).
×
402
                  (#details -> groupedByDate) } asDictionary
×
403
]
×
404

405
{ #category : #churn }
406
GitMetric4User >> delayUntilFirstChurnSince: since until: until overA: aDateWeekMonthOrYear [
×
407

×
408
        | commits groupedByDate res avg |
×
409
        self
×
410
                deprecated:
×
411
                'Use #delayUntilFirstChurnSince:until:onACommitWindowOf:overA: instead'
×
412
                on: '1 July 2024'
×
413
                in:
×
414
                'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
×
415

×
416
        'GitMetric4User: delay until first churn' recordInfo.
×
417

×
418
        groupedByDate := self
×
419
                                 setupGroupedDateFrom: since
×
420
                                 to: until
×
421
                                 over: aDateWeekMonthOrYear.
×
422

×
423
        commits := self
×
424
                           loadCommitsFromProjectsIds: itsProjects keys
×
425
                           since: since
×
426
                           until: until.
×
427

×
428
        "class commit by dates, filter none user commits"
×
429
        commits do: [ :commit |
×
430
                commit commitCreator = user ifTrue: [
×
431
                        | overDate |
×
432
                        overDate := self
×
433
                                            transformDate: commit created_at
×
434
                                            to: aDateWeekMonthOrYear.
×
435

×
436
                        groupedByDate
×
437
                                at: overDate printString
×
438
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
439
                                ifAbsentPut: [
×
440
                                        OrderedCollection new
×
441
                                                add: commit;
×
442
                                                yourself ] ] ].
×
443

×
444

×
445

×
446
        res := groupedByDate collect: [ :commits4Date |
×
447
                       | durationFromA2B |
×
448
                       commits4Date collect: [ :commitA |
×
449
                               | commitB |
×
450
                               commitB := GitAnalyzer new
×
451
                                                  glhImporter: glhImporter;
×
452
                                                  onModel: glhModel;
×
453
                                                  fromCommit: commitA;
×
454
                                                  maxChildCommit: 5;
×
455
                                                  analyseDelayUntilFirstChurn.
×
456

×
457
                               durationFromA2B := commitB
×
458
                                                          ifNil: [ 0 ]
×
459
                                                          ifNotNil: [
×
460
                                                          commitB created_at - commitA created_at ].
×
461
                               durationFromA2B ] ].
×
462

×
463

×
464

×
465
        res := res collect: [ :durationsByDate |
×
466
                       | filtered |
×
467
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
468
                       filtered isEmpty
×
469
                               ifTrue: [ nil ]
×
470
                               ifFalse: [
×
471
                               (filtered sum: [ :v | v asDuration ]) / filtered size ] ].
×
472

×
473
        res := res reject: #isNil.
×
474

×
475
        res
×
476
                ifEmpty: [ avg := nil ]
×
477
                ifNotEmpty: [ avg := res values sum / res keys size ].
×
478

×
479

×
480
        ^ {
×
481
                  (#avgDelay -> avg).
×
482
                  (#overEach -> aDateWeekMonthOrYear name).
×
483
                  (#forOver -> (groupedByDate keys size printString
×
484
                    , aDateWeekMonthOrYear printString)).
×
485
                  (#details -> groupedByDate) } asDictionary
×
486
]
×
487

488
{ #category : #churn }
489
GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitLimit [
×
490

×
491
        | analyzingCommits i size|
×
492
        analyzingCommits := Set new.
×
493
        glhImporter withCommitDiffs: true.
×
494

×
495
        userCommits do: [ :c |
×
496
                gitAnalyzer
×
497
                        visitChildCommits: c childCommits
×
498
                        toStoreThemIn: analyzingCommits
×
499
                        upto: commitLimit ].
×
500

×
501
        i := 0.
×
502
        size := analyzingCommits size. 
×
503
        analyzingCommits do: [ :c |
×
504
                ('import complete commits  [' , (i:=i+1) printString, '/', size printString , ']'  ) recordInfo.
×
505
                glhImporter completeImportedCommit: c ].
×
506

×
507
        ^ analyzingCommits
×
508
]
×
509

510
{ #category : #'as yet unclassified' }
511
GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWindows: maxCommitWindow [
×
512

×
NEW
513
        | contribution codeAddition codeDeletion commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn numberOfProjectWithCommit |
×
514
        
×
515
        contribution := self
×
516
                                codeContributionsSince: (period at: #since)
×
517
                                until: (period at: #until)
×
518
                                overA: over.
×
519
        codeAddition := contribution at: #avgAddition.
×
520
        codeDeletion := contribution at: #avgDeletion.
×
521

×
522
        commitFrequency := (self
×
523
                                    commitFrequencySince: (period at: #since)
×
524
                                    until: (period at: #until)
×
525
                                    overA: over) at: #averageFloat.
×
526

×
527
        commentContribution := (self
×
528
                                        commentsContributionsSince:
×
529
                                        (period at: #since)
×
530
                                        until: (period at: #until)
×
531
                                        overA: over) at: #avgComments.
×
532

×
533
        mergeRequestDuration := (self
×
534
                                         mergeRequestDurationSince:
×
535
                                         (period at: #since)
×
536
                                         until: (period at: #until)
×
537
                                         overA: over) at: #avgDuration.
×
538

×
539
        codeChurn := (self
×
540
                              codeChurnSince: (period at: #since)
×
541
                              until: (period at: #until)
×
542
                              onACommitWindowOf: maxCommitWindow
×
543
                              overA: over) at: #churn.
×
544

×
545
        delayUntilFirstChurn := (self
×
546
                                         delayUntilFirstChurnSince:
×
547
                                         (period at: #since)
×
548
                                         until: (period at: #until)
×
549
                                         onACommitWindowOf: maxCommitWindow
×
550
                                         overA: over) at: #avgDelay.
×
NEW
551
                
×
NEW
552
        numberOfProjectWithCommit := self numberOfProjectWithCommitSince: (period at: #since) until: (period at: #until) overA: over.
×
NEW
553
        
×
554
        ^ AnalysisReport new
×
555
                  username: self user name;
×
556
                  period: period;
×
557
                  codeAddition: codeAddition;
×
558
                  codeDeletion: codeDeletion;
×
559
                  commitFrequency: commitFrequency;
×
560
                  commentContribution: commentContribution;
×
561
                  mergeRequestDuration: mergeRequestDuration;
×
562
                  codeChurn: codeChurn;
×
NEW
563
                  delayUntilFirstChurn: delayUntilFirstChurn;
×
NEW
564
                numberOfProjectWithCommit: (numberOfProjectWithCommit at: #average)
×
565
]
×
566

567
{ #category : #initialization }
568
GitMetric4User >> initialize [
×
569

×
570
        user := GLHUser new.
×
571
        itsProjects := Dictionary new.
×
572
        itsCommits := Dictionary new.
×
573
        itsMergeRequests := Dictionary new
×
574
]
×
575

576
{ #category : #accessing }
577
GitMetric4User >> itsProjects: projects [
×
578
        itsProjects := projects .
×
579
]
×
580

581
{ #category : #churn }
582
GitMetric4User >> loadCommitOfProjects: aCollection since: aTimespan [
×
583
        |commits|
×
584
        
×
585
        commits := (aCollection collect: [ :id |
×
586
                 glhImporter
×
587
                        importCommitsOProject: (itsProjects at: id)
×
588
                        since: aTimespan
×
589
                        until: nil ]) flattened.
×
590

×
591
        commits do: [ :commit |
×
592
                glhImporter completeImportedCommit: commit. 
×
593
                 ].
×
594

×
595
        ^ self userCommits.
×
596
]
×
597

598
{ #category : #metrics }
599
GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeekMonthOrYear [
×
600

×
601
        | mergeRequest res groupedByDate filterGroups avg |
×
602
        groupedByDate := self
×
603
                                 setupGroupedDateFrom: since
×
604
                                 to: until
×
605
                                 over: aDateWeekMonthOrYear.
×
606

×
607
        gitAnalyzer := GitAnalyzer new
×
608
                               glhImporter: glhImporter;
×
609
                               onModel: glhModel.
×
610

×
611
        glhImporter withCommitDiffs: false.
×
612
        mergeRequest := self
×
613
                                loadMergeRequestsFromProjectsIds: itsProjects keys
×
614
                                since: since
×
615
                                until: until.
×
616
        glhImporter withCommitDiffs: true.
×
617

×
618
        mergeRequest ifEmpty: [
×
619
                ^ {
×
620
                          (#avgDuration -> nil).
×
621
                          (#overEach -> aDateWeekMonthOrYear name).
×
622
                          (#forOver -> (groupedByDate keys size printString
×
623
                            , aDateWeekMonthOrYear printString)).
×
624
                          (#totalMergeRequest -> 0).
×
625
                          (#details -> nil) } asDictionary ].
×
626

×
627
        res := mergeRequest collect: [ :mr |
×
628
                       gitAnalyzer analyseMergeResquestValidation: mr ].
×
629

×
630

×
631
        res do: [ :dic |
×
632
                | overDate |
×
633
                overDate := self
×
634
                                    transformDate: (dic at: #created_at)
×
635
                                    to: aDateWeekMonthOrYear.
×
636

×
637
                groupedByDate
×
638
                        at: overDate printString
×
639
                        ifPresent: [ :durations | durations add: (dic at: #duration) ]
×
640
                        ifAbsentPut: [
×
641
                                OrderedCollection new
×
642
                                        add: (dic at: #duration);
×
643
                                        yourself ] ].
×
644

×
645

×
646
        filterGroups := groupedByDate reject: [ :array | array isEmpty ].
×
647

×
648
        filterGroups associations do: [ :assoc |
×
649
                | sum denominator |
×
650
                denominator := assoc value size.
×
651

×
652
                sum := assoc value sum: [ :v |
×
653
                               v ifNil: [
×
654
                                       denominator := denominator - 1.
×
655
                                       0 asDuration ] ].
×
656
                denominator = 0 ifTrue: [ denominator := 1 ].
×
657

×
658
                filterGroups at: assoc key put: sum / denominator ].
×
659

×
660

×
661
        filterGroups keys
×
662
                ifEmpty: [ avg := 0 ]
×
663
                ifNotEmpty: [
×
664
                avg := filterGroups values sum / filterGroups keys size ].
×
665

×
666

×
667
        ^ {
×
668
                  (#avgDuration -> avg).
×
669
                  (#overEach -> aDateWeekMonthOrYear name).
×
670
                  (#forOver -> (groupedByDate keys size printString
×
671
                    , aDateWeekMonthOrYear printString)).
×
672
                  (#totalMergeRequest -> mergeRequest size).
×
673
                  (#details -> groupedByDate) } asDictionary
×
674
]
×
675

676
{ #category : #metrics }
NEW
677
GitMetric4User >> numberOfProjectWithCommitSince: since until: until overA: aDateWeekMonthOrYear [
×
NEW
678
        | groupedByDate commits userCommits dateOver projects |
×
NEW
679
        groupedByDate := self
×
NEW
680
                                 setupGroupedDateFrom: since
×
NEW
681
                                 to: until
×
NEW
682
                                 over: aDateWeekMonthOrYear.
×
NEW
683
                
×
NEW
684
        gitAnalyzer := GitAnalyzer new
×
NEW
685
                               onModel: glhModel;
×
NEW
686
                               glhImporter: glhImporter.
×
NEW
687

×
NEW
688
        glhImporter withCommitDiffs: false.
×
NEW
689
        commits := self
×
NEW
690
                           loadCommitsFromProjectsIds: itsProjects keys
×
NEW
691
                           since: since
×
NEW
692
                           until: until.
×
NEW
693
        glhImporter withCommitDiffs: true.
×
NEW
694
        userCommits := commits reject: [ :commit | commit commitCreator ~= user ].
×
NEW
695
        
×
NEW
696

×
NEW
697
        userCommits do: [ :userCommit |
×
NEW
698
                 dateOver := self
×
NEW
699
                                    transformDate: userCommit committed_date 
×
NEW
700
                                    to: aDateWeekMonthOrYear.
×
NEW
701
                        
×
NEW
702
                groupedByDate at: dateOver printString ifPresent: [ :value | value add: (userCommit repository project) ].
×
NEW
703
        ].
×
NEW
704

×
NEW
705
        groupedByDate := groupedByDate collect: [ :group |                 
×
NEW
706
                projects := Set newFrom: group.                
×
NEW
707
                projects size.
×
NEW
708
        ].
×
NEW
709

×
NEW
710
        ^ {
×
NEW
711
                  (#overEach -> aDateWeekMonthOrYear name).
×
NEW
712
                  (#forOver -> (groupedByDate keys size printString
×
NEW
713
                    , aDateWeekMonthOrYear printString)).
×
NEW
714
                  (#average
×
NEW
715
                   ->
×
NEW
716
                   groupedByDate average asFloat).
×
NEW
717
                  (#details -> groupedByDate).
×
NEW
718
                  (#userCommits -> commits size) } asDictionary
×
NEW
719

×
NEW
720
]
×
721

722
{ #category : #accessing }
723
GitMetric4User >> user [
×
724
        ^ user
×
725
]
×
726

727
{ #category : #accessing }
728
GitMetric4User >> user: anUser [
×
729
        user := anUser. 
×
730
]
×
731

732
{ #category : #accessing }
733
GitMetric4User >> userCommits [
×
734
        ^ user commits
×
735
]
×
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