Bladeren bron

Cleanup, use get('foo', 0) + 1 instead of if/else.

Heikki Hokkanen 16 jaren geleden
bovenliggende
commit
52a20a7b09
1 gewijzigde bestanden met toevoegingen van 10 en 40 verwijderingen
  1. 10
    40
      gitstats

+ 10
- 40
gitstats Bestand weergeven

@@ -238,45 +238,30 @@ class GitDataCollector(DataCollector):
238 238
 			# activity
239 239
 			# hour
240 240
 			hour = date.hour
241
-			if hour in self.activity_by_hour_of_day:
242
-				self.activity_by_hour_of_day[hour] += 1
243
-			else:
244
-				self.activity_by_hour_of_day[hour] = 1
241
+			self.activity_by_hour_of_day[hour] = self.activity_by_hour_of_day.get(hour, 0) + 1
245 242
 			# most active hour?
246 243
 			if self.activity_by_hour_of_day[hour] > self.activity_by_hour_of_day_busiest:
247 244
 				self.activity_by_hour_of_day_busiest = self.activity_by_hour_of_day[hour]
248 245
 
249 246
 			# day of week
250 247
 			day = date.weekday()
251
-			if day in self.activity_by_day_of_week:
252
-				self.activity_by_day_of_week[day] += 1
253
-			else:
254
-				self.activity_by_day_of_week[day] = 1
248
+			self.activity_by_day_of_week[day] = self.activity_by_day_of_week.get(day, 0) + 1
255 249
 
256 250
 			# hour of week
257 251
 			if day not in self.activity_by_hour_of_week:
258 252
 				self.activity_by_hour_of_week[day] = {}
259
-			if hour not in self.activity_by_hour_of_week[day]:
260
-				self.activity_by_hour_of_week[day][hour] = 1
261
-			else:
262
-				self.activity_by_hour_of_week[day][hour] += 1
253
+			self.activity_by_hour_of_week[day][hour] = self.activity_by_hour_of_week[day].get(hour, 0) + 1
263 254
 			# most active hour?
264 255
 			if self.activity_by_hour_of_week[day][hour] > self.activity_by_hour_of_week_busiest:
265 256
 				self.activity_by_hour_of_week_busiest = self.activity_by_hour_of_week[day][hour]
266 257
 
267 258
 			# month of year
268 259
 			month = date.month
269
-			if month in self.activity_by_month_of_year:
270
-				self.activity_by_month_of_year[month] += 1
271
-			else:
272
-				self.activity_by_month_of_year[month] = 1
260
+			self.activity_by_month_of_year[month] = self.activity_by_month_of_year.get(month, 0) + 1
273 261
 
274 262
 			# yearly/weekly activity
275 263
 			yyw = date.strftime('%Y-%W')
276
-			if yyw not in self.activity_by_year_week:
277
-				self.activity_by_year_week[yyw] = 1
278
-			else:
279
-				self.activity_by_year_week[yyw] += 1
264
+			self.activity_by_year_week[yyw] = self.activity_by_year_week.get(yyw, 0) + 1
280 265
 			if self.activity_by_year_week_peak < self.activity_by_year_week[yyw]:
281 266
 				self.activity_by_year_week_peak = self.activity_by_year_week[yyw]
282 267
 
@@ -287,39 +272,24 @@ class GitDataCollector(DataCollector):
287 272
 			if 'last_commit_stamp' not in self.authors[author]:
288 273
 				self.authors[author]['last_commit_stamp'] = stamp
289 274
 			self.authors[author]['first_commit_stamp'] = stamp
290
-			if 'commits' in self.authors[author]:
291
-				self.authors[author]['commits'] += 1
292
-			else:
293
-				self.authors[author]['commits'] = 1
275
+			self.authors[author]['commits'] = self.authors[author].get('commits', 0) + 1
294 276
 
295 277
 			# author of the month/year
296 278
 			yymm = date.strftime('%Y-%m')
297 279
 			if yymm in self.author_of_month:
298
-				if author in self.author_of_month[yymm]:
299
-					self.author_of_month[yymm][author] += 1
300
-				else:
301
-					self.author_of_month[yymm][author] = 1
280
+				self.author_of_month[yymm][author] = self.author_of_month[yymm].get(author, 0) + 1
302 281
 			else:
303 282
 				self.author_of_month[yymm] = {}
304 283
 				self.author_of_month[yymm][author] = 1
305
-			if yymm in self.commits_by_month:
306
-				self.commits_by_month[yymm] += 1
307
-			else:
308
-				self.commits_by_month[yymm] = 1
284
+			self.commits_by_month[yymm] = self.commits_by_month.get(yymm, 0) + 1
309 285
 
310 286
 			yy = date.year
311 287
 			if yy in self.author_of_year:
312
-				if author in self.author_of_year[yy]:
313
-					self.author_of_year[yy][author] += 1
314
-				else:
315
-					self.author_of_year[yy][author] = 1
288
+				self.author_of_year[yy][author] = self.author_of_year[yy].get(author, 0) + 1
316 289
 			else:
317 290
 				self.author_of_year[yy] = {}
318 291
 				self.author_of_year[yy][author] = 1
319
-			if yy in self.commits_by_year:
320
-				self.commits_by_year[yy] += 1
321
-			else:
322
-				self.commits_by_year[yy] = 1
292
+			self.commits_by_year[yy] = self.commits_by_year.get(yy, 0) + 1
323 293
 
324 294
 			# authors: active days
325 295
 			yymmdd = date.strftime('%Y-%m-%d')