r85458 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85457‎ | r85458 | r85459 >
Date:19:01, 5 April 2011
Author:diederik
Status:deferred
Tags:
Comment:
Updated the plugins code for Wikilytics 0.2
Modified paths:
  • /trunk/tools/editor_trends/analyses/plugins/edit_patterns.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/histogram_edits.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/new_editor_count.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/taxonomy_burnout.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/taxonomy_list_makers.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/total_cumulative_edits.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/total_number_of_articles.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/total_number_of_new_wikipedians.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/analyses/plugins/total_cumulative_edits.py
@@ -17,9 +17,22 @@
1818 __date__ = '2011-01-25'
1919 __version__ = '0.1'
2020
 21+from datetime import datetime
2122
2223 def total_cumulative_edits(var, editor, **kwargs):
23 - cnt = editor['edit_count']
24 - last = editor['final_edit']
25 - var.add(last, cnt, {'year': last.year})
 24+ '''
 25+ If you have questions about how to use this plugin, please visit:
 26+ http://meta.wikimedia.org/wiki/Wikilytics_Plugins
 27+ '''
 28+ namespace = kwargs.get('namespace', ['0'])
 29+ edits = editor['edit_count']
 30+ years = edits.keys()
 31+ for year in years:
 32+ months = edits[year].keys()
 33+ for month in months:
 34+ date = datetime(int(year), int(month), 1)
 35+ for ns in namespace:
 36+ count = edits[year][month].get(ns, 0)
 37+ if count > 0:
 38+ var.add(date, count, {'namespace': ns})
2639 return var
Index: trunk/tools/editor_trends/analyses/plugins/taxonomy_list_makers.py
@@ -20,23 +20,24 @@
2121 def taxonomy_list_makers(var, editor, **kwargs):
2222 """
2323 == List makers ==
24 - Any editor who makes more than 10 mainspace edits a month to articles with titles that begin with "List of..."
25 - """
 24+ Any editor who makes more than 10 mainspace edits a month to articles with
 25+ titles that begin with "List of..."
 26+ """
2627 articles_by_year = editor['articles_by_year']
2728 count = 0
28 -
 29+
2930 for year in xrange(new_wikipedian.year, var.max_year):
3031 for month in xrange(1, 13):
3132 for article in articles_by_year[year][month]:
3233 """ locate article titles containing "List of" """
3334 if article.find('List of') > -1:
3435 count = count + 1
35 -
36 -
 36+
 37+
3738 """ Add all editors with an edit count of more than 10 """
3839
3940 if count > 10:
4041 var.add(editor['username'], 1)
41 -
42 -
 42+
 43+
4344 return var
Index: trunk/tools/editor_trends/analyses/plugins/taxonomy_burnout.py
@@ -12,17 +12,20 @@
1313 http://www.fsf.org/licenses/gpl.html
1414 '''
1515
16 -__author__ = '''\n'''.join(['Diederik van Liere (dvanliere@wikimedia.org', 'Ryan Faulkner (rfaulkner@wikimedia.org)'])
 16+__author__ = '''\n'''.join(['Diederik van Liere (dvanliere@wikimedia.org',
 17+ 'Ryan Faulkner (rfaulkner@wikimedia.org)'])
1718 __email__ = 'dvanliere at wikimedia dot org'
1819 __date__ = '2011-01-25'
1920 __version__ = '0.1'
2021
2122
22 -
2323 def taxonomy_burnout(var, editor, **kwargs):
 24+ '''
 25+ If you have questions about how to use this plugin, please visit:
 26+ http://meta.wikimedia.org/wiki/Wikilytics_Plugins
 27+ '''
2428 new_wikipedian = editor['new_wikipedian']
2529 edits = editor['edit_count']
26 - final_edit = editor['final_edit']
2730 cutoff = kwargs.get('cutoff', 149)
2831 username = editor['username']
2932
Index: trunk/tools/editor_trends/analyses/plugins/total_number_of_new_wikipedians.py
@@ -20,8 +20,11 @@
2121
2222
2323 def total_number_of_new_wikipedians(var, editor, **kwargs):
24 -
 24+ '''
 25+ If you have questions about how to use this plugin, please visit:
 26+ http://meta.wikimedia.org/wiki/Wikilytics_Plugins
 27+ '''
2528 new_wikipedian = editor['new_wikipedian']
2629 if new_wikipedian != False:
27 - var.add(new_wikipedian, 1, {'year':new_wikipedian.year})
 30+ var.add(new_wikipedian, 1)
2831 return var
Index: trunk/tools/editor_trends/analyses/plugins/edit_patterns.py
@@ -17,23 +17,31 @@
1818 __date__ = '2011-01-28'
1919 __version__ = '0.1'
2020
21 -import datetime
 21+from datetime import datetime
2222
2323 def edit_patterns(var, editor, **kwargs):
24 - monthly = editor['monthly_edits']
 24+ '''
 25+ If you have questions about how to use this plugin, please visit:
 26+ http://meta.wikimedia.org/wiki/Wikilytics_Plugins
 27+ '''
 28+ edits = editor['edit_count']
2529 new_wikipedian = editor['new_wikipedian']
2630 final_edit = editor['final_edit']
27 - dt = final_edit - new_wikipedian
28 - if dt.days < 366:
29 - return var
3031
3132 if new_wikipedian != False:
32 - for year in xrange(new_wikipedian.year, new_wikipedian.year + 2):
 33+ dt = final_edit - new_wikipedian
 34+ if dt.days < 366:
 35+ return var
 36+
 37+ years = edits.keys()
 38+ for year in years:
 39+ #for year in xrange(new_wikipedian.year, new_wikipedian.year + 2):
3340 obs = [False for x in xrange(13)]
34 - for month in xrange(new_wikipedian.month, 13):
35 - n = monthly[str(year)][str(month)]
36 - date = datetime.datetime(year, month, 1)
37 - if n >= var.cutoff:
 41+ months = edit[year].keys()
 42+ for month in xrange(13):
 43+ count = edits[year].get(month, {}).get('0', 0)
 44+ date = datetime(int(year), int(month), 1)
 45+ if count >= var.cutoff:
3846 obs[month] = True
3947 var.add(date, obs)
4048 return var
Index: trunk/tools/editor_trends/analyses/plugins/histogram_edits.py
@@ -17,11 +17,22 @@
1818 __date__ = '2011-01-25'
1919 __version__ = '0.1'
2020
 21+from datetime import datetime
2122
2223 def histogram_edits(var, editor, **kwargs):
23 -# headers = ['year', 'num_edits', 'frequency']
24 - cnt = editor['edit_count']
25 - new_wikipedian = editor['new_wikipedian']
26 - if new_wikipedian != False:
27 - var.add(new_wikipedian, cnt)
 24+ '''
 25+ If you have questions about how to use this plugin, please visit:
 26+ http://meta.wikimedia.org/wiki/Wikilytics_Plugins
 27+ '''
 28+ namespace = kwargs.get('namespace', ['0'])
 29+ edits = editor['edit_count']
 30+ years = edits.keys()
 31+ for year in years:
 32+ months = edits[year].keys()
 33+ for month in months:
 34+ date = datetime(int(year), int(month), 1)
 35+ for ns in namespace:
 36+ count = edits[year][month].get(ns, 0)
 37+ if count > 0:
 38+ var.add(date, 1, {'namespace': ns, 'number_of_edits': count})
2839 return var
Index: trunk/tools/editor_trends/analyses/plugins/total_number_of_articles.py
@@ -17,8 +17,12 @@
1818 __date__ = '2011-01-25'
1919 __version__ = '0.1'
2020
 21+import sys
2122
2223 def total_number_of_articles(var, editor, **kwargs):
 24+ print 'This plugin is not yet functional, needs to be rewritten.'
 25+ sys.exit(-1)
 26+
2327 for year in editor['edits']:
2428 edits = editor['edits'][year]
2529 for edit in edits:
Index: trunk/tools/editor_trends/analyses/plugins/new_editor_count.py
@@ -25,7 +25,6 @@
2626 Purpose: This data can be used to compare with Erik Zachte's
2727 stats.download.org to make sure that we are using the same numbers.
2828 '''
29 -# headers = ['year', 'month', 'count']
3029 if editor['new_wikipedian'] != False:
3130 new_wikipedian = editor['new_wikipedian']
3231 var.add(new_wikipedian, 1)