annotate MoinMoin/stats/languages.py @ 4109:e88baf535b48

fix backup action configuration (broke on windows due to backslashes in e.g. cache_dir), try 2. cfg.backup_exclude is now just a function of filename, telling whether the file should be excluded. By default, no file is excluded.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 19 Sep 2008 21:41:40 +0200
parents 742cabb168b9
children
rev   line source
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - Language Statistics
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 @copyright: 2002-2004 Juergen Hermann <jh@web.de>, # Part of the code is
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 2007 MoinMoin:ThomasWaldmann, # from useragents.py
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7 2007 Nina Kuisma <ninnnu@gmail.com>
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9 """
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11
3175
2a3a6cb34e45 pylint findings: fix some harmless stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3122
diff changeset
12 from MoinMoin import user, i18n
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15 def linkto(pagename, request, params=''):
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 return used_languages(request)
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
18
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 def get_data(request):
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20 _ = request.getText
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21 data = {}
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 users = user.getUserList(request)
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 for userID in users:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 current_user = user.User(request, userID)
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 if current_user.language == u'':
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 # User is using <Browser setting>, attempting to look up if we've managed to store the real language...
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 try:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 data[current_user.real_language] = data.get(current_user.real_language, 0) + 1
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 except AttributeError: # Couldn't find the used language at all...
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 data[u''] = data.get(u'', 0) + 1
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 else:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 data[current_user.language] = data.get(current_user.language, 0) + 1
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 if u'' in data:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35 data[u'browser'] = data.pop(u'') # In case we have users whose languages aren't detectable.
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36 data = [(cnt, current_user_language) for current_user_language, cnt in data.items()]
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37 data.sort()
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 data.reverse()
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 return data
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 def used_languages(request):
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 from MoinMoin.util.dataset import TupleDataset, Column
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 from MoinMoin.widget.browser import DataBrowserWidget
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 _ = request.getText
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 data = get_data(request)
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
50 total = 0.0
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 for cnt, lang in data:
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
52 total += cnt
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55 languages = TupleDataset()
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3064
diff changeset
56 languages.columns = [Column('language', label=_("Language"), align='left'),
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57 Column('value', label='%', align='right')]
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 cnt_printed = 0
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 data = data[:10]
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
62 # Preparing "<Browser setting>"
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3064
diff changeset
63 browserlang = _('<Browser setting>')
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
64 browserlang = browserlang[1:len(browserlang) - 1].capitalize()
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
65 if total:
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
66 for cnt, lang in data:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
67 try:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
68 if lang == u'browser':
3033
6d9bdb12163f stats.languages: small fix (Thanks to Nina Kuisma) (port from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3032
diff changeset
69 languages.addRow((browserlang, "%(percent).2f%% (%(count)d)" % {
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
70 'percent': 100.0 * cnt / total,
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
71 'count': cnt}))
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
72 else:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
73 lang = i18n.wikiLanguages()[lang]['x-language-in-english']
3033
6d9bdb12163f stats.languages: small fix (Thanks to Nina Kuisma) (port from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3032
diff changeset
74 languages.addRow((lang, "%(percent).2f%% (%(count)d)" % {
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
75 'percent': 100.0 * cnt / total,
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
76 'count': cnt}))
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
77 cnt_printed += cnt
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
78 except UnicodeError:
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
79 pass
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
80 if total > cnt_printed:
3122
a1322262398a refactored _() getText calls to match new api
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3064
diff changeset
81 languages.addRow((_('Others'), "%(percent).2f%% (%(count)d)" % {
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
82 'percent': 100.0 * (total - cnt_printed) / total,
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
83 'count': total - cnt_printed}))
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
84
3032
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
85 else: # If we don't have any users, we can safely assume that the only real user is the visitor (who is normally ignored, though) who is using "Browser setting"
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
86 languages.addRow((browserlang, "100% (1)"))
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
87
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
88 table = DataBrowserWidget(request)
c242772754c5 stats macro which shows the preferred language distribution of the wiki users (Thanks to Nina Kuisma) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
89 table.setData(languages)
4093
742cabb168b9 browser._format: refactored input parameter "method". The default value is changed from "GET" to None. Now it does not add a form tag to the table on default. You have to give a value of "GET" or "POST" to add a form tag using the given method.
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3907
diff changeset
90 return table.render(method="GET")
3064
af5872a8f022 useragent/language stats: fixed division by zero, do not use 'sum' (reserved) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3033
diff changeset
91