Przeglądaj źródła

Optimization: only run "git-rev-list HEAD" once.

Heikki Hokkanen 18 lat temu
rodzic
commit
4c488e1bfc
1 zmienionych plików z 18 dodań i 21 usunięć
  1. 18
    21
      statgit

+ 18
- 21
statgit Wyświetl plik

@@ -73,46 +73,43 @@ class GitDataCollector(DataCollector):
73 73
 		self.activity_by_hour_of_day = {} # hour -> commits
74 74
 		self.activity_by_day_of_week = {} # day -> commits
75 75
 
76
-		# TODO
77 76
 		self.authors = {} # name -> {commits, first_commit_stamp, last_commit_stamp}
78 77
 
79
-		# activity
80
-		lines = getoutput('git-rev-list HEAD --pretty=format:%at |grep -v ^commit').split('\n')
81
-		for stamp in lines:
82
-			date = datetime.datetime.fromtimestamp(float(stamp))
83
-
84
-			# hour
85
-			hour = date.hour
86
-			if hour in self.activity_by_hour_of_day:
87
-				self.activity_by_hour_of_day[hour] += 1
88
-			else:
89
-				self.activity_by_hour_of_day[hour] = 1
90
-
91
-			# day
92
-			day = date.weekday()
93
-			if day in self.activity_by_day_of_week:
94
-				self.activity_by_day_of_week[day] += 1
95
-			else:
96
-				self.activity_by_day_of_week[day] = 1
97
-
98
-		# TODO author of the month
78
+		# author of the month
99 79
 		self.author_of_month = {} # month -> author -> commits
100 80
 		self.author_of_year = {} # year -> author -> commits
101 81
 		self.commits_by_month = {} # month -> commits
102 82
 		self.first_commit_stamp = 0
103 83
 		self.last_commit_stamp = 0
104 84
 
85
+		# TODO also collect statistics for "last 30 days"/"last 12 months"
105 86
 		lines = getoutput('git-rev-list --pretty=format:"%at %an" HEAD |grep -v ^commit').split('\n')
106 87
 		for line in lines:
107 88
 			parts = line.split(' ')
108 89
 			stamp = int(parts[0])
109 90
 			author = ' '.join(parts[1:])
91
+			date = datetime.datetime.fromtimestamp(float(stamp))
110 92
 
111 93
 			# First and last commit stamp
112 94
 			if self.last_commit_stamp == 0:
113 95
 				self.last_commit_stamp = stamp
114 96
 			self.first_commit_stamp = stamp
115 97
 
98
+			# activity
99
+			# hour
100
+			hour = date.hour
101
+			if hour in self.activity_by_hour_of_day:
102
+				self.activity_by_hour_of_day[hour] += 1
103
+			else:
104
+				self.activity_by_hour_of_day[hour] = 1
105
+
106
+			# day
107
+			day = date.weekday()
108
+			if day in self.activity_by_day_of_week:
109
+				self.activity_by_day_of_week[day] += 1
110
+			else:
111
+				self.activity_by_day_of_week[day] = 1
112
+
116 113
 			# author stats
117 114
 			if author not in self.authors:
118 115
 				self.authors[author] = {}