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

moosetechnology / GitProjectHealth / 9681022804

26 Jun 2024 01:56PM UTC coverage: 29.585% (+2.7%) from 26.896%
9681022804

Pull #7

github

web-flow
Merge 1d2c206b6 into dfd76b711
Pull Request #7: Optimize code and writting tests

513 of 1111 new or added lines in 11 files covered. (46.17%)

16 existing lines in 3 files now uncovered.

2176 of 7355 relevant lines covered (29.59%)

0.3 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 : #Object,
4
        #instVars : [
5
                'user',
6
                'itsProjects',
7
                'itsGroups',
8
                'itsCommits',
9
                'gitAnalyzer',
10
                'glhModel',
11
                'glhImporter',
12
                'itsMergeRequests'
13
        ],
14
        #category : #'GitLabHealth-Model-Analysis'
15
}
16

17
{ #category : #churn }
18
GitMetric4User >> codeChurnSince: since until: until onACommitWindowOf: commitLimit overA: aDateWeekMonthOrYear [
×
19

×
20
        | commits res groupedByDate totalContributions |
×
21
        
×
22
                ('GitMetric4User: code churn')
×
23
                recordInfo.
×
24
        
×
25
        totalContributions := OrderedCollection new.
×
26
                groupedByDate := self
×
27
                                 setupGroupedDateFrom: since
×
28
                                 to: until
×
29
                                 over: aDateWeekMonthOrYear.
×
30
        gitAnalyzer := GitAnalyzer new
×
31
                               glhImporter: glhImporter;
×
32
                               onModel: glhModel;
×
33
                               maxChildCommit: commitLimit.
×
34

×
35
        commits := self
×
36
                           loadCommitOfProjects: itsProjects keys
×
37
                           since: since
×
38
                           until: until.
×
39
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
40

×
41

×
42
        "for each commit, we get its churn result (a dictionnary)"
×
43
        res := commits collect: [ :commit |
×
44
                       commit -> (gitAnalyzer
×
45
                                fromCommit: commit;
×
46
                                analyseChurn) ].
×
47

×
48

×
NEW
49
        res do: [ :commits4Churns |
×
NEW
50
                | commit allChurnsInCommit sumChurnInCommit overDate contribution churnOnCommit|
×
NEW
51
                commit := commits4Churns key.
×
NEW
52
                allChurnsInCommit := commits4Churns value.
×
NEW
53
                sumChurnInCommit := (allChurnsInCommit at: #churns) sum: [ :churn |
×
54
                                    | numerator |
×
NEW
55
                                    numerator := churn value at: #churnLoC .
×
NEW
56
                                                        "debug halt"
×
NEW
57
                                                        self haltIf: [ numerator = -1 ].
×
NEW
58
                                                        numerator.             
×
NEW
59
                         ].
×
NEW
60
                contribution := allChurnsInCommit at: #totalContribution.
×
61
                totalContributions add: contribution.
×
NEW
62
                
×
NEW
63
                churnOnCommit := { (#churnOnCommit -> sumChurnInCommit). (#LoCOnCommit -> contribution). } asDictionary.
×
NEW
64
                
×
65
                overDate := self
×
66
                                    transformDate: commit created_at
×
67
                                    to: aDateWeekMonthOrYear.
×
68
                groupedByDate
×
69
                        at: overDate printString
×
NEW
70
                        ifPresent: [ :array | array add: churnOnCommit ]
×
71
                        ifAbsentPut: [
×
72
                                OrderedCollection new
×
NEW
73
                                        add: churnOnCommit;
×
74
                                        yourself ] ].
×
75

×
76

×
NEW
77
        groupedByDate := groupedByDate collect: [ :churnsAtDate |
×
NEW
78
                                 | totalChurn totalContribution percentage|
×
NEW
79
                                 totalChurn := churnsAtDate sum: [ :churn |
×
NEW
80
                                                                                                        
×
NEW
81
                                                       churn at: #churnOnCommit ].
×
NEW
82
                                 totalContribution := churnsAtDate sum: [ :churn |
×
NEW
83
                                                              churn at: #LoCOnCommit ].
×
NEW
84
                                                         (totalContribution = 0) ifTrue: [ percentage := 0 asFloat ] ifFalse: [ percentage := (((totalChurn * 100) / totalContribution) asFloat)  ].
×
NEW
85
                                                        "percentage := (((totalChurn * 100) / totalContribution) asFloat)"
×
NEW
86
                                                        { (#churn -> totalChurn) . (#contribution -> totalContribution) . (#percentage ->  percentage) } asDictionary 
×
NEW
87
                                  ].
×
88

×
89
        ^ {
×
90
                  (#details -> groupedByDate).
×
91
                  (#totalContribution -> (totalContributions ifEmpty: [ 0 ] ifNotEmpty: [ totalContributions sum ]) ).
×
NEW
92
                  (#totalChurn -> (groupedByDate sum: [ :date | date at: #churn ])).
×
NEW
93
                  
×
NEW
94
"                (
×
NEW
95
                #churn -> ((groupedByDate sum: [ :frac | frac numerator ]) ->
×
NEW
96
                     (groupedByDate sum: [ :frac | frac denominator ]))
×
NEW
97
                )."
×
NEW
98
                (
×
NEW
99
                #churn -> ((groupedByDate collect: [:date | date at: #percentage]) average )
×
NEW
100
                ).
×
NEW
101
                
×
102
                  (#overEach -> aDateWeekMonthOrYear name).
×
103
                  (#forOver -> (groupedByDate keys size printString
×
104
                    , aDateWeekMonthOrYear printString)).
×
105
                  (#userCommits -> commits size).
×
106
                  (#churnWindow -> commitLimit) } asDictionary
×
107
]
×
UNCOV
108

×
UNCOV
109
{ #category : #metrics }
×
110
GitMetric4User >> codeContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
111

×
112
        | commits contributions groupedByDate |
×
113
        
×
114
                        ('GitMetric4User: code contribution') recordInfo.
×
115
        
×
116
                glhImporter withCommitDiffs: false.
×
117
        
×
118
                groupedByDate := self
×
119
                                 setupGroupedDateFrom: since
×
120
                                 to: until
×
121
                                 over: aDateWeekMonthOrYear.
×
122
                
×
123
        gitAnalyzer := GitAnalyzer new
×
124
                               onModel: glhModel;
×
125
                               glhImporter: glhImporter.
×
126

×
127
        commits := self
×
128
                           loadCommitOfProjects: itsProjects keys
×
129
                           since: since
×
130
                           until: until.
×
131
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
132

×
133
        contributions := commits collect: [ :commit |
×
134
                                 commit -> (gitAnalyzer
×
135
                                          fromCommit: commit;
×
136
                                          analyseCommitContribution) ].
×
137

×
138
        contributions do: [ :assoc |
×
139
                | dateOver |
×
140
                dateOver := self
×
141
                                    transformDate: assoc key created_at
×
142
                                    to: aDateWeekMonthOrYear.
×
143
                groupedByDate
×
144
                        at: dateOver printString
×
145
                        ifPresent: [ :v | v add: assoc value ]
×
146
                        ifAbsentPut: [
×
147
                                OrderedCollection new
×
148
                                        add: assoc value;
×
149
                                        yourself ] ].
×
150

×
151
        groupedByDate := groupedByDate collect: [ :contribs |
×
152
                                 | totalAdd totalDele |
×
153
                                 totalAdd := contribs sum: [ :v | v at: #addition ].
×
154
                                 totalDele := contribs sum: [ :v | v at: #deletion ].
×
155
                                 {
×
156
                                         (#addition -> totalAdd).
×
157
                                         (#deletion -> totalDele) } asDictionary ].
×
158

×
159
                glhImporter withCommitDiffs: true.
×
160

×
161
        ^ {
×
162
                  (#overEach -> aDateWeekMonthOrYear name).
×
163
                  (#forOver -> (groupedByDate keys size printString
×
164
                    , aDateWeekMonthOrYear printString)).
×
NEW
165
                  (#avgAddition -> (groupedByDate collect: [:d | d at: #addition]) average asFloat ).
×
NEW
166
                  (#avgDeletion -> (groupedByDate collect: [:d | d at: #deletion]) average asFloat ).
×
167
                  (#details -> groupedByDate).
×
168
                  (#userCommits -> commits size) } asDictionary
×
169
]
×
UNCOV
170

×
UNCOV
171
{ #category : #metrics }
×
172
GitMetric4User >> commentsContributionsSince: since until: until overA: aDateWeekMonthOrYear [
×
173

×
174
        | commits contributions groupedByDate |
×
NEW
175
        'GitMetric4User: comment contribution' recordInfo.
×
NEW
176

×
177
        groupedByDate := self
×
178
                                 setupGroupedDateFrom: since
×
179
                                 to: until
×
180
                                 over: aDateWeekMonthOrYear.
×
181

×
182
        gitAnalyzer := GitAnalyzer new
×
183
                               onModel: glhModel;
×
184
                               glhImporter: glhImporter.
×
185

×
186
        commits := self
×
187
                           loadCommitOfProjects: itsProjects keys
×
188
                           since: since
×
189
                           until: until.
×
190
        commits := commits reject: [ :commit | commit commitCreator ~= user ].
×
191

×
192
        contributions := commits collect: [ :commit |
×
193
                                 commit -> (gitAnalyzer
×
194
                                          fromCommit: commit;
×
195
                                          analyseCommentContributions) ].
×
196

×
197

×
198
        contributions do: [ :assoc |
×
199
                | dateOver |
×
200
                dateOver := self
×
201
                                    transformDate: assoc key created_at
×
202
                                    to: aDateWeekMonthOrYear.
×
203
                groupedByDate
×
204
                        at: dateOver printString
×
205
                        ifPresent: [ :v | v add: assoc value ]
×
206
                        ifAbsentPut: [
×
207
                                OrderedCollection new
×
208
                                        add: assoc value;
×
209
                                        yourself ] ].
×
210

×
211
        groupedByDate := groupedByDate collect: [ :contribs |
×
212
                                 contribs
×
213
                                         ifNotEmpty: [ contribs sum ]
×
214
                                         ifEmpty: [ 0 ] ].
×
215

×
216

×
217
        ^ {
×
218
                  (#details -> groupedByDate).
×
219
                  (#totalComments -> groupedByDate values sum).
×
220
                  (#avgComments
×
NEW
221
                   -> (groupedByDate values average asFloat)).
×
222
                  (#overEach -> aDateWeekMonthOrYear name).
×
223
                  (#forOver -> (groupedByDate keys size printString
×
224
                    , aDateWeekMonthOrYear printString)).
×
225
                  (#userCommits -> commits size) } asDictionary
×
226
]
×
UNCOV
227

×
UNCOV
228
{ #category : #metrics }
×
229
GitMetric4User >> commitFrequencySince: since until: until overA: aDateWeekMonthOrYear [
×
230

×
231
        | all aggregate periods total groupedByDate userCommits |
×
232
        'GitMetric4User: commit frequency' recordInfo.
×
233

×
234
        groupedByDate := self
×
235
                                 setupGroupedDateFrom: since
×
236
                                 to: until
×
237
                                 over: aDateWeekMonthOrYear.
×
238

×
239

×
240
        userCommits := self
×
241
                               loadCommitOfProjects: itsProjects keys
×
242
                               since: since
×
243
                               until: until.
×
244
        userCommits := userCommits reject: [ :c | c commitCreator ~= user ].
×
245

×
246
        userCommits do: [ :c |
×
247
                | dateOver |
×
248
                dateOver := self
×
249
                                    transformDate: c created_at
×
250
                                    to: aDateWeekMonthOrYear.
×
251
                groupedByDate at: dateOver printString ifPresent: [ :v | v add: c ] ].
×
252

×
253

×
254
        periods := groupedByDate keys size.
×
255
        total := groupedByDate values sum: [ :commits | commits size ].
×
256

×
257

×
258
        "aggregate := OrderedDictionary new.
×
259

×
260
        all := itsProjects keys collect: [ :id |
×
261
                       self
×
262
                               commitsProducedOnProject: id
×
263
                               since: since
×
264
                               until: until
×
265
                               overA: aDateWeekMonthOrYear ].
×
266

×
267

×
268
        all do: [ :frequencies |
×
269
                frequencies associations do: [ :assoc |
×
270
                        aggregate
×
271
                                at: assoc key
×
272
                                ifPresent: [ :collection | collection addAll: assoc value ]
×
273
                                ifAbsentPut: [ assoc value ] ] ].
×
274

×
275
        periods := aggregate keys size.
×
276
        total := aggregate values sum: [ :commits | commits size ].
×
277
"
×
278

×
279
        ^ {
×
280
                  (#averageFrac -> (total / periods)).
×
281
                  (#averageFloat -> (total / periods) asFloat).
×
282
                  (#userCommit -> total).
×
283
                  (#forOver -> (groupedByDate keys size printString
×
284
                    , aDateWeekMonthOrYear printString)).
×
285
                  (#periode -> aDateWeekMonthOrYear name).
×
286
                  (#details -> groupedByDate) } asOrderedDictionary
×
287
]
×
288

289
{ #category : #'as yet unclassified' }
290
GitMetric4User >> commitsProducedOnProject: projectId since: sinceDate until: untilDate [
×
291

×
292
        | frequencies |
×
293
        
×
294
        
×
295
        gitAnalyzer := GitAnalyzer new 
×
296
        glhImporter: glhImporter; 
×
297
        onModel: glhModel.
×
298
         
×
299
        frequencies := gitAnalyzer
×
300
                               onProject: (itsProjects at: projectId);
×
301
                               analyseCommitFrequencySince: sinceDate
×
302
                               until: untilDate. 
×
303
        
×
304
        "complete each commit "
×
305
        frequencies values flattened do: [ :commit |
×
306
                glhImporter completeImportedCommit: commit.
×
307
                 ].
×
308
        
×
309
        "Filter the associations in the 'frequencies' collection, removing any commits not created by the specified 'user'. "
×
310
        frequencies associations do: [ :assoc |
×
311
                |commits| 
×
312
                commits := assoc value.
×
313
                assoc value: (commits reject: [ :commit | commit commitCreator ~= user ]). 
×
314
        ].
×
315
        
×
316
        ^ frequencies 
×
317
]
×
318

319
{ #category : #metrics }
320
GitMetric4User >> commitsProducedOnProject: aProjectId since: since until: until overA: aWeekOrMonthOrYear [
×
321
        "'aWeekOrMonthOrYear' should be the class of Week, Month or Year"
×
322

×
323
        "self commitFrequencyOnProject: 6462 since: (Date today - 60 day) until: (Date today) overA: Week. "
×
324

×
325
        | frequency aggregatedFrequencies |
×
326
        aggregatedFrequencies := self setupGroupedDateFrom: since to: until  over: aWeekOrMonthOrYear.
×
327
        
×
328
        frequency := self
×
329
                             commitsProducedOnProject: aProjectId
×
330
                             since: since
×
331
                             until: until.
×
332

×
333

×
334
        frequency associations do: [ :assoc |
×
335
                | date commits overDate |
×
336
                date := assoc key.
×
337
                commits := assoc value.
×
338

×
339
                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 "
×
340
                        overDate := self transformDate: date to: aWeekOrMonthOrYear.
×
341
                        aggregatedFrequencies
×
342
                                at: overDate printString
×
343
                                ifPresent: [ :collection | collection addAll: commits ]
×
344
                                ifAbsentPut: [ commits ] ] ].
×
345

×
346
        ^ aggregatedFrequencies
×
347
]
×
348

349
{ #category : #churn }
NEW
350
GitMetric4User >> delayUntilFirstChurnSince: since until: until onACommitWindowOf: maxCommitWindow overA: aDateWeekMonthOrYear [
×
NEW
351

×
NEW
352
        | commits groupedByDate res avg |
×
NEW
353
        'GitMetric4User: delay until first churn' recordInfo.
×
NEW
354

×
NEW
355
        groupedByDate := self
×
NEW
356
                                 setupGroupedDateFrom: since
×
NEW
357
                                 to: until
×
NEW
358
                                 over: aDateWeekMonthOrYear.
×
NEW
359

×
NEW
360
        commits := self
×
NEW
361
                           loadCommitOfProjects: itsProjects keys
×
NEW
362
                           since: since
×
NEW
363
                           until: until.
×
NEW
364

×
NEW
365
        "class commit by dates, filter none user commits"
×
NEW
366
        commits do: [ :commit |
×
NEW
367
                commit commitCreator = user ifTrue: [
×
NEW
368
                        | overDate |
×
NEW
369
                        overDate := self
×
NEW
370
                                            transformDate: commit created_at
×
NEW
371
                                            to: aDateWeekMonthOrYear.
×
NEW
372

×
NEW
373
                        groupedByDate
×
NEW
374
                                at: overDate printString
×
NEW
375
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
NEW
376
                                ifAbsentPut: [
×
NEW
377
                                        OrderedCollection new
×
NEW
378
                                                add: commit;
×
NEW
379
                                                yourself ] ] ].
×
NEW
380

×
NEW
381

×
NEW
382

×
NEW
383
        res := groupedByDate collect: [ :commits4Date |
×
NEW
384
                       | durationFromA2B |
×
NEW
385
                       commits4Date collect: [ :commitA |
×
NEW
386
                               | commitB |
×
NEW
387
                               commitB := GitAnalyzer new
×
NEW
388
                                                  glhImporter: glhImporter;
×
NEW
389
                                                  onModel: glhModel;
×
NEW
390
                                                  fromCommit: commitA;
×
NEW
391
                                                  maxChildCommit: maxCommitWindow;
×
NEW
392
                                                  analyseAmandment.
×
NEW
393

×
NEW
394
                               durationFromA2B := commitB
×
NEW
395
                                                          ifNil: [ 0 ]
×
NEW
396
                                                          ifNotNil: [
×
NEW
397
                                                          commitB created_at - commitA created_at ].
×
NEW
398
                               durationFromA2B ] ].
×
NEW
399

×
NEW
400

×
NEW
401

×
NEW
402
        res := res collect: [ :durationsByDate |
×
NEW
403
                       | filtered |
×
NEW
404
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
NEW
405
                       filtered isEmpty
×
NEW
406
                               ifTrue: [ nil ]
×
NEW
407
                               ifFalse: [
×
NEW
408
                               (filtered sum: [ :v | v asDuration ]) / filtered size ] ].
×
NEW
409

×
NEW
410
        res := res reject: #isNil.
×
NEW
411

×
NEW
412
        res
×
NEW
413
                ifEmpty: [ avg := nil ]
×
NEW
414
                ifNotEmpty: [ avg := res values sum / res keys size ].
×
NEW
415

×
NEW
416

×
NEW
417
        ^ {
×
NEW
418
                  (#avgDelay -> avg).
×
NEW
419
                  (#overEach -> aDateWeekMonthOrYear name).
×
NEW
420
                  (#forOver -> (groupedByDate keys size printString
×
NEW
421
                    , aDateWeekMonthOrYear printString)).
×
NEW
422
                  (#details -> groupedByDate) } asDictionary
×
NEW
423
]
×
424

425
{ #category : #churn }
426
GitMetric4User >> delayUntilFirstChurnSince: since until: until overA: aDateWeekMonthOrYear [
×
427

×
428
        | commits groupedByDate res avg |
×
429
        
×
430
                ('GitMetric4User: delay until first churn') recordInfo.        
×
431
        
×
432
        groupedByDate := self
×
433
                                 setupGroupedDateFrom: since
×
434
                                 to: until
×
435
                                 over: aDateWeekMonthOrYear.
×
436

×
437
        commits := self
×
438
                           loadCommitOfProjects: itsProjects keys
×
439
                           since: since
×
440
                           until: until.
×
441

×
442
        "class commit by dates, filter none user commits"
×
443
        commits do: [ :commit |
×
444
                commit commitCreator = user ifTrue: [
×
445
                        | overDate |
×
446
                        overDate := self
×
447
                                            transformDate: commit created_at
×
448
                                            to: aDateWeekMonthOrYear.
×
449

×
450
                        groupedByDate
×
451
                                at: overDate printString
×
452
                                ifPresent: [ :arrayOfCommits | arrayOfCommits add: commit ]
×
453
                                ifAbsentPut: [
×
454
                                        OrderedCollection new
×
455
                                                add: commit;
×
456
                                                yourself ] ] ].
×
457

×
458

×
459

×
460
        res := groupedByDate collect: [ :commits4Date |
×
461
                       | durationFromA2B |
×
462
                       commits4Date collect: [ :commitA |
×
463
                               | commitB |
×
464
                               commitB := GitAnalyzer new
×
465
                                                  glhImporter: glhImporter;
×
466
                                                  onModel: glhModel;
×
467
                                                  fromCommit: commitA;
×
468
                                                                                maxChildCommit: 5;
×
469
                                                  analyseAmandment.
×
470

×
471
                               durationFromA2B := commitB
×
472
                                                          ifNil: [ 0 ]
×
473
                                                          ifNotNil: [
×
474
                                                          commitB created_at - commitA created_at ].
×
475
                               durationFromA2B ] ].
×
476

×
477

×
478

×
479
        res := res collect: [ :durationsByDate |
×
480
                       | filtered |
×
481
                       filtered := durationsByDate reject: [ :value | value = 0 ].
×
482
                       filtered isEmpty
×
483
                               ifTrue: [ nil ]
×
484
                               ifFalse: [
×
485
                               (filtered sum: [ :v | v asDuration ]) / filtered size ] ].
×
486

×
487
        res := res reject: #isNil.
×
488
        
×
489
        res ifEmpty: [ avg:= nil ] ifNotEmpty: [ avg := res values sum / res keys size. ].
×
490

×
491

×
492
        ^ {
×
493
                  (#avgDelay -> avg).
×
494
                  (#overEach -> aDateWeekMonthOrYear name).
×
495
                  (#forOver -> (groupedByDate keys size printString
×
496
                    , aDateWeekMonthOrYear printString)).
×
497
                  (#details -> groupedByDate) } asDictionary
×
498
]
×
499

500
{ #category : #'as yet unclassified' }
501
GitMetric4User >> findUserNamed: aUsername [
×
502

×
503
        user := glhImporter importUserByUsername: aUsername.
×
504
        ^ user
×
505
]
×
506

507
{ #category : #accessing }
508
GitMetric4User >> glhImporter: aGLPHModelImporter [ 
×
509
        glhImporter := aGLPHModelImporter
×
510
]
×
511

512
{ #category : #initialization }
513
GitMetric4User >> initialize [
×
514

×
515
        user := GLHUser new.
×
516
        itsProjects := Dictionary new.
×
517
        itsCommits := Dictionary new.
×
518
        itsGroups := Dictionary new.
×
519
        itsMergeRequests := Dictionary new
×
520
]
×
521

522
{ #category : #accessing }
NEW
523
GitMetric4User >> itsProjects: projects [
×
NEW
524
        itsProjects := projects .
×
NEW
525
]
×
526

527
{ #category : #churn }
528
GitMetric4User >> loadCommitOfProjects: aCollection since: aTimespan [
×
529
        |commits|
×
530
        
×
531
        commits := (aCollection collect: [ :id |
×
532
                 glhImporter
×
533
                        importCommitsOProject: (itsProjects at: id)
×
534
                        since: aTimespan
×
535
                        until: nil ]) flattened.
×
536

×
537
        commits do: [ :commit |
×
538
                glhImporter completeImportedCommit: commit. 
×
539
                 ].
×
540

×
541
        ^ self userCommits.
×
542
]
×
543

544
{ #category : #churn }
545
GitMetric4User >> loadCommitOfProjects: aCollection since: since until: until [
×
546

×
NEW
547
        | allCommits period |
×
NEW
548
        period := ('commits since ' , since printString , ' to '
×
NEW
549
                   , until printString) asSymbol.
×
NEW
550

×
NEW
551
        "download commits unless project cache is not empty"
×
NEW
552
        allCommits := aCollection collect: [ :idProject |
×
NEW
553
                              | project |
×
NEW
554
                              project := itsProjects at: idProject.
×
NEW
555
                              project repository cacheAt: period ifAbsentPut: [
×
NEW
556
                                      | foundCommits |
×
NEW
557
                                      foundCommits := glhImporter
×
NEW
558
                                                              importCommitsOProject: project
×
NEW
559
                                                              since: since
×
NEW
560
                                                              until: until.
×
NEW
561
                                      foundCommits ] ].
×
562

×
563
        allCommits := allCommits flatten.
×
564
        allCommits do: [ :commit |
×
565
                glhImporter completeImportedCommit: commit ].
×
566

×
567
        glhImporter chainsCommitsFrom: allCommits.
×
568

×
569
        ^ allCommits
×
570
]
×
571

572
{ #category : #churn }
573
GitMetric4User >> loadMergeRequestsOfProjects: aCollection since: since until: until [
×
574

×
575
        | allMr |
×
576
        itsMergeRequests ifNil: [ itsMergeRequests := Dictionary new ].
×
577

×
578
        allMr := itsMergeRequests
×
579
                         at: since printString , '-' , until printString
×
580
                         ifAbsentPut: [
×
581
                                 | mr |
×
582
                                 mr := (aCollection collect: [ :id |
×
583
                                                glhImporter
×
584
                                                        importMergeRequests: (itsProjects at: id)
×
585
                                                        since: since
×
586
                                                        until: until ]) flattened.
×
NEW
587
                                 " mr := mr flatCollect: [ :c | c ]."
×
588
                                 mr ].
×
589

×
590

×
591
        ^ allMr
×
592
]
×
593

594
{ #category : #loading }
595
GitMetric4User >> loadProjects: projectIds [
×
596

×
597
        projectIds do: [ :id |
×
598
                
×
599
                itsProjects at: id ifAbsentPut: [ glhImporter importProject: id ] ].
×
600

×
601
        ^ itsProjects
×
602
]
×
603

604
{ #category : #metrics }
605
GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeekMonthOrYear [
×
606

×
607
        | mergeRequest res groupedByDate filterGroups avg |
×
608
        groupedByDate := self
×
609
                                 setupGroupedDateFrom: since
×
610
                                 to: until
×
611
                                 over: aDateWeekMonthOrYear.
×
612

×
613
        gitAnalyzer := GitAnalyzer new
×
614
                               glhImporter: glhImporter;
×
615
                               onModel: glhModel.
×
616

×
617
        mergeRequest := self
×
618
                                loadMergeRequestsOfProjects: itsProjects keys
×
619
                                since: since
×
620
                                until: until.
×
621
        
×
622

×
623
        mergeRequest ifEmpty: [
×
624
                ^ {
×
625
                          (#avgDuration -> nil).
×
626
                          (#overEach -> aDateWeekMonthOrYear name).
×
627
                          (#forOver -> (groupedByDate keys size printString
×
628
                            , aDateWeekMonthOrYear printString)).
×
629
                          (#totalMergeRequest -> 0).
×
630
                          (#details -> nil) } asDictionary ].
×
631

×
632
        res := mergeRequest collect: [ :mr |
×
633
                       gitAnalyzer analyseMergeResquestValidation: mr ].
×
634

×
635

×
636
        res do: [ :dic |
×
637
                | overDate |
×
638
                overDate := self
×
639
                                    transformDate: (dic at: #created_at)
×
640
                                    to: aDateWeekMonthOrYear.
×
641

×
642
                groupedByDate
×
643
                        at: overDate printString
×
644
                        ifPresent: [ :durations | durations add: (dic at: #duration) ]
×
645
                        ifAbsentPut: [
×
646
                                OrderedCollection new
×
647
                                        add: (dic at: #duration);
×
648
                                        yourself ] ].
×
649

×
650

×
651
        filterGroups := groupedByDate reject: [ :array | array isEmpty ].
×
652

×
653
        filterGroups associations do: [ :assoc |
×
654
                | sum denominator |
×
655
                denominator := assoc value size.
×
656

×
657
                sum := assoc value sum: [ :v |
×
658
                               v ifNil: [
×
659
                                       denominator := denominator - 1.
×
660
                                       0 asDuration ] ].
×
661
                denominator = 0 ifTrue: [ denominator := 1 ].
×
662

×
663
                filterGroups at: assoc key put: sum / denominator ].
×
664

×
665

×
666
        filterGroups keys
×
667
                ifEmpty: [ avg := 0 ]
×
668
                ifNotEmpty: [
×
669
                avg := filterGroups values sum / filterGroups keys size ].
×
670

×
671

×
672
        ^ {
×
673
                  (#avgDuration -> avg).
×
674
                  (#overEach -> aDateWeekMonthOrYear name).
×
675
                  (#forOver -> (groupedByDate keys size printString
×
676
                    , aDateWeekMonthOrYear printString)).
×
677
                  (#totalMergeRequest -> mergeRequest size).
×
678
                  (#details -> groupedByDate) } asDictionary
×
679
]
×
680

681
{ #category : #setup }
682
GitMetric4User >> setupGroupedDateFrom: since to: until over: aDateWeekMonthOrYear [
×
683

×
684
        | groupedByDate start end over increment|
×
685
        groupedByDate := OrderedDictionary new.
×
686

×
687
        increment := 1.
×
688
        start := self transformDate: since to: aDateWeekMonthOrYear.
×
689
        end := self transformDate: until to: aDateWeekMonthOrYear.
×
690

×
691
        groupedByDate
×
692
                at: start printString
×
693
                ifAbsentPut: [ OrderedCollection new ].
×
694
        
×
695
        over := aDateWeekMonthOrYear name asLowercase asSymbol.
×
696
                over = #date ifTrue: [ over := #day ].
×
697
                over = #month ifTrue: [ increment := 32. over := #day ].
×
698
                 
×
699

×
700
        [ groupedByDate keys last asDateAndTime < end ] whileTrue: [
×
701
                | index  |
×
702
                index := groupedByDate keys last asDateAndTime + (increment perform: over).
×
703
                index := self transformDate: index to: aDateWeekMonthOrYear.
×
704
                groupedByDate
×
705
                        at: index printString
×
706
                        ifAbsentPut: [ OrderedCollection new ] ].
×
707
        
×
708
        
×
709
        over = #day ifTrue: [ 
×
710
                groupedByDate keys do: [ :date |
×
711
                        |aWeekday|
×
712
                         aWeekday := date asDate weekday. 
×
713
                        ((aWeekday =  #Sunday) or: [ aWeekday = #Saturday ] )ifTrue: [ 
×
714
                                groupedByDate removeKey: date. 
×
715
                                 ] 
×
716
                         ].
×
717
                 ].
×
718
        
×
719

×
720
        groupedByDate
×
721
                at: end printString
×
722
                ifAbsentPut: [ OrderedCollection new ].
×
723

×
724
        ^ groupedByDate
×
725
]
×
726

727
{ #category : #'as yet unclassified' }
728
GitMetric4User >> transformDate: date to: aWeekOrMonthOrYear [
×
729

×
730
        aWeekOrMonthOrYear = Month ifTrue: [ ^ date asDate month asDate ].
×
731

×
732
        ^ (date asDate perform: ('as' , aWeekOrMonthOrYear name) asSymbol)
×
733
                  asDate
×
734
]
×
735

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

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

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