##// END OF EJS Templates
fixed graph bug
marcink -
r937:6489d9b7 beta
parent child Browse files
Show More
@@ -1,147 +1,146 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.controllers.summary
3 rhodecode.controllers.summary
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 Summary controller for Rhodecode
6 Summary controller for Rhodecode
7
7
8 :created_on: Apr 18, 2010
8 :created_on: Apr 18, 2010
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software; you can redistribute it and/or
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; version 2
15 # as published by the Free Software Foundation; version 2
16 # of the License or (at your opinion) any later version of the license.
16 # of the License or (at your opinion) any later version of the license.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27
27
28 import calendar
28 import calendar
29 import logging
29 import logging
30 from time import mktime
30 from time import mktime
31 from datetime import datetime, timedelta
31 from datetime import datetime, timedelta, date
32
32
33 from vcs.exceptions import ChangesetError
33 from vcs.exceptions import ChangesetError
34
34
35 from pylons import tmpl_context as c, request, url
35 from pylons import tmpl_context as c, request, url
36 from pylons.i18n.translation import _
36 from pylons.i18n.translation import _
37
37
38 from rhodecode.model.scm import ScmModel
38 from rhodecode.model.scm import ScmModel
39 from rhodecode.model.db import Statistics
39 from rhodecode.model.db import Statistics
40
40
41 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
41 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
42 from rhodecode.lib.base import BaseController, render
42 from rhodecode.lib.base import BaseController, render
43 from rhodecode.lib.utils import OrderedDict, EmptyChangeset
43 from rhodecode.lib.utils import OrderedDict, EmptyChangeset
44
44
45 from rhodecode.lib.celerylib import run_task
45 from rhodecode.lib.celerylib import run_task
46 from rhodecode.lib.celerylib.tasks import get_commits_stats
46 from rhodecode.lib.celerylib.tasks import get_commits_stats
47
47
48 from webhelpers.paginate import Page
48 from webhelpers.paginate import Page
49
49
50 try:
50 try:
51 import json
51 import json
52 except ImportError:
52 except ImportError:
53 #python 2.5 compatibility
53 #python 2.5 compatibility
54 import simplejson as json
54 import simplejson as json
55 log = logging.getLogger(__name__)
55 log = logging.getLogger(__name__)
56
56
57 class SummaryController(BaseController):
57 class SummaryController(BaseController):
58
58
59 @LoginRequired()
59 @LoginRequired()
60 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
60 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
61 'repository.admin')
61 'repository.admin')
62 def __before__(self):
62 def __before__(self):
63 super(SummaryController, self).__before__()
63 super(SummaryController, self).__before__()
64
64
65 def index(self):
65 def index(self):
66 scm_model = ScmModel()
66 scm_model = ScmModel()
67 c.repo_info = scm_model.get_repo(c.repo_name)
67 c.repo_info = scm_model.get_repo(c.repo_name)
68 c.following = scm_model.is_following_repo(c.repo_name,
68 c.following = scm_model.is_following_repo(c.repo_name,
69 c.rhodecode_user.user_id)
69 c.rhodecode_user.user_id)
70 def url_generator(**kw):
70 def url_generator(**kw):
71 return url('shortlog_home', repo_name=c.repo_name, **kw)
71 return url('shortlog_home', repo_name=c.repo_name, **kw)
72
72
73 c.repo_changesets = Page(c.repo_info, page=1, items_per_page=10,
73 c.repo_changesets = Page(c.repo_info, page=1, items_per_page=10,
74 url=url_generator)
74 url=url_generator)
75
75
76 e = request.environ
76 e = request.environ
77
77
78 if self.rhodecode_user.username == 'default':
78 if self.rhodecode_user.username == 'default':
79 #for default(anonymous) user we don't need to pass credentials
79 #for default(anonymous) user we don't need to pass credentials
80 username = ''
80 username = ''
81 password = ''
81 password = ''
82 else:
82 else:
83 username = str(c.rhodecode_user.username)
83 username = str(c.rhodecode_user.username)
84 password = '@'
84 password = '@'
85
85
86 uri = u'%(protocol)s://%(user)s%(password)s%(host)s%(prefix)s/%(repo_name)s' % {
86 uri = u'%(protocol)s://%(user)s%(password)s%(host)s%(prefix)s/%(repo_name)s' % {
87 'protocol': e.get('wsgi.url_scheme'),
87 'protocol': e.get('wsgi.url_scheme'),
88 'user':username,
88 'user':username,
89 'password':password,
89 'password':password,
90 'host':e.get('HTTP_HOST'),
90 'host':e.get('HTTP_HOST'),
91 'prefix':e.get('SCRIPT_NAME'),
91 'prefix':e.get('SCRIPT_NAME'),
92 'repo_name':c.repo_name, }
92 'repo_name':c.repo_name, }
93 c.clone_repo_url = uri
93 c.clone_repo_url = uri
94 c.repo_tags = OrderedDict()
94 c.repo_tags = OrderedDict()
95 for name, hash in c.repo_info.tags.items()[:10]:
95 for name, hash in c.repo_info.tags.items()[:10]:
96 try:
96 try:
97 c.repo_tags[name] = c.repo_info.get_changeset(hash)
97 c.repo_tags[name] = c.repo_info.get_changeset(hash)
98 except ChangesetError:
98 except ChangesetError:
99 c.repo_tags[name] = EmptyChangeset(hash)
99 c.repo_tags[name] = EmptyChangeset(hash)
100
100
101 c.repo_branches = OrderedDict()
101 c.repo_branches = OrderedDict()
102 for name, hash in c.repo_info.branches.items()[:10]:
102 for name, hash in c.repo_info.branches.items()[:10]:
103 try:
103 try:
104 c.repo_branches[name] = c.repo_info.get_changeset(hash)
104 c.repo_branches[name] = c.repo_info.get_changeset(hash)
105 except ChangesetError:
105 except ChangesetError:
106 c.repo_branches[name] = EmptyChangeset(hash)
106 c.repo_branches[name] = EmptyChangeset(hash)
107
107
108 td = datetime.today() + timedelta(days=1)
108 td = date.today() + timedelta(days=1)
109 y, m, d = td.year, td.month, td.day
109 td_1m = td - timedelta(days=calendar.mdays[td.month])
110 td_1y = td - timedelta(days=365)
110
111
111 ts_min_y = mktime((y - 1, (td - timedelta(days=calendar.mdays[m])).month,
112 ts_min_m = mktime(td_1m.timetuple())
112 d, 0, 0, 0, 0, 0, 0,))
113 ts_min_y = mktime(td_1y.timetuple())
113 ts_min_m = mktime((y, (td - timedelta(days=calendar.mdays[m])).month,
114 ts_max_y = mktime(td.timetuple())
114 d, 0, 0, 0, 0, 0, 0,))
115
115
116 ts_max_y = mktime((y, m, d, 0, 0, 0, 0, 0, 0,))
117 if c.repo_info.dbrepo.enable_statistics:
116 if c.repo_info.dbrepo.enable_statistics:
118 c.no_data_msg = _('No data loaded yet')
117 c.no_data_msg = _('No data loaded yet')
119 run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y)
118 run_task(get_commits_stats, c.repo_info.name, ts_min_y, ts_max_y)
120 else:
119 else:
121 c.no_data_msg = _('Statistics update are disabled for this repository')
120 c.no_data_msg = _('Statistics update are disabled for this repository')
122 c.ts_min = ts_min_m
121 c.ts_min = ts_min_m
123 c.ts_max = ts_max_y
122 c.ts_max = ts_max_y
124
123
125 stats = self.sa.query(Statistics)\
124 stats = self.sa.query(Statistics)\
126 .filter(Statistics.repository == c.repo_info.dbrepo)\
125 .filter(Statistics.repository == c.repo_info.dbrepo)\
127 .scalar()
126 .scalar()
128
127
129
128
130 if stats and stats.languages:
129 if stats and stats.languages:
131 c.no_data = False is c.repo_info.dbrepo.enable_statistics
130 c.no_data = False is c.repo_info.dbrepo.enable_statistics
132 lang_stats = json.loads(stats.languages)
131 lang_stats = json.loads(stats.languages)
133 c.commit_data = stats.commit_activity
132 c.commit_data = stats.commit_activity
134 c.overview_data = stats.commit_activity_combined
133 c.overview_data = stats.commit_activity_combined
135 c.trending_languages = json.dumps(OrderedDict(
134 c.trending_languages = json.dumps(OrderedDict(
136 sorted(lang_stats.items(), reverse=True,
135 sorted(lang_stats.items(), reverse=True,
137 key=lambda k: k[1])[:10]
136 key=lambda k: k[1])[:10]
138 )
137 )
139 )
138 )
140 else:
139 else:
141 c.commit_data = json.dumps({})
140 c.commit_data = json.dumps({})
142 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10] ])
141 c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10] ])
143 c.trending_languages = json.dumps({})
142 c.trending_languages = json.dumps({})
144 c.no_data = True
143 c.no_data = True
145
144
146 return render('summary/summary.html')
145 return render('summary/summary.html')
147
146
General Comments 0
You need to be logged in to leave comments. Login now