Mercurial > public > src > rhodecode
comparison pylons_app/controllers/summary.py @ 510:3fc3ce53659b celery
starting celery branch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 11 Sep 2010 01:55:46 +0200 |
parents | 728fbb693183 |
children | 6b934c9607e7 |
comparison
equal
deleted
inserted
replaced
509:183cee110578 | 510:3fc3ce53659b |
---|---|
20 """ | 20 """ |
21 Created on April 18, 2010 | 21 Created on April 18, 2010 |
22 summary controller for pylons | 22 summary controller for pylons |
23 @author: marcink | 23 @author: marcink |
24 """ | 24 """ |
25 from datetime import datetime, timedelta | 25 from pylons import tmpl_context as c, request,url |
26 from pylons import tmpl_context as c, request | |
27 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator | 26 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator |
28 from pylons_app.lib.base import BaseController, render | 27 from pylons_app.lib.base import BaseController, render |
29 from pylons_app.lib.helpers import person | |
30 from pylons_app.lib.utils import OrderedDict | 28 from pylons_app.lib.utils import OrderedDict |
31 from pylons_app.model.hg_model import HgModel | 29 from pylons_app.model.hg_model import HgModel |
32 from time import mktime | |
33 from webhelpers.paginate import Page | 30 from webhelpers.paginate import Page |
34 import calendar | 31 from pylons_app.lib.celerylib import run_task |
32 from pylons_app.lib.celerylib.tasks import get_commits_stats | |
35 import logging | 33 import logging |
36 | 34 |
37 log = logging.getLogger(__name__) | 35 log = logging.getLogger(__name__) |
38 | 36 |
39 class SummaryController(BaseController): | 37 class SummaryController(BaseController): |
60 c.repo_tags[name] = c.repo_info.get_changeset(hash) | 58 c.repo_tags[name] = c.repo_info.get_changeset(hash) |
61 | 59 |
62 c.repo_branches = OrderedDict() | 60 c.repo_branches = OrderedDict() |
63 for name, hash in c.repo_info.branches.items()[:10]: | 61 for name, hash in c.repo_info.branches.items()[:10]: |
64 c.repo_branches[name] = c.repo_info.get_changeset(hash) | 62 c.repo_branches[name] = c.repo_info.get_changeset(hash) |
65 | 63 |
66 c.commit_data = self.__get_commit_stats(c.repo_info) | 64 task = run_task(get_commits_stats,False,c.repo_info.name) |
65 c.ts_min = task.result[0] | |
66 c.ts_max = task.result[1] | |
67 c.commit_data = task.result[2] | |
67 | 68 |
68 return render('summary/summary.html') | 69 return render('summary/summary.html') |
69 | 70 |
70 | |
71 | |
72 def __get_commit_stats(self, repo): | |
73 aggregate = OrderedDict() | |
74 | |
75 #graph range | |
76 td = datetime.today() + timedelta(days=1) | |
77 y, m, d = td.year, td.month, td.day | |
78 c.ts_min = mktime((y, (td - timedelta(days=calendar.mdays[m])).month, | |
79 d, 0, 0, 0, 0, 0, 0,)) | |
80 c.ts_max = mktime((y, m, d, 0, 0, 0, 0, 0, 0,)) | |
81 | |
82 def author_key_cleaner(k): | |
83 k = person(k) | |
84 k = k.replace('"', "'") #for js data compatibilty | |
85 return k | |
86 | |
87 for cs in repo[:200]:#added limit 200 until fix #29 is made | |
88 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1], | |
89 cs.date.timetuple()[2]) | |
90 timetupple = [int(x) for x in k.split('-')] | |
91 timetupple.extend([0 for _ in xrange(6)]) | |
92 k = mktime(timetupple) | |
93 if aggregate.has_key(author_key_cleaner(cs.author)): | |
94 if aggregate[author_key_cleaner(cs.author)].has_key(k): | |
95 aggregate[author_key_cleaner(cs.author)][k]["commits"] += 1 | |
96 aggregate[author_key_cleaner(cs.author)][k]["added"] += len(cs.added) | |
97 aggregate[author_key_cleaner(cs.author)][k]["changed"] += len(cs.changed) | |
98 aggregate[author_key_cleaner(cs.author)][k]["removed"] += len(cs.removed) | |
99 | |
100 else: | |
101 #aggregate[author_key_cleaner(cs.author)].update(dates_range) | |
102 if k >= c.ts_min and k <= c.ts_max: | |
103 aggregate[author_key_cleaner(cs.author)][k] = {} | |
104 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1 | |
105 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added) | |
106 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed) | |
107 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed) | |
108 | |
109 else: | |
110 if k >= c.ts_min and k <= c.ts_max: | |
111 aggregate[author_key_cleaner(cs.author)] = OrderedDict() | |
112 #aggregate[author_key_cleaner(cs.author)].update(dates_range) | |
113 aggregate[author_key_cleaner(cs.author)][k] = {} | |
114 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1 | |
115 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added) | |
116 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed) | |
117 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed) | |
118 | |
119 d = '' | |
120 tmpl0 = u""""%s":%s""" | |
121 tmpl1 = u"""{label:"%s",data:%s,schema:["commits"]},""" | |
122 for author in aggregate: | |
123 | |
124 d += tmpl0 % (author, | |
125 tmpl1 \ | |
126 % (author, | |
127 [{"time":x, | |
128 "commits":aggregate[author][x]['commits'], | |
129 "added":aggregate[author][x]['added'], | |
130 "changed":aggregate[author][x]['changed'], | |
131 "removed":aggregate[author][x]['removed'], | |
132 } for x in aggregate[author]])) | |
133 if d == '': | |
134 d = '"%s":{label:"%s",data:[[0,1],]}' \ | |
135 % (author_key_cleaner(repo.contact), | |
136 author_key_cleaner(repo.contact)) | |
137 return d | |
138 | |
139 |