-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor GitMetric structure around project group and user
- Loading branch information
HLAD Nicolas
committed
Jul 16, 2024
1 parent
0192f00
commit 703f312
Showing
5 changed files
with
167 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters