r81002 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81001‎ | r81002 | r81003 >
Date:23:00, 25 January 2011
Author:diederik
Status:deferred
Tags:
Comment:
Final alpha commit of wikilytics.
Modified paths:
  • /trunk/tools/editor_trends/wikilytics/api/forms.py (modified) (history)
  • /trunk/tools/editor_trends/wikilytics/api/models.py (modified) (history)
  • /trunk/tools/editor_trends/wikilytics/api/views.py (modified) (history)
  • /trunk/tools/editor_trends/wikilytics/urls.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/wikilytics/api/views.py
@@ -4,12 +4,13 @@
55
66 from django.shortcuts import render_to_response
77 from django.http import HttpResponseRedirect, HttpResponse
 8+from django.core.context_processors import csrf
89 from django.core.urlresolvers import reverse
910 from django.conf import settings
1011 from django.core import serializers
1112
1213
13 -from wikilytics.api.forms import SearchForm
 14+from wikilytics.api.forms import SearchForm, AnalysisForm
1415 from wikilytics.api.models import Editor, Dataset, Job, Dump
1516 import wikilytics.api.helpers as helpers
1617
@@ -31,38 +32,59 @@
3233
3334
3435 def dataset_dispatcher(request, project, language):
35 - dbname = '%s%s' % (language, project)
36 - editors = Editor.objects.count()
37 - if editors == 0:
 36+ #dbname = '%s%s' % (language, project)
 37+ print request
3838 #Dataset has not yet been made, put job in queue to create the dataset
39 - hash = helpers.create_hash(project, language)
40 - job, created = Job.objects.get_or_create(hash=hash, defaults={'project':project, 'language_code': language, 'hash':hash})
41 - print job.hash
42 - if created:
43 - job.save()
44 - jobs = Job.objects.filter(jobtype='dataset', finished=False, in_progress=True)
45 - return render_to_response('queue.html', {'jobs': jobs})
46 - else:
47 - ds = Dataset.objects.filter(project=project, language_code=language)
48 - print ds
49 - return render_to_response('datasets_available.html', {'datasets': ds})
 39+ hash = helpers.create_hash(project, language)
 40+ job, created = Job.objects.get_or_create(hash=hash, defaults={'project':project, 'language_code': language, 'hash':hash})
 41+ print job.hash
 42+ if created:
 43+ job.save()
 44+ jobs = Job.objects.filter(jobtype='dataset', finished=False, in_progress=False)
 45+ ds = Dataset.objects.filter(project=project, language_code=language)
 46+ print ds
 47+ return render_to_response('datasets.html', {'datasets': ds, 'jobs': jobs})
5048
5149
5250 def chart_dispatcher(request, project, language):
5351 #project = '%s%s' % (project, language)
54 - analyses = Job.objects.filter(jobtype='chart')
 52+ analyses = Job.objects.exclude(jobtype='dataset').filter(finished=True, project=project, language_code=language)
5553 print analyses
56 - return render_to_response('analyses_available.html', {'analyses': analyses})
 54+ return render_to_response('analyses.html', {'analyses': analyses})
5755
5856
5957 def chart_generator(request, project, language, chart):
6058 xhr = request.GET.has_key('json')
61 - print xhr
62 - ds = Dataset.objects.using('enwiki').get(project=project, language_code=language, name=chart)
63 - if xhr:
 59+ c = {}
 60+ print project, language, chart
 61+ try:
 62+ ds = Dataset.objects.using('enwiki').get(project=project, language_code=language, name=chart)
 63+ except:
 64+ hash = helpers.create_hash(project, language)
 65+ job = Job()
 66+ job.jobtype = chart
 67+ job.project = project
 68+ job.language_code = language
 69+ job.hash = hash
 70+ job.save()
 71+ c['queue'] = True
 72+
 73+ if request.POST:
 74+ print request.POST
 75+ chart = request.POST.get('analysis')
 76+ return HttpResponseRedirect(reverse('chart_generator', args=[project, language, chart]))
 77+ elif xhr:
6478 dthandler = lambda obj:'new Date("%s")' % datetime.date.ctime(obj) if isinstance(obj, datetime.datetime) else obj
6579 data = helpers.transform_to_stacked_bar_json(ds)
6680 return HttpResponse(json.dumps(data, default=dthandler), mimetype='application/json')
6781 else:
68 - url = ds.get_absolute_url()
69 - return render_to_response('chart.html', {'url': url})
 82+
 83+ c.update(csrf(request))
 84+ analysis = AnalysisForm()
 85+ url = reverse('chart_generator', args=[project, language, chart])
 86+ #url = ds.get_absolute_url()
 87+
 88+ c['url'] = url
 89+ c['analysis'] = analysis
 90+ c['chart'] = chart
 91+ return render_to_response('chart.html', c)
Index: trunk/tools/editor_trends/wikilytics/api/models.py
@@ -63,6 +63,7 @@
6464 created = models.DateField(auto_now_add=True)
6565 finished = models.BooleanField(default=False)
6666 in_progress = models.BooleanField(default=False)
 67+ error = models.BooleanField(default=False)
6768 jobtype = models.CharField(max_length=15, default='dataset')
6869
6970 def __unicode__(self):
@@ -71,13 +72,13 @@
7273
7374 @permalink
7475 def get_absolute_url(self):
75 - if self.jobtype == 'chart':
76 - print reverse('chart_generator', args=[self.project, self.language_code, self.hash])
 76+ if self.jobtype != 'dataset':
 77+ print reverse('chart_generator', args=[self.project, self.language_code, self.jobtype])
7778 return ('chart_generator', (),
7879 {'project': self.project,
7980 'language': self.language_code,
80 - 'chart': self.hash})
81 - elif self.jobtype == 'dataset':
 81+ 'chart': self.jobtype})
 82+ else:
8283 return ('dataset_dispatcher', (),
8384 {'project': self.project,
8485 'language': self.language_code,
Index: trunk/tools/editor_trends/wikilytics/api/forms.py
@@ -3,8 +3,8 @@
44
55 from wikilytics.api.widgets import MonthYearWidget
66 from editor_trends.classes import wikiprojects
 7+from editor_trends.analyses.analyzer import available_analyses
78
8 -
99 wiki = wikiprojects.Wiki('settings')
1010
1111
@@ -21,3 +21,6 @@
2222 #print 'Project: %s' % language
2323 #date = forms.DateField(widget=MonthYearWidget(years=years))
2424
 25+class AnalysisForm(forms.Form):
 26+ analysis = forms.CharField(widget=forms.Select(choices=available_analyses('django')))
 27+
Index: trunk/tools/editor_trends/wikilytics/urls.py
@@ -16,7 +16,7 @@
1717 #url(r'^search/(?P<project>[\w]*)/available_dumps/json/$', 'api.views.available_dumps', name='available_dumps'),
1818 url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/datasets/$', 'api.views.dataset_dispatcher', name='dataset_dispatcher'),
1919 url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/analyses/$', 'api.views.chart_dispatcher', name='chart_dispatcher'),
20 - url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/chart/(?P<chart>[\w]*)/$', 'api.views.chart_generator', name='chart_generator'),
 20+ url(r'^(?P<project>[\w]*)/(?P<language>\w{2})/analyses/(?P<chart>[\w]*)/$', 'api.views.chart_generator', name='chart_generator'),
2121 url(r'^static/js/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_JS}),
2222 url(r'^static/css/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_CSS}),
2323

Status & tagging log