Pārlūkot izejas kodu

combine like authors

Dan Rapp 7 gadus atpakaļ
vecāks
revīzija
77d4d53b17
3 mainītis faili ar 29 papildinājumiem un 4 dzēšanām
  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 Parādīt failu

@@ -1,6 +1,8 @@
1
+from collections import defaultdict
1 2
 from dataclasses import dataclass, field
2 3
 from datetime import timedelta
3
-from typing import Set
4
+from typing import Dict, Set
5
+
4 6
 
5 7
 @dataclass
6 8
 class Author:
@@ -16,4 +18,8 @@ class Author:
16 18
     date_first: str = ''
17 19
     date_last: str = ''
18 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 Parādīt failu

@@ -26,6 +26,11 @@ class GitDataCollector(DataCollector):
26 26
         self.get_loc_info()
27 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 34
     def get_author_info(self):
30 35
         # Per-author statistics
31 36
         # defined for stamp, author only if author commited at this timestamp.
@@ -51,6 +56,7 @@ class GitDataCollector(DataCollector):
51 56
                     try:
52 57
                         oldstamp = stamp
53 58
                         (stamp, author) = (int(line[:pos]), line[pos + 1:])
59
+                        author = self.xlate(author)
54 60
                         if oldstamp > stamp:
55 61
                             # clock skew, keep old timestamp to avoid having ugly graph
56 62
                             stamp = oldstamp
@@ -202,7 +208,7 @@ class GitDataCollector(DataCollector):
202 208
                 stamp = 0
203 209
             timezone = parts[3]
204 210
             author, mail = parts[4].split('<', 1)
205
-            author = author.rstrip()
211
+            author = self.xlate(author.rstrip())
206 212
             mail = mail.rstrip('>')
207 213
             domain = '?'
208 214
             if mail.find('@') != -1:
@@ -254,6 +260,7 @@ class GitDataCollector(DataCollector):
254 260
             # author stats
255 261
             if author not in self.authors:
256 262
                 self.authors[author] = Author()
263
+            self.authors[author].activity_by_day_and_hour[day][hour] += 1
257 264
             # commits, note again that commits may be in any date order because of cherry-picking and patches
258 265
             if not self.authors[author].last_commit_stamp:
259 266
                 self.authors[author].last_commit_stamp = stamp
@@ -395,6 +402,11 @@ class GitDataCollector(DataCollector):
395 402
             a.date_first = date_first.strftime('%Y-%m-%d')
396 403
             a.date_last = date_last.strftime('%Y-%m-%d')
397 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 411
     def getActiveDays(self):
400 412
         return self.active_days
@@ -435,7 +447,9 @@ class GitDataCollector(DataCollector):
435 447
         return self.revToDate('tags/' + tag)
436 448
 
437 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 454
     def getTotalCommits(self):
441 455
         return self.total_commits

+ 6
- 1
gitstats/gitstats.py Parādīt failu

@@ -28,7 +28,12 @@ conf = {
28 28
     'project_name': '',
29 29
     'processes': 8,
30 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 39
 class GitStats: