comparison pylons_app/controllers/summary.py @ 362:558eb7c5028f rhodecode-0.0.0.8.0

version bump to 0.8 hg app 0.8 new template. Add yui flot and graph into summary page. + various tweeks and patches into look of application
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 24 Jul 2010 02:17:48 +0200
parents fdf9f6ee5217
children ec7b76d4bda4
comparison
equal deleted inserted replaced
361:3581656180b7 362:558eb7c5028f
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 #
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 26 from pylons import tmpl_context as c, request
26 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator 27 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
27 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
30 from pylons_app.lib.utils import OrderedDict
28 from pylons_app.model.hg_model import HgModel 31 from pylons_app.model.hg_model import HgModel
32 from time import mktime
29 from webhelpers.paginate import Page 33 from webhelpers.paginate import Page
34 import calendar
30 import logging 35 import logging
36
31 log = logging.getLogger(__name__) 37 log = logging.getLogger(__name__)
32 38
33 class SummaryController(BaseController): 39 class SummaryController(BaseController):
34 40
35 @LoginRequired() 41 @LoginRequired()
54 c.repo_tags[name] = c.repo_info.get_changeset(hash) 60 c.repo_tags[name] = c.repo_info.get_changeset(hash)
55 61
56 c.repo_branches = {} 62 c.repo_branches = {}
57 for name, hash in c.repo_info.branches.items()[:10]: 63 for name, hash in c.repo_info.branches.items()[:10]:
58 c.repo_branches[name] = c.repo_info.get_changeset(hash) 64 c.repo_branches[name] = c.repo_info.get_changeset(hash)
59 65
66 c.commit_data = self.__get_commit_stats(c.repo_info)
67
60 return render('summary/summary.html') 68 return render('summary/summary.html')
69
70
71
72 def __get_commit_stats(self, repo):
73 aggregate = OrderedDict()
74
75
76 #graph range
77 td = datetime.today()
78 y = td.year
79 m = td.month
80 d = td.day
81 c.ts_min = mktime((y, (td - timedelta(days=calendar.mdays[m] - 1)).month, d, 0, 0, 0, 0, 0, 0,))
82 c.ts_max = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
83
84
85 # #generate this monhts keys
86 # dates_range = OrderedDict()
87 # year_range = range(2010, datetime.today().year + 1)
88 # month_range = range(1, datetime.today().month + 1)
89 #
90 #
91 #
92 # for y in year_range:
93 # for m in month_range:
94 # for d in range(1, calendar.mdays[m] + 1):
95 # k = '%s-%s-%s' % (y, m, d)
96 # timetupple = [int(x) for x in k.split('-')]
97 # timetupple.extend([0 for _ in xrange(6)])
98 # k = mktime(timetupple)
99 # dates_range[k] = 0
100
101 def author_key_cleaner(k):
102 k = person(k)
103 return k
104
105 for cs in repo:
106 k = '%s-%s-%s' % (cs.date.timetuple()[0], cs.date.timetuple()[1],
107 cs.date.timetuple()[2])
108 timetupple = [int(x) for x in k.split('-')]
109 timetupple.extend([0 for _ in xrange(6)])
110 k = mktime(timetupple)
111 if aggregate.has_key(author_key_cleaner(cs.author)):
112 if aggregate[author_key_cleaner(cs.author)].has_key(k):
113 aggregate[author_key_cleaner(cs.author)][k] += 1
114 else:
115 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
116 if k >= c.ts_min and k <= c.ts_max:
117 aggregate[author_key_cleaner(cs.author)][k] = 1
118 else:
119 if k >= c.ts_min and k <= c.ts_max:
120 aggregate[author_key_cleaner(cs.author)] = OrderedDict()
121 #aggregate[author_key_cleaner(cs.author)].update(dates_range)
122 aggregate[author_key_cleaner(cs.author)][k] = 1
123
124 d = ''
125 tmpl0 = u""""%s":%s"""
126 tmpl1 = u"""{label:"%s",data:%s},"""
127 for author in aggregate:
128 d += tmpl0 % (author.decode('utf8'),
129 tmpl1 \
130 % (author.decode('utf8'),
131 [[x, aggregate[author][x]] for x in aggregate[author]]))
132 if d == '':
133 d = '"%s":{label:"%s",data:[[0,0],]}' \
134 % (author_key_cleaner(repo.contact),
135 author_key_cleaner(repo.contact))
136 return d
137
138