Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

Side by Side Diff: commit_queue.py

Issue 12045029: Add CQ Top Score dashboard. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/chromium-status
Patch Set: Add "Top scores" link to all CQ pags Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « app.yaml ('k') | main.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Commit queue status.""" 5 """Commit queue status."""
6 6
7 import cgi 7 import cgi
8 import datetime 8 import datetime
9 import json 9 import json
10 import logging 10 import logging
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 if not self.user: 308 if not self.user:
309 user = None 309 user = None
310 else: 310 else:
311 user = self.user.email() 311 user = self.user.email()
312 return user 312 return user
313 313
314 314
315 class OwnerStats(object): 315 class OwnerStats(object):
316 """CQ usage statistics for a single user.""" 316 """CQ usage statistics for a single user."""
317 def __init__(self, now, owner, last_day, last_week, last_month, forever): 317 def __init__(self, now, owner, last_day, last_week, last_month, forever):
318 # Since epoch in float.
318 self.now = now 319 self.now = now
320 # User instance.
319 self.owner = owner 321 self.owner = owner
322 assert all(isinstance(i, PendingCommit) for i in last_day)
320 self.last_day = last_day 323 self.last_day = last_day
324 assert all(isinstance(i, PendingCommit) for i in last_week)
321 self.last_week = last_week 325 self.last_week = last_week
326 assert isinstance(last_month, int)
322 self.last_month = last_month 327 self.last_month = last_month
328 assert isinstance(forever, int)
323 self.forever = forever 329 self.forever = forever
330 # Gamify ALL the things!
331 self.points = (
332 len(self.last_day) * 10 +
333 len(self.last_week) * 5 +
334 self.last_month + 2 +
335 self.forever)
324 336
325 337
326 class OwnerQuery(object): 338 class OwnerQuery(object):
327 def __init__(self, owner_key, now): 339 def __init__(self, owner_key, now):
328 self.owner_key = owner_key 340 self.owner_key = owner_key
329 self.now = now 341 self.now = now
330 since = lambda x: now - datetime.timedelta(days=x) 342 since = lambda x: now - datetime.timedelta(days=x)
331 self._owner = db.get_async(owner_key) 343 self._owner = db.get_async(owner_key)
332 self._last_day = self._pendings().filter('created >=', since(1)).run() 344 self._last_day = self._pendings().filter('created >=', since(1)).run()
333 self._last_week = self._pendings().filter( 345 self._last_week = self._pendings().filter(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 'last_month': stats.last_month, 407 'last_month': stats.last_month,
396 'forever': stats.forever, 408 'forever': stats.forever,
397 } 409 }
398 owners.append(data) 410 owners.append(data)
399 owners.sort(key=lambda x: -x['last_month']) 411 owners.sort(key=lambda x: -x['last_month'])
400 template_values = self.InitializeTemplate(self.APP_NAME + ' Commit queue') 412 template_values = self.InitializeTemplate(self.APP_NAME + ' Commit queue')
401 template_values['data'] = owners 413 template_values['data'] = owners
402 self.DisplayTemplate('cq_owners.html', template_values, use_cache=True) 414 self.DisplayTemplate('cq_owners.html', template_values, use_cache=True)
403 415
404 416
417 class TopScore(CQBasePage):
418 def _get_as_html(self, _):
419 owners = [
420 {
421 'name': stats.owner.email.split('@', 1)[0].upper(),
422 'points': stats.points,
423 }
424 for stats in monthly_top_contributors()
425 ]
426 owners.sort(key=lambda x: -x['points'])
427 for i in xrange(len(owners)):
428 if i == 0:
429 owners[i]['rank'] = '1st'
430 elif i == 1:
431 owners[i]['rank'] = '2nd'
432 elif i == 2:
433 owners[i]['rank'] = '3rd'
434 else:
435 owners[i]['rank'] = '%dth' % (i + 1)
436 template_values = self.InitializeTemplate(self.APP_NAME + ' Commit queue')
437 template_values['data'] = owners
438 self.DisplayTemplate('cq_top_score.html', template_values, use_cache=True)
439
440
405 class User(CQBasePage): 441 class User(CQBasePage):
406 def _get_as_html(self, query): 442 def _get_as_html(self, query):
407 pending_commits_events = {} 443 pending_commits_events = {}
408 pending_commits = {} 444 pending_commits = {}
409 for event in query.fetch(self._get_limit()): 445 for event in query.fetch(self._get_limit()):
410 # Implicitly find PendingCommit's. 446 # Implicitly find PendingCommit's.
411 pending_commit = event.parent() 447 pending_commit = event.parent()
412 if not pending_commit: 448 if not pending_commit:
413 logging.warn('Event %s is corrupted, can\'t find %s' % ( 449 logging.warn('Event %s is corrupted, can\'t find %s' % (
414 event.key().id_or_name(), event.parent_key().id_or_name())) 450 event.key().id_or_name(), event.parent_key().id_or_name()))
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 546
511 547
512 def bootstrap(): 548 def bootstrap():
513 # Used by _parse_packet() to find the right model to use from the 549 # Used by _parse_packet() to find the right model to use from the
514 # 'verification' value of the packet. 550 # 'verification' value of the packet.
515 module = sys.modules[__name__] 551 module = sys.modules[__name__]
516 for i in dir(module): 552 for i in dir(module):
517 if i.endswith('Event') and i != 'VerificationEvent': 553 if i.endswith('Event') and i != 'VerificationEvent':
518 obj = getattr(module, i) 554 obj = getattr(module, i)
519 EVENT_MAP[obj.name] = obj 555 EVENT_MAP[obj.name] = obj
OLDNEW
« no previous file with comments | « app.yaml ('k') | main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698