Browse Source

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

Heikki Hokkanen 16 years ago
parent
commit
52a20a7b09
1 changed files with 10 additions and 40 deletions
  1. 10
    40
      gitstats

+ 10
- 40
gitstats View File

238
 			# activity
238
 			# activity
239
 			# hour
239
 			# hour
240
 			hour = date.hour
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
 			# most active hour?
242
 			# most active hour?
246
 			if self.activity_by_hour_of_day[hour] > self.activity_by_hour_of_day_busiest:
243
 			if self.activity_by_hour_of_day[hour] > self.activity_by_hour_of_day_busiest:
247
 				self.activity_by_hour_of_day_busiest = self.activity_by_hour_of_day[hour]
244
 				self.activity_by_hour_of_day_busiest = self.activity_by_hour_of_day[hour]
248
 
245
 
249
 			# day of week
246
 			# day of week
250
 			day = date.weekday()
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
 			# hour of week
250
 			# hour of week
257
 			if day not in self.activity_by_hour_of_week:
251
 			if day not in self.activity_by_hour_of_week:
258
 				self.activity_by_hour_of_week[day] = {}
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
 			# most active hour?
254
 			# most active hour?
264
 			if self.activity_by_hour_of_week[day][hour] > self.activity_by_hour_of_week_busiest:
255
 			if self.activity_by_hour_of_week[day][hour] > self.activity_by_hour_of_week_busiest:
265
 				self.activity_by_hour_of_week_busiest = self.activity_by_hour_of_week[day][hour]
256
 				self.activity_by_hour_of_week_busiest = self.activity_by_hour_of_week[day][hour]
266
 
257
 
267
 			# month of year
258
 			# month of year
268
 			month = date.month
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
 			# yearly/weekly activity
262
 			# yearly/weekly activity
275
 			yyw = date.strftime('%Y-%W')
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
 			if self.activity_by_year_week_peak < self.activity_by_year_week[yyw]:
265
 			if self.activity_by_year_week_peak < self.activity_by_year_week[yyw]:
281
 				self.activity_by_year_week_peak = self.activity_by_year_week[yyw]
266
 				self.activity_by_year_week_peak = self.activity_by_year_week[yyw]
282
 
267
 
287
 			if 'last_commit_stamp' not in self.authors[author]:
272
 			if 'last_commit_stamp' not in self.authors[author]:
288
 				self.authors[author]['last_commit_stamp'] = stamp
273
 				self.authors[author]['last_commit_stamp'] = stamp
289
 			self.authors[author]['first_commit_stamp'] = stamp
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
 			# author of the month/year
277
 			# author of the month/year
296
 			yymm = date.strftime('%Y-%m')
278
 			yymm = date.strftime('%Y-%m')
297
 			if yymm in self.author_of_month:
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
 			else:
281
 			else:
303
 				self.author_of_month[yymm] = {}
282
 				self.author_of_month[yymm] = {}
304
 				self.author_of_month[yymm][author] = 1
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
 			yy = date.year
286
 			yy = date.year
311
 			if yy in self.author_of_year:
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
 			else:
289
 			else:
317
 				self.author_of_year[yy] = {}
290
 				self.author_of_year[yy] = {}
318
 				self.author_of_year[yy][author] = 1
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
 			# authors: active days
294
 			# authors: active days
325
 			yymmdd = date.strftime('%Y-%m-%d')
295
 			yymmdd = date.strftime('%Y-%m-%d')