Skip to content

Commit

Permalink
refactor GitMetric structure around project group and user
Browse files Browse the repository at this point in the history
  • Loading branch information
HLAD Nicolas committed Jul 16, 2024
1 parent 0192f00 commit 703f312
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 139 deletions.
147 changes: 147 additions & 0 deletions src/GitLabHealth-Model-Analysis/GitMetric.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
Class {
#name : #GitMetric,
#superclass : #Object,
#instVars : [
'user',
'glhImporter',
'itsProjects',
'gitAnalyzer',
'glhModel'
],
#category : #'GitLabHealth-Model-Analysis'
}

{ #category : #'as yet unclassified' }
GitMetric >> cacheSymbolFor: anEntityType since: since until: until [

^ (anEntityType printString , ' since ' , since printString , ' to '
, until printString) asSymbol
]

{ #category : #'as yet unclassified' }
GitMetric >> findUserNamed: aUsername [

user := glhImporter importUserByUsername: aUsername.
^ user
]

{ #category : #churn }
GitMetric >> loadCommitOfProjects: aCollection since: since until: until [

| allCommits period i size|
period := self cacheSymbolFor: GLHCommit since: since until: until.

"download commits unless project cache is not empty"
allCommits := aCollection collect: [ :idProject |
| project |
project := itsProjects at: idProject.
project repository cacheAt: period ifAbsentPut: [
| foundCommits |
foundCommits := glhImporter
importCommitsOProject: project
since: since
until: until.
foundCommits ] ].

allCommits := allCommits flatten.

i := 1.
size := allCommits size.
allCommits do: [ :commit |
(' ' join: {
'import creators '.
i.
'/'.
size }) recordInfo.
glhImporter importCreatorOfCommit: commit.
i := i + 1 ].

glhImporter chainsCommitsFrom: allCommits.

^ allCommits
]

{ #category : #churn }
GitMetric >> loadMergeRequestsOfProjects: aCollection since: since until: until [

| allMr period |
"itsMergeRequests ifNil: [ itsMergeRequests := Dictionary new ]."
period := self cacheSymbolFor: GLPHEMergeRequest since: since until: until.

allMr := aCollection collect: [ :idProject |
| project mr |
project := itsProjects at: idProject.
project cacheAt: period ifAbsentPut: [
mr := glhImporter
importMergeRequests: project
since: since
until: until.
mr ] ].

^ allMr flattened
]

{ #category : #loading }
GitMetric >> loadProjects: projectIds [

projectIds do: [ :id |

itsProjects at: id ifAbsentPut: [ glhImporter importProject: id ] ].

^ itsProjects
]

{ #category : #setup }
GitMetric >> setupGroupedDateFrom: since to: until over: aDateWeekMonthOrYear [

| groupedByDate start end over increment |
groupedByDate := OrderedDictionary new.

increment := 1.
start := self transformDate: since to: aDateWeekMonthOrYear.
end := self transformDate: until to: aDateWeekMonthOrYear.

groupedByDate
at: start printString
ifAbsentPut: [ OrderedCollection new ].

over := aDateWeekMonthOrYear name asLowercase asSymbol.
over = #date ifTrue: [ over := #day ].
over = #month ifTrue: [
increment := 32.
over := #day ].


[ groupedByDate keys last asDateAndTime < end ] whileTrue: [
| index |
index := groupedByDate keys last asDateAndTime
+ (increment perform: over).
index := self transformDate: index to: aDateWeekMonthOrYear.
groupedByDate
at: index printString
ifAbsentPut: [ OrderedCollection new ] ].


over = #day ifTrue: [
groupedByDate keysDo: [ :date |
| aWeekday |
aWeekday := date asDate weekday.
(aWeekday = #Sunday or: [ aWeekday = #Saturday ]) ifTrue: [
groupedByDate removeKey: date ] ] ].


groupedByDate
at: end printString
ifAbsentPut: [ OrderedCollection new ].

^ groupedByDate
]

{ #category : #'as yet unclassified' }
GitMetric >> transformDate: date to: aWeekOrMonthOrYear [

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

^ (date asDate perform: ('as' , aWeekOrMonthOrYear name) asSymbol)
asDate
]
8 changes: 8 additions & 0 deletions src/GitLabHealth-Model-Analysis/GitMetric4Group.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Class {
#name : #GitMetric4Group,
#superclass : #GitMetric,
#instVars : [
'project'
],
#category : #'GitLabHealth-Model-Analysis'
}
8 changes: 8 additions & 0 deletions src/GitLabHealth-Model-Analysis/GitMetric4Project.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Class {
#name : #GitMetric4Project,
#superclass : #GitMetric,
#instVars : [
'project'
],
#category : #'GitLabHealth-Model-Analysis'
}
137 changes: 1 addition & 136 deletions src/GitLabHealth-Model-Analysis/GitMetric4User.class.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
Class {
#name : #GitMetric4User,
#superclass : #Object,
#superclass : #GitMetric,
#instVars : [
'user',
'itsProjects',
'itsGroups',
'itsCommits',
'gitAnalyzer',
'glhModel',
'glhImporter',
'itsMergeRequests'
],
#category : #'GitLabHealth-Model-Analysis'
Expand Down Expand Up @@ -498,13 +493,6 @@ GitMetric4User >> delayUntilFirstChurnSince: since until: until overA: aDateWeek
(#details -> groupedByDate) } asDictionary
]

{ #category : #'as yet unclassified' }
GitMetric4User >> findUserNamed: aUsername [

user := glhImporter importUserByUsername: aUsername.
^ user
]

{ #category : #churn }
GitMetric4User >> foundSuccessorOf: userCommits andCompleteImportForMax: commitLimit [

Expand Down Expand Up @@ -562,74 +550,6 @@ GitMetric4User >> loadCommitOfProjects: aCollection since: aTimespan [
^ self userCommits.
]

{ #category : #churn }
GitMetric4User >> loadCommitOfProjects: aCollection since: since until: until [

| allCommits period i|
period := ('commits since ' , since printString , ' to '
, until printString) asSymbol.

"download commits unless project cache is not empty"
allCommits := aCollection collect: [ :idProject |
| project |
project := itsProjects at: idProject.
project repository cacheAt: period ifAbsentPut: [
| foundCommits |
foundCommits := glhImporter
importCommitsOProject: project
since: since
until: until.
foundCommits ] ].

allCommits := allCommits flatten.

i := 1.
allCommits do: [ :commit |
(' ' join: { 'import creators ' .(i) . '/' . allCommits size }) recordInfo.
glhImporter importCreatorOfCommit: commit.
i := i + 1.
].

glhImporter chainsCommitsFrom: allCommits.

^ allCommits
]

{ #category : #churn }
GitMetric4User >> loadMergeRequestsOfProjects: aCollection since: since until: until [

| allMr period|
"itsMergeRequests ifNil: [ itsMergeRequests := Dictionary new ]."

period := ('mr since ' , since printString , ' to '
, until printString) asSymbol.

allMr := aCollection collect: [ :idProject |
| project mr|
project := itsProjects at: idProject.
project cacheAt: period ifAbsentPut: [
mr := glhImporter
importMergeRequests: project
since: since
until: until.
mr.
].
].

^ allMr flattened.

]

{ #category : #loading }
GitMetric4User >> loadProjects: projectIds [

projectIds do: [ :id |

itsProjects at: id ifAbsentPut: [ glhImporter importProject: id ] ].

^ itsProjects
]

{ #category : #metrics }
GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeekMonthOrYear [

Expand Down Expand Up @@ -708,61 +628,6 @@ GitMetric4User >> mergeRequestDurationSince: since until: until overA: aDateWeek
(#details -> groupedByDate) } asDictionary
]

{ #category : #setup }
GitMetric4User >> setupGroupedDateFrom: since to: until over: aDateWeekMonthOrYear [

| groupedByDate start end over increment|
groupedByDate := OrderedDictionary new.

increment := 1.
start := self transformDate: since to: aDateWeekMonthOrYear.
end := self transformDate: until to: aDateWeekMonthOrYear.

groupedByDate
at: start printString
ifAbsentPut: [ OrderedCollection new ].

over := aDateWeekMonthOrYear name asLowercase asSymbol.
over = #date ifTrue: [ over := #day ].
over = #month ifTrue: [ increment := 32. over := #day ].


[ groupedByDate keys last asDateAndTime < end ] whileTrue: [
| index |
index := groupedByDate keys last asDateAndTime + (increment perform: over).
index := self transformDate: index to: aDateWeekMonthOrYear.
groupedByDate
at: index printString
ifAbsentPut: [ OrderedCollection new ] ].


over = #day ifTrue: [
groupedByDate keys do: [ :date |
|aWeekday|
aWeekday := date asDate weekday.
((aWeekday = #Sunday) or: [ aWeekday = #Saturday ] )ifTrue: [
groupedByDate removeKey: date.
]
].
].


groupedByDate
at: end printString
ifAbsentPut: [ OrderedCollection new ].

^ groupedByDate
]

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

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

^ (date asDate perform: ('as' , aWeekOrMonthOrYear name) asSymbol)
asDate
]

{ #category : #accessing }
GitMetric4User >> user [
^ user
Expand Down
6 changes: 3 additions & 3 deletions src/GitLabHealth-Visualization/RSCommitDiff.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ RSCommitDiff class >> shapeFor: aCommitDiff [
RSCommitDiff >> buildCanvas [

| shapes |
self
" self
deprecated: 'Use #build instead'
on: '2 May 2024'
in:
'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.
'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'."
canvas := RSCanvas new.
shapes := RSGroup new.

Expand Down Expand Up @@ -101,7 +101,7 @@ RSCommitDiff >> shapeForDiff: aGLHDiff withColor: color [
group := RSGroup new.
label := RSLabel new
text:
(aGLHDiff new_path asPath segments last
(aGLHDiff diff new_path asPath segments last
truncateWithElipsisTo: 50);
yourself.
box := RSBox new
Expand Down

0 comments on commit 703f312

Please sign in to comment.