Skip to content

Commit 7a6969e

Browse files
authored
feat(metrics): number of project with a commit of the user (#30)
* feat: create numberOfProjetWithCommit method * feat: add numberOfProjectWithCommit metric in analysis report and csv export * fix: missing semicolon * fix: missing comma
1 parent 157ef93 commit 7a6969e

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/GitLabHealth-Model-Analysis/AnalysisReport.class.st

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Class {
1111
'mergeRequestDuration',
1212
'codeChurn',
1313
'delayUntilFirstChurn',
14+
'numberOfProjectWithCommit',
1415
'averageTimeBetweenCommits'
1516
],
1617
#category : #'GitLabHealth-Model-Analysis'
@@ -117,6 +118,18 @@ AnalysisReport >> mergeRequestDuration: anObject [
117118
mergeRequestDuration := anObject
118119
]
119120

121+
{ #category : #accessing }
122+
AnalysisReport >> numberOfProjectWithCommit [
123+
124+
^ numberOfProjectWithCommit
125+
]
126+
127+
{ #category : #accessing }
128+
AnalysisReport >> numberOfProjectWithCommit: anObject [
129+
130+
numberOfProjectWithCommit := anObject
131+
]
132+
120133
{ #category : #accessing }
121134
AnalysisReport >> period [
122135

src/GitLabHealth-Model-Analysis/GitMetric4User.class.st

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitL
567567
{ #category : #'as yet unclassified' }
568568
GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWindows: maxCommitWindow [
569569

570-
| contribution codeAddition codeDeletion commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn averageTimeBetweenCommits |
570+
| contribution codeAddition codeDeletion commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn averageTimeBetweenCommits averageTimeBetweenCommits |
571571

572572
contribution := self
573573
codeContributionsSince: (period at: #since)
@@ -606,6 +606,7 @@ GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWind
606606
onACommitWindowOf: maxCommitWindow
607607
overA: over) at: #avgDelay.
608608

609+
numberOfProjectWithCommit := self numberOfProjectWithCommitSince: (period at: #since) until: (period at: #until) overA: over.
609610
averageTimeBetweenCommits := (self averageTimeBetweenCommitSince: (period at: #since) until: (period at: #until) over: over) at: #average.
610611

611612
^ AnalysisReport new
@@ -618,6 +619,7 @@ GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWind
618619
mergeRequestDuration: mergeRequestDuration;
619620
codeChurn: codeChurn;
620621
delayUntilFirstChurn: delayUntilFirstChurn;
622+
numberOfProjectWithCommit: (numberOfProjectWithCommit at: #average);
621623
averageTimeBetweenCommits: averageTimeBetweenCommits.
622624
]
623625

@@ -730,6 +732,52 @@ GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeek
730732
(#details -> groupedByDate) } asDictionary
731733
]
732734

735+
{ #category : #metrics }
736+
GitMetric4User >> numberOfProjectWithCommitSince: since until: until overA: aDateWeekMonthOrYear [
737+
| groupedByDate commits userCommits dateOver projects |
738+
groupedByDate := self
739+
setupGroupedDateFrom: since
740+
to: until
741+
over: aDateWeekMonthOrYear.
742+
743+
gitAnalyzer := GitAnalyzer new
744+
onModel: glhModel;
745+
glhImporter: glhImporter.
746+
747+
glhImporter withCommitDiffs: false.
748+
commits := self
749+
loadCommitsFromProjectsIds: itsProjects keys
750+
since: since
751+
until: until.
752+
glhImporter withCommitDiffs: true.
753+
userCommits := commits reject: [ :commit | commit commitCreator ~= user ].
754+
755+
756+
userCommits do: [ :userCommit |
757+
dateOver := self
758+
transformDate: userCommit committed_date
759+
to: aDateWeekMonthOrYear.
760+
761+
groupedByDate at: dateOver printString ifPresent: [ :value | value add: (userCommit repository project) ].
762+
].
763+
764+
groupedByDate := groupedByDate collect: [ :group |
765+
projects := Set newFrom: group.
766+
projects size.
767+
].
768+
769+
^ {
770+
(#overEach -> aDateWeekMonthOrYear name).
771+
(#forOver -> (groupedByDate keys size printString
772+
, aDateWeekMonthOrYear printString)).
773+
(#average
774+
->
775+
groupedByDate average asFloat).
776+
(#details -> groupedByDate).
777+
(#userCommits -> commits size) } asDictionary
778+
779+
]
780+
733781
{ #category : #accessing }
734782
GitMetric4User >> user [
735783
^ user

src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ GitMetricExporter >> exportInCSVOver: aCollectionOfDateWeekMonthOrYear [
232232
'delay Until First Churn (W=' , maxCommitWindow printString
233233
, ') ' asSymbol.
234234

235+
"number of project with minimum one commit of user"
236+
exportBrowserModel
237+
addColumnForQuery: [ :analysis | analysis numberOfProjectWithCommit ]
238+
withName:
239+
'number of project with min 1 commit of user' asSymbol.
240+
235241
"average time between commits"
236242
exportBrowserModel
237243
addColumnForQuery: [ :analysis | analysis averageTimeBetweenCommits ]

0 commit comments

Comments
 (0)