Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
998828fe
Commit
998828fe
authored
Feb 15, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Views for rendering activity charts (issue #176)
parent
74263ed3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
181 additions
and
0 deletions
+181
-0
weblate/trans/charts.py
weblate/trans/charts.py
+171
-0
weblate/urls.py
weblate/urls.py
+10
-0
No files found.
weblate/trans/charts.py
0 → 100644
View file @
998828fe
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
'''
Charting library for Weblate.
'''
from
weblate.trans.models
import
Change
,
Project
,
SubProject
,
Translation
from
django.shortcuts
import
render_to_response
,
get_object_or_404
from
django.http
import
HttpResponse
from
cStringIO
import
StringIO
from
django.utils.translation
import
ugettext
as
_
import
cairo
import
pycha.bar
def
render_activity
(
ticks
,
line
):
'''
Helper for rendering activity charts.
'''
# Prepare cairo surface
surface
=
cairo
.
ImageSurface
(
cairo
.
FORMAT_ARGB32
,
800
,
400
)
# Data set
data
=
(
(
'lines'
,
line
),
)
# Chart options
options
=
{
'axis'
:
{
'x'
:
{
'ticks'
:
ticks
,
},
'y'
:
{
'tickCount'
:
4
,
}
},
'background'
:
{
'color'
:
'#eeeeff'
,
'lineColor'
:
'#444444'
},
'colorScheme'
:
{
'name'
:
'gradient'
,
'args'
:
{
'initialColor'
:
'#004276'
,
},
},
'legend'
:
{
'hide'
:
True
,
},
}
# Render chart into surface
chart
=
pycha
.
bar
.
VerticalBarChart
(
surface
,
options
)
chart
.
addDataset
(
data
)
chart
.
render
()
# Render surface to PNG
out
=
StringIO
()
surface
.
write_to_png
(
out
)
data
=
out
.
getvalue
()
# Return response
return
HttpResponse
(
content_type
=
'image/png'
,
content
=
data
)
def
get_translation
(
project
=
None
,
subproject
=
None
,
lang
=
None
):
'''
Returns project, subproject, translation tuple for given parameters.
'''
if
lang
is
not
None
:
# Language defined? We can get all
translation
=
get_object_or_404
(
Translation
,
language__code
=
lang
,
subproject__slug
=
subproject
,
subproject__project__slug
=
project
,
enabled
=
True
)
subproject
=
translation
.
subproject
project
=
subproject
.
project
else
:
translation
=
None
if
subproject
is
not
None
:
# Subproject defined?
subproject
=
get_object_or_404
(
SubProject
,
project__slug
=
project
.
slug
,
slug
=
project
)
project
=
subproject
.
project
elif
project
is
not
None
:
# Only project defined?
project
=
get_object_or_404
(
Project
,
slug
=
project
)
# Return tuple
return
project
,
subproject
,
translation
def
monthly_activity
(
request
,
project
=
None
,
subproject
=
None
,
lang
=
None
):
'''
Show monthly activity chart.
'''
# Process parameters
project
,
subproject
,
translation
=
get_translation
(
project
,
subproject
,
lang
)
# Get actual stats
changes_counts
=
Change
.
objects
.
month_stats
(
project
,
subproject
,
translation
)
# Preprocess data for chart
line
=
[(
i
,
l
[
1
])
for
i
,
l
in
enumerate
(
changes_counts
)]
ticks
=
[
dict
(
v
=
i
,
label
=
l
[
0
].
day
)
for
i
,
l
in
enumerate
(
changes_counts
)]
# Render chart
return
render_activity
(
ticks
,
line
)
def
yearly_activity
(
request
,
project
=
None
,
subproject
=
None
,
lang
=
None
):
'''
Show yearly activity chart.
'''
# Process parameters
project
,
subproject
,
translation
=
get_translation
(
project
,
subproject
,
lang
)
# Get actual stats
changes_counts
=
Change
.
objects
.
year_stats
(
project
,
subproject
,
translation
)
# Preprocess data for chart
line
=
[(
i
,
l
[
1
])
for
i
,
l
in
enumerate
(
changes_counts
)]
ticks
=
[{
'v'
:
i
,
'label'
:
l
[
0
].
isocalendar
()[
1
]}
for
i
,
l
in
enumerate
(
changes_counts
)]
# Render chart
return
render_activity
(
ticks
,
line
)
weblate/urls.py
View file @
998828fe
...
@@ -147,6 +147,16 @@ urlpatterns = patterns('',
...
@@ -147,6 +147,16 @@ urlpatterns = patterns('',
url
(
r'^projects/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/upload/$'
,
'weblate.trans.views.upload_translation'
),
url
(
r'^projects/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/upload/$'
,
'weblate.trans.views.upload_translation'
),
url
(
r'^projects/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/auto/$'
,
'weblate.trans.views.auto_translation'
),
url
(
r'^projects/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/auto/$'
,
'weblate.trans.views.auto_translation'
),
url
(
r'^activity/month/$'
,
'weblate.trans.charts.monthly_activity'
,
name
=
'monthly_activity'
),
url
(
r'^activity/month/(?P<project>[^/]*)/$'
,
'weblate.trans.charts.monthly_activity'
,
name
=
'monthly_activity_project'
),
url
(
r'^activity/month/(?P<project>[^/]*)/(?P<subproject>[^/]*)/$'
,
'weblate.trans.charts.monthly_activity'
,
name
=
'monthly_activity_subproject'
),
url
(
r'^activity/month/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/$'
,
'weblate.trans.charts.monthly_activity'
,
name
=
'monthly_activity_translation'
),
url
(
r'^activity/year/$'
,
'weblate.trans.charts.yearly_activity'
,
name
=
'yearly_activity'
),
url
(
r'^activity/year/(?P<project>[^/]*)/$'
,
'weblate.trans.charts.yearly_activity'
,
name
=
'yearly_activity_project'
),
url
(
r'^activity/year/(?P<project>[^/]*)/(?P<subproject>[^/]*)/$'
,
'weblate.trans.charts.yearly_activity'
,
name
=
'yearly_activity_subproject'
),
url
(
r'^activity/year/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/$'
,
'weblate.trans.charts.yearly_activity'
,
name
=
'yearly_activity_translation'
),
url
(
r'^commit/(?P<project>[^/]*)/$'
,
'weblate.trans.views.commit_project'
),
url
(
r'^commit/(?P<project>[^/]*)/$'
,
'weblate.trans.views.commit_project'
),
url
(
r'^commit/(?P<project>[^/]*)/(?P<subproject>[^/]*)/$'
,
'weblate.trans.views.commit_subproject'
),
url
(
r'^commit/(?P<project>[^/]*)/(?P<subproject>[^/]*)/$'
,
'weblate.trans.views.commit_subproject'
),
url
(
r'^commit/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/$'
,
'weblate.trans.views.commit_translation'
),
url
(
r'^commit/(?P<project>[^/]*)/(?P<subproject>[^/]*)/(?P<lang>[^/]*)/$'
,
'weblate.trans.views.commit_translation'
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment