Skip to content

Commit

Permalink
Merge branch 'develop' into test-user-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
knowbased authored Sep 6, 2024
2 parents 8f78d52 + 4f01fb9 commit d353ae6
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,10 @@ GLHUserCatalogueTest >> testNamesAtChangingUser [
username: 'testUser';
yourself.

user hash. " 114462615"

catalogue addUser: user withName: 'toto'.

user name: 'test User'.

user hash.

self assert: (catalogue namesAt: user) size equals: 3.
self
Expand All @@ -247,6 +244,6 @@ GLHUserCatalogueTest >> testNamesAtChangingUser [
assert: ((catalogue namesAt: user) includes: 'testUser')
equals: true.
self
assert: ((catalogue namesAt: user) includes: 'test user')
equals: true
assert: ((catalogue namesAt: user) includes: 'test User')
equals: false
]
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ GLHUserCatalogueV2Test >> testExportAndLoad [
user := GLHUser new
username: 'testUser';
name: 'test user';
contributedProjects: { GLHProject new id: 11 };
yourself.


catalogue addUser: user.
json := catalogue exportToJson.

res := GLHUserCatalogue loadFromJson: json.
self assert: res size equals: catalogue size
res := GLHUserCatalogueV2 loadFromJson: json.

self assert: res size equals: catalogue size.
self assert: ((res at: 'test user' at: #contributedProjects) includes: 11) equals: true.
self assert: ((res at: 'test user' at: #names) includes: 'test user') equals: true.
self assert: ((res at: 'test user' at: #names) includes: 'testUser') equals: true.
]

{ #category : #test }
Expand All @@ -164,12 +167,14 @@ GLHUserCatalogueV2Test >> testExportToJson [
user := GLHUser new
username: 'testUser';
name: 'test user';
contributedProjects: { GLHProject new id: 11 } ;
id: 1;
yourself.
user2 := GLHUser new
username: 'testUser2';
name: 'test user2';
id: 2;
contributedProjects: { GLHProject new id: 21 . GLHProject new id: 22 } ;
yourself.


Expand All @@ -181,7 +186,9 @@ GLHUserCatalogueV2Test >> testExportToJson [
res := STONJSON fromString: json.
self assert: res size equals: catalogue size.
self assert: ((res at: 'test user2') at: #foundNames) size equals: 2.
self assert: ((res at: 'test user') at: #foundNames) size equals: 2
self assert: ((res at: 'test user') at: #foundNames) size equals: 2.
self assert: ((res at: 'test user') at: #contributedProjects) size equals: 1.
self assert: ((res at: 'test user2') at: #contributedProjects) size equals: 2.
]

{ #category : #'as yet unclassified' }
Expand Down
136 changes: 100 additions & 36 deletions src/GitLabHealth-Model-Analysis/GLHUserCatalogueV2.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ GLHUserCatalogueV2 class >> loadFromJson: aString [
catalogue := self new.
dic := (STONJSON fromString: aString) asDictionary.
dic associationsDo: [ :assoc |
| itsName itsUsername itsCommitNames itsId |
| itsName itsUsername itsCommitNames itsId itsProjectIDs|
itsName := assoc key.
itsCommitNames := assoc value at: #foundNames.
itsUsername := assoc value at: #username.
itsId := assoc value at: #id.
itsProjectIDs := assoc value at: #contributedProjects ifAbsent: [{}].

catalogue
addUser: (GLHUser new
id: itsId;
username: itsUsername;
name: itsName;
yourself)
withNames: itsCommitNames ].
withNames: itsCommitNames
withProjects: itsProjectIDs ].

^ catalogue
]
Expand Down Expand Up @@ -126,35 +128,58 @@ GLHUserCatalogueV2 >> RSHeatMapLevenshteinTrimedAt: aBlockCondition [
{ #category : #adding }
GLHUserCatalogueV2 >> addUser: aGLHUser [

self at: aGLHUser name ifAbsentPut: [
self newEntryForUser: aGLHUser ]
^ self at: aGLHUser name ifAbsentPut: [
self initACatalogueEntryForUser: aGLHUser ]
]

{ #category : #adding }
GLHUserCatalogueV2 >> addUser: aGLHUser withName: name [

self
at: aGLHUser name
ifPresent: [ :entry | (entry at: #names) add: name ]
ifAbsentPut: [
|entry|
entry := (self newEntryForUser: aGLHUser).
(entry at: #names) add: name.
entry
]
^ self addUser: aGLHUser withNames: { name }

]

{ #category : #adding }
GLHUserCatalogueV2 >> addUser: aGLHUser withNames: aCollectionOfNames [

self
| entry |
entry := (self
at: aGLHUser name
ifPresent: [ :entry | (entry at: #names) addAll: aCollectionOfNames ]
ifAbsentPut: [
|entry|
entry := (self newEntryForUser: aGLHUser ).
(entry at: #names ) addAll: aCollectionOfNames.
entry ]
ifAbsentPut: [ (self initACatalogueEntryForUser: aGLHUser ). ]).
(entry at: #names) addAll: aCollectionOfNames.
^ entry
]

{ #category : #adding }
GLHUserCatalogueV2 >> addUser: aGLHUser withNames: aCollectionOfNames withProject: aProjectID [

^ self addUser: aGLHUser withNames: aCollectionOfNames withProjects: { aProjectID }
]

{ #category : #adding }
GLHUserCatalogueV2 >> addUser: aGLHUser withNames: aCollectionOfNames withProjects: aCollectionOfProjectIDs [
|entry|

entry := self addUser: aGLHUser withNames: aCollectionOfNames.
(entry at: #contributedProjects) addAll: aCollectionOfProjectIDs.
^ entry.

]

{ #category : #adding }
GLHUserCatalogueV2 >> addUser: aGLHUser withProject: aProjectID [

^ self addUser: aGLHUser withProjects: {aProjectID}.

]

{ #category : #adding }
GLHUserCatalogueV2 >> addUser: aGLHUser withProjects: aCollectionOfProjectIDs [
|entry|

entry := self addUser: aGLHUser.
(entry at: #contributedProjects) addAll: aCollectionOfProjectIDs.
^ entry.

]

{ #category : #accessing }
Expand All @@ -163,6 +188,12 @@ GLHUserCatalogueV2 >> anImporter: aGLHModelImporter [

]

{ #category : #accessing }
GLHUserCatalogueV2 >> atId: anId [
^ self detect: [ :entry |
(entry at: #user) id = anId ]
]

{ #category : #'as yet unclassified' }
GLHUserCatalogueV2 >> collectUsernames [

Expand Down Expand Up @@ -214,30 +245,48 @@ GLHUserCatalogueV2 >> exportToJson [
(#id -> assoc key id) } asDictionary); yourself ]."
tempDic := Dictionary new.
self associationsDo: [ :assoc |
| entry user names |
|entry user names projectIDs|
entry := assoc value.
user := entry at: #user.
names := entry at: #names.
projectIDs := entry at: #contributedProjects.
tempDic
at: assoc key put: {
(#name -> user name).
(#username -> user username).
(#foundNames -> names asArray).
(#contributedProjects -> projectIDs asArray).
(#id -> user id) } asDictionary;
yourself ].

^ STONJSON toString: tempDic
^ STONJSON toStringPretty: tempDic
]

{ #category : #fuse }
GLHUserCatalogueV2 >> fuse: mainUser with: subUser [
self at: mainUser ifPresent: [ :entry |
self at: subUser ifAbsent: [ ^ self ].
(entry at: #names) addAll: (self at: subUser at: #names ).
(entry at: #contributedProjects) addAll: (self at: subUser at: #contributedProjects ).
self removeKey: subUser.
].
]

{ #category : #'instance creation' }
GLHUserCatalogueV2 >> initACatalogueEntryForUser: aGLHUser [.

^ Dictionary new
at: #user put: aGLHUser;
at: #names put: (Set new
add: aGLHUser username;
add: aGLHUser name;
yourself);
at: #contributedProjects put: (Set new
addAll: (aGLHUser contributedProjects collect: #id);
yourself );
yourself
]

{ #category : #initialization }
GLHUserCatalogueV2 >> initialize [

Expand Down Expand Up @@ -271,18 +320,6 @@ GLHUserCatalogueV2 >> namesAt: aGLHUser [
^ (self at: aGLHUser name) at: #names.
]

{ #category : #'instance creation' }
GLHUserCatalogueV2 >> newEntryForUser: aGLHUser [.

^ Dictionary new
at: #user put: aGLHUser;
at: #names put: (Set new
add: aGLHUser username;
add: aGLHUser name;
yourself);
yourself
]

{ #category : #'as yet unclassified' }
GLHUserCatalogueV2 >> reImportAllUsers [
"use it after a catalogue import from JSON"
Expand All @@ -299,10 +336,37 @@ GLHUserCatalogueV2 >> reImportAllUsers [
assoc value at: #user put: user ]
]

{ #category : #'as yet unclassified' }
GLHUserCatalogueV2 >> reImportUser: aGLHUser [
"use it after a catalogue import from JSON"
|user|
user := anImporter
ifNotNil: [
aGLHUser id
ifNotNil: [ anImporter importUser: aGLHUser id ]
ifNil: [ anImporter importUserByUsername: aGLHUser username ] ]
ifNil: [aGLHUser].


self at: aGLHUser name at: #user put: (user).

]

{ #category : #scrape }
GLHUserCatalogueV2 >> scrapeAuthorNameForAllRealUsers [

|listOfUsers|
listOfUsers := self users select: [ :user | user id isNotNil ].
listOfUsers do: [ :user | self scrapeAuthorNameForUser: user ].
]

{ #category : #'as yet unclassified' }
GLHUserCatalogueV2 >> scrapeAuthorNameForAllUsers [

self users do: [ :user | self scrapeAuthorNameForUser: user ]
|listOfUsers|

listOfUsers := self users.
listOfUsers do: [ :user | self scrapeAuthorNameForUser: user ]
]

{ #category : #'as yet unclassified' }
Expand Down
20 changes: 18 additions & 2 deletions src/GitLabHealth-Model-Analysis/GitMetricExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,32 @@ GitMetricExporter >> entities: aCollection [
{ #category : #exporting }
GitMetricExporter >> exportFor: usersWithProjects [

self exportFor: usersWithProjects over: { Date. Week . Month . Year }.
self
deprecated: 'Use #exportInCSV instead'
on: '03 Sept 2024'
in:
'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.

self exportFor: usersWithProjects over: {
Date.
Week.
Month.
Year }
]

{ #category : #exporting }
GitMetricExporter >> exportFor: usersWithProjects over: aCollectionOfDateWeekMonthOrYear [

self
deprecated: 'Use #exportInCSV instead'
on: '03 Sept 2024'
in:
'Pharo-11.0.0+build.726.sha.aece1b5473acf3830a0e082c1bc3a15d4ff3522b (64 Bit)'.

entities ifNil: [
self addEntitiesFromUserNamesAndProjects: usersWithProjects ].

self exportFor: aCollectionOfDateWeekMonthOrYear.
self exportFor: aCollectionOfDateWeekMonthOrYear
]

{ #category : #exporting }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
MergeRequestDurationMetric >> calculate [

| groupedByDate gitAnalyzer mergeRequestsValidation filterGroups |
userMergeRequests ifNil: [ self load ].
userMergeRequests ifNil: [ self load ].
groupedByDate := self setupGroupedDate.

userMergeRequests ifEmpty: [ ^ nil ].
Expand Down Expand Up @@ -47,13 +47,13 @@ MergeRequestDurationMetric >> calculate [

filterGroups at: assoc key put: sum / denominator ].

^ filterGroups average asDuration
^ filterGroups average asSeconds
]

{ #category : #accessing }
MergeRequestDurationMetric >> description [

^ 'merge request duration'
^ 'merge request duration (in seconds)'
]

{ #category : #accessing }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ TimeBetweenCommitMetric >> calculate [
(commits2 committed_date
- commits1 committed_date)
asSeconds ].


differences average asDuration ].
differences average asFloat ].

average := groupedByDate
ifEmpty: [ nil ]
Expand All @@ -46,7 +47,7 @@ TimeBetweenCommitMetric >> calculate [
{ #category : #accessing }
TimeBetweenCommitMetric >> description [

^ 'average time between commits'
^ 'average time between commits (in seconds)'
]

{ #category : #accessing }
Expand Down
Loading

0 comments on commit d353ae6

Please sign in to comment.