##// END OF EJS Templates
fixed bug in summary graph
marcink -
r439:728fbb69 default
parent child Browse files
Show More
@@ -1,142 +1,139 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 # summary controller for pylons
3 # summary controller for pylons
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
5 #
6 # This program is free software; you can redistribute it and/or
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
9 # of the License or (at your opinion) any later version of the license.
10 #
10 #
11 # This program is distributed in the hope that it will be useful,
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
14 # GNU General Public License for more details.
15 #
15 #
16 # You should have received a copy of the GNU General Public License
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
19 # MA 02110-1301, USA.
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 datetime import datetime, timedelta
26 from pylons import tmpl_context as c, request
26 from pylons import tmpl_context as c, request
27 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
28 from pylons_app.lib.base import BaseController, render
28 from pylons_app.lib.base import BaseController, render
29 from pylons_app.lib.helpers import person
29 from pylons_app.lib.helpers import person
30 from pylons_app.lib.utils import OrderedDict
30 from pylons_app.lib.utils import OrderedDict
31 from pylons_app.model.hg_model import HgModel
31 from pylons_app.model.hg_model import HgModel
32 from time import mktime
32 from time import mktime
33 from webhelpers.paginate import Page
33 from webhelpers.paginate import Page
34 import calendar
34 import calendar
35 import logging
35 import logging
36
36
37 log = logging.getLogger(__name__)
37 log = logging.getLogger(__name__)
38
38
39 class SummaryController(BaseController):
39 class SummaryController(BaseController):
40
40
41 @LoginRequired()
41 @LoginRequired()
42 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
42 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
43 'repository.admin')
43 'repository.admin')
44 def __before__(self):
44 def __before__(self):
45 super(SummaryController, self).__before__()
45 super(SummaryController, self).__before__()
46
46
47 def index(self):
47 def index(self):
48 hg_model = HgModel()
48 hg_model = HgModel()
49 c.repo_info = hg_model.get_repo(c.repo_name)
49 c.repo_info = hg_model.get_repo(c.repo_name)
50 c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20)
50 c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20)
51 e = request.environ
51 e = request.environ
52 uri = u'%(protocol)s://%(user)s@%(host)s/%(repo_name)s' % {
52 uri = u'%(protocol)s://%(user)s@%(host)s/%(repo_name)s' % {
53 'protocol': e.get('wsgi.url_scheme'),
53 'protocol': e.get('wsgi.url_scheme'),
54 'user':str(c.hg_app_user.username),
54 'user':str(c.hg_app_user.username),
55 'host':e.get('HTTP_HOST'),
55 'host':e.get('HTTP_HOST'),
56 'repo_name':c.repo_name, }
56 'repo_name':c.repo_name, }
57 c.clone_repo_url = uri
57 c.clone_repo_url = uri
58 c.repo_tags = OrderedDict()
58 c.repo_tags = OrderedDict()
59 for name, hash in c.repo_info.tags.items()[:10]:
59 for name, hash in c.repo_info.tags.items()[:10]:
60 c.repo_tags[name] = c.repo_info.get_changeset(hash)
60 c.repo_tags[name] = c.repo_info.get_changeset(hash)
61
61
62 c.repo_branches = OrderedDict()
62 c.repo_branches = OrderedDict()
63 for name, hash in c.repo_info.branches.items()[:10]:
63 for name, hash in c.repo_info.branches.items()[:10]:
64 c.repo_branches[name] = c.repo_info.get_changeset(hash)
64 c.repo_branches[name] = c.repo_info.get_changeset(hash)
65
65
66 c.commit_data = self.__get_commit_stats(c.repo_info)
66 c.commit_data = self.__get_commit_stats(c.repo_info)
67
67
68 return render('summary/summary.html')
68 return render('summary/summary.html')
69
69
70
70
71
71
72 def __get_commit_stats(self, repo):
72 def __get_commit_stats(self, repo):
73 aggregate = OrderedDict()
73 aggregate = OrderedDict()
74
74
75 #graph range
75 #graph range
76 td = datetime.today() + timedelta(days=1)
76 td = datetime.today() + timedelta(days=1)
77 y = td.year
77 y, m, d = td.year, td.month, td.day
78 m = td.month
78 c.ts_min = mktime((y, (td - timedelta(days=calendar.mdays[m])).month,
79 d = td.day
80 c.ts_min = mktime((y, (td - timedelta(days=calendar.mdays[m] - 1)).month,
81 d, 0, 0, 0, 0, 0, 0,))
79 d, 0, 0, 0, 0, 0, 0,))
82 c.ts_max = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
80 c.ts_max = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
83
84
81
85 def author_key_cleaner(k):
82 def author_key_cleaner(k):
86 k = person(k)
83 k = person(k)
87 k = k.replace('"', "'") #for js data compatibilty
84 k = k.replace('"', "'") #for js data compatibilty
88 return k
85 return k
89
86
90 for cs in repo[:200]:#added limit 200 until fix #29 is made
87 for cs in repo[:200]:#added limit 200 until fix #29 is made
91 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
88 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
92 cs.date.timetuple()[2])
89 cs.date.timetuple()[2])
93 timetupple = [int(x) for x in k.split('-')]
90 timetupple = [int(x) for x in k.split('-')]
94 timetupple.extend([0 for _ in xrange(6)])
91 timetupple.extend([0 for _ in xrange(6)])
95 k = mktime(timetupple)
92 k = mktime(timetupple)
96 if aggregate.has_key(author_key_cleaner(cs.author)):
93 if aggregate.has_key(author_key_cleaner(cs.author)):
97 if aggregate[author_key_cleaner(cs.author)].has_key(k):
94 if aggregate[author_key_cleaner(cs.author)].has_key(k):
98 aggregate[author_key_cleaner(cs.author)][k]["commits"] += 1
95 aggregate[author_key_cleaner(cs.author)][k]["commits"] += 1
99 aggregate[author_key_cleaner(cs.author)][k]["added"] += len(cs.added)
96 aggregate[author_key_cleaner(cs.author)][k]["added"] += len(cs.added)
100 aggregate[author_key_cleaner(cs.author)][k]["changed"] += len(cs.changed)
97 aggregate[author_key_cleaner(cs.author)][k]["changed"] += len(cs.changed)
101 aggregate[author_key_cleaner(cs.author)][k]["removed"] += len(cs.removed)
98 aggregate[author_key_cleaner(cs.author)][k]["removed"] += len(cs.removed)
102
99
103 else:
100 else:
104 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
101 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
105 if k >= c.ts_min and k <= c.ts_max:
102 if k >= c.ts_min and k <= c.ts_max:
106 aggregate[author_key_cleaner(cs.author)][k] = {}
103 aggregate[author_key_cleaner(cs.author)][k] = {}
107 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1
104 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1
108 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added)
105 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added)
109 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed)
106 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed)
110 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed)
107 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed)
111
108
112 else:
109 else:
113 if k >= c.ts_min and k <= c.ts_max:
110 if k >= c.ts_min and k <= c.ts_max:
114 aggregate[author_key_cleaner(cs.author)] = OrderedDict()
111 aggregate[author_key_cleaner(cs.author)] = OrderedDict()
115 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
112 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
116 aggregate[author_key_cleaner(cs.author)][k] = {}
113 aggregate[author_key_cleaner(cs.author)][k] = {}
117 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1
114 aggregate[author_key_cleaner(cs.author)][k]["commits"] = 1
118 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added)
115 aggregate[author_key_cleaner(cs.author)][k]["added"] = len(cs.added)
119 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed)
116 aggregate[author_key_cleaner(cs.author)][k]["changed"] = len(cs.changed)
120 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed)
117 aggregate[author_key_cleaner(cs.author)][k]["removed"] = len(cs.removed)
121
118
122 d = ''
119 d = ''
123 tmpl0 = u""""%s":%s"""
120 tmpl0 = u""""%s":%s"""
124 tmpl1 = u"""{label:"%s",data:%s,schema:["commits"]},"""
121 tmpl1 = u"""{label:"%s",data:%s,schema:["commits"]},"""
125 for author in aggregate:
122 for author in aggregate:
126
123
127 d += tmpl0 % (author,
124 d += tmpl0 % (author,
128 tmpl1 \
125 tmpl1 \
129 % (author,
126 % (author,
130 [{"time":x,
127 [{"time":x,
131 "commits":aggregate[author][x]['commits'],
128 "commits":aggregate[author][x]['commits'],
132 "added":aggregate[author][x]['added'],
129 "added":aggregate[author][x]['added'],
133 "changed":aggregate[author][x]['changed'],
130 "changed":aggregate[author][x]['changed'],
134 "removed":aggregate[author][x]['removed'],
131 "removed":aggregate[author][x]['removed'],
135 } for x in aggregate[author]]))
132 } for x in aggregate[author]]))
136 if d == '':
133 if d == '':
137 d = '"%s":{label:"%s",data:[[0,1],]}' \
134 d = '"%s":{label:"%s",data:[[0,1],]}' \
138 % (author_key_cleaner(repo.contact),
135 % (author_key_cleaner(repo.contact),
139 author_key_cleaner(repo.contact))
136 author_key_cleaner(repo.contact))
140 return d
137 return d
141
138
142
139
General Comments 0
You need to be logged in to leave comments. Login now