Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics): average time between commits #27

Merged
merged 6 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/GitLabHealth-Model-Analysis/AnalysisReport.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Class {
'commentContribution',
'mergeRequestDuration',
'codeChurn',
'delayUntilFirstChurn'
'delayUntilFirstChurn',
'averageTimeBetweenCommits'
],
#category : #'GitLabHealth-Model-Analysis'
}
Expand All @@ -20,6 +21,18 @@ AnalysisReport class >> isVoyageRoot [
^true
]

{ #category : #accessing }
AnalysisReport >> averageTimeBetweenCommits [

^ averageTimeBetweenCommits
]

{ #category : #accessing }
AnalysisReport >> averageTimeBetweenCommits: anObject [

averageTimeBetweenCommits := anObject
]

{ #category : #accessing }
AnalysisReport >> codeAddition [

Expand Down
64 changes: 62 additions & 2 deletions src/GitLabHealth-Model-Analysis/GitMetric4User.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,63 @@ Class {
#category : #'GitLabHealth-Model-Analysis'
}

{ #category : #metrics }
GitMetric4User >> averageTimeBetweenCommitSince: since until: until over: aDateWeekMonthOrYear [

| commits commitSortedByDate commits1 commits2 differences groupedByDate dateOver |

groupedByDate := self
setupGroupedDateFrom: since
to: until
over: aDateWeekMonthOrYear.

gitAnalyzer := GitAnalyzer new
onModel: glhModel;
glhImporter: glhImporter.

glhImporter withCommitDiffs: false.
commits := self
loadCommitsFromProjectsIds: itsProjects keys
since: since
until: until.
glhImporter withCommitDiffs: true.
commits := commits reject: [ :commit | commit commitCreator ~= user ].

commitSortedByDate := commits sorted: [ :commit1 :commit2 |
commit1 committed_date
< commit2 committed_date ].

commitSortedByDate do: [ :commit |
dateOver := self
transformDate: commit committed_date
to: aDateWeekMonthOrYear.

groupedByDate at: dateOver printString ifPresent: [ :value | value add: commit ].
].

groupedByDate := groupedByDate select: [ :group | group size >= 2 ].


groupedByDate := groupedByDate collect: [ :group |
differences := (1 to: group size - 1) collect: [ :i |
commits1 := group at: i.
commits2 := group at: i + 1.

(commits2 committed_date - commits1 committed_date) asSeconds ].

differences average asDuration.
].


^{
(#overEach -> aDateWeekMonthOrYear name).
(#forOver -> (groupedByDate keys size printString
, aDateWeekMonthOrYear printString)).
(#average -> groupedByDate average).
(#details -> groupedByDate).
(#userCommits -> commits size) } asDictionary.
]

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

Expand Down Expand Up @@ -510,7 +567,7 @@ GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitL
{ #category : #'as yet unclassified' }
GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWindows: maxCommitWindow [

| contribution codeAddition codeDeletion commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn |
| contribution codeAddition codeDeletion commitFrequency commentContribution mergeRequestDuration codeChurn delayUntilFirstChurn averageTimeBetweenCommits |

contribution := self
codeContributionsSince: (period at: #since)
Expand Down Expand Up @@ -548,6 +605,8 @@ GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWind
until: (period at: #until)
onACommitWindowOf: maxCommitWindow
overA: over) at: #avgDelay.

averageTimeBetweenCommits := (self averageTimeBetweenCommitSince: (period at: #since) until: (period at: #until) over: over) at: #average.

^ AnalysisReport new
username: self user name;
Expand All @@ -558,7 +617,8 @@ GitMetric4User >> generateAnalysisForPeriod: period over: over withMaxCommitWind
commentContribution: commentContribution;
mergeRequestDuration: mergeRequestDuration;
codeChurn: codeChurn;
delayUntilFirstChurn: delayUntilFirstChurn
delayUntilFirstChurn: delayUntilFirstChurn;
averageTimeBetweenCommits: averageTimeBetweenCommits.
]

{ #category : #initialization }
Expand Down
6 changes: 6 additions & 0 deletions src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ GitMetricExporter >> exportInCSVOver: aCollectionOfDateWeekMonthOrYear [
withName:
'delay Until First Churn (W=' , maxCommitWindow printString
, ') ' asSymbol.

"average time between commits"
exportBrowserModel
addColumnForQuery: [ :analysis | analysis averageTimeBetweenCommits ]
withName:
'average time between commits' asSymbol.

aCollectionOfDateWeekMonthOrYear do: [ :aDateWeekMonthOrYear |
over := aDateWeekMonthOrYear.
Expand Down
Loading