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