Browse Source

combine like authors

Dan Rapp 7 years ago
parent
commit
77d4d53b17
3 changed files with 29 additions and 4 deletions
  1. 7
    1
      gitstats/data/author.py
  2. 16
    2
      gitstats/gitdatacollector.py
  3. 6
    1
      gitstats/gitstats.py

+ 7
- 1
gitstats/data/author.py View File

1
+from collections import defaultdict
1
 from dataclasses import dataclass, field
2
 from dataclasses import dataclass, field
2
 from datetime import timedelta
3
 from datetime import timedelta
3
-from typing import Set
4
+from typing import Dict, Set
5
+
4
 
6
 
5
 @dataclass
7
 @dataclass
6
 class Author:
8
 class Author:
16
     date_first: str = ''
18
     date_first: str = ''
17
     date_last: str = ''
19
     date_last: str = ''
18
     timedelta: timedelta = None
20
     timedelta: timedelta = None
21
+    activity_by_day_and_hour: Dict[int, Dict[int, int]] = field(default_factory=lambda: defaultdict(lambda: defaultdict(int)))
22
+    extra_effort: int = 0
23
+    extra_frac: float = 0.0
24
+
19
 
25
 

+ 16
- 2
gitstats/gitdatacollector.py View File

26
         self.get_loc_info()
26
         self.get_loc_info()
27
         self.get_author_info()
27
         self.get_author_info()
28
 
28
 
29
+    def xlate(self, name):
30
+        if name in self.conf['name_xlate']:
31
+            return self.conf['name_xlate'][name]
32
+        return name
33
+
29
     def get_author_info(self):
34
     def get_author_info(self):
30
         # Per-author statistics
35
         # Per-author statistics
31
         # defined for stamp, author only if author commited at this timestamp.
36
         # defined for stamp, author only if author commited at this timestamp.
51
                     try:
56
                     try:
52
                         oldstamp = stamp
57
                         oldstamp = stamp
53
                         (stamp, author) = (int(line[:pos]), line[pos + 1:])
58
                         (stamp, author) = (int(line[:pos]), line[pos + 1:])
59
+                        author = self.xlate(author)
54
                         if oldstamp > stamp:
60
                         if oldstamp > stamp:
55
                             # clock skew, keep old timestamp to avoid having ugly graph
61
                             # clock skew, keep old timestamp to avoid having ugly graph
56
                             stamp = oldstamp
62
                             stamp = oldstamp
202
                 stamp = 0
208
                 stamp = 0
203
             timezone = parts[3]
209
             timezone = parts[3]
204
             author, mail = parts[4].split('<', 1)
210
             author, mail = parts[4].split('<', 1)
205
-            author = author.rstrip()
211
+            author = self.xlate(author.rstrip())
206
             mail = mail.rstrip('>')
212
             mail = mail.rstrip('>')
207
             domain = '?'
213
             domain = '?'
208
             if mail.find('@') != -1:
214
             if mail.find('@') != -1:
254
             # author stats
260
             # author stats
255
             if author not in self.authors:
261
             if author not in self.authors:
256
                 self.authors[author] = Author()
262
                 self.authors[author] = Author()
263
+            self.authors[author].activity_by_day_and_hour[day][hour] += 1
257
             # commits, note again that commits may be in any date order because of cherry-picking and patches
264
             # commits, note again that commits may be in any date order because of cherry-picking and patches
258
             if not self.authors[author].last_commit_stamp:
265
             if not self.authors[author].last_commit_stamp:
259
                 self.authors[author].last_commit_stamp = stamp
266
                 self.authors[author].last_commit_stamp = stamp
395
             a.date_first = date_first.strftime('%Y-%m-%d')
402
             a.date_first = date_first.strftime('%Y-%m-%d')
396
             a.date_last = date_last.strftime('%Y-%m-%d')
403
             a.date_last = date_last.strftime('%Y-%m-%d')
397
             a.timedelta = delta
404
             a.timedelta = delta
405
+            for day in range(6):
406
+                for hour in range(24):
407
+                    if day > 4 or hour < 8 or hour > 17:
408
+                        a.extra_effort += a.activity_by_day_and_hour[day][hour]
409
+            a.extra_frac = (100 * float(a.extra_effort)) / a.commits
398
 
410
 
399
     def getActiveDays(self):
411
     def getActiveDays(self):
400
         return self.active_days
412
         return self.active_days
435
         return self.revToDate('tags/' + tag)
447
         return self.revToDate('tags/' + tag)
436
 
448
 
437
     def getTotalAuthors(self):
449
     def getTotalAuthors(self):
438
-        return self.total_authors
450
+        # because we are equating names (see name_xlate), the total authors will be the number of
451
+        # elements in the authors dictionary rather than the count from the git log
452
+        return len(self.authors)
439
 
453
 
440
     def getTotalCommits(self):
454
     def getTotalCommits(self):
441
         return self.total_commits
455
         return self.total_commits

+ 6
- 1
gitstats/gitstats.py View File

28
     'project_name': '',
28
     'project_name': '',
29
     'processes': 8,
29
     'processes': 8,
30
     'start_date': '',
30
     'start_date': '',
31
-    'logging': logging.INFO
31
+    'logging': logging.INFO,
32
+    'name_xlate': {
33
+        'lmonson': 'Lynn Monson',
34
+        'DallanQ': 'Dallan Quass',
35
+        'Daniel Rapp': 'Dan Rapp'
36
+    }
32
 }
37
 }
33
 
38
 
34
 class GitStats:
39
 class GitStats: