Index: trunk/tools/editor_trends/wikilytics/api/helpers.py |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +def init_database(dbname):
|
| 3 | + if dbname not in settings.DATABASES:
|
| 4 | + settings.DATABASES[dbname] = {
|
| 5 | + 'ENGINE': 'django_mongodb_engine',
|
| 6 | + 'NAME': '%s' % dbname,
|
| 7 | + 'USER': '',
|
| 8 | + 'PASSWORD': '',
|
| 9 | + 'HOST': 'localhost',
|
| 10 | + 'PORT': '27017',
|
| 11 | + }
|
| 12 | +
|
| 13 | +
|
| 14 | +def create_hash(project, language):
|
| 15 | + today = datetime.datetime.today()
|
| 16 | + datum = datetime.date(today.year, today.month, 1)
|
| 17 | + secs = time.mktime(datum.timetuple())
|
| 18 | + return hash('%s%s' % (project, language)) + hash(secs)
|
Index: trunk/tools/editor_trends/wikilytics/api/tasks.py |
— | — | @@ -0,0 +1,57 @@ |
| 2 | +from multiprocessing import Process
|
| 3 | +
|
| 4 | +from celery.decorators import task
|
| 5 | +from celery.registry import tasks
|
| 6 | +
|
| 7 | +from editor_trends.utils import wikiprojects
|
| 8 | +from editor_trends import manage as manager
|
| 9 | +
|
| 10 | +from wikilytics.api.models import Job
|
| 11 | +
|
| 12 | +@task
|
| 13 | +def launcher():
|
| 14 | + jobs = Job.objects.filter(finished=False)
|
| 15 | + n = len(jobs)
|
| 16 | + if n > 0:
|
| 17 | +
|
| 18 | + job = jobs[0]
|
| 19 | + job.in_progress = True
|
| 20 | + job.save()
|
| 21 | + print 'Launching %s task' % job.type
|
| 22 | + if job.type == 'dataset':
|
| 23 | + res = launch_editor_trends_toolkit(job.project, job.language)
|
| 24 | + elif job.type == 'chart':
|
| 25 | + res = launch_chart(job.project, job.language)
|
| 26 | + else:
|
| 27 | + print 'Unknown job type, no handler has been configured.'
|
| 28 | +
|
| 29 | + if res == True:
|
| 30 | + job.finished = True
|
| 31 | + job.in_progress = False
|
| 32 | + job.save()
|
| 33 | +
|
| 34 | +
|
| 35 | +def launch_editor_trends_toolkit(project, language):
|
| 36 | + '''
|
| 37 | + This function should only be called from within Django Wikilytics.
|
| 38 | + '''
|
| 39 | + res = False
|
| 40 | + parser, settings, wiki = manager.init_args_parser()
|
| 41 | + args = parser.parse_args(['dummy'])
|
| 42 | + args.language = language
|
| 43 | + args.project = project
|
| 44 | + print args
|
| 45 | + wiki = wikiprojects.Wiki(settings, args)
|
| 46 | + p = Process(target=manager.all_launcher, args=(wiki, settings, None))
|
| 47 | + p.start()
|
| 48 | + #res = manager.all_launcher(wiki, settings, None)
|
| 49 | + return res
|
| 50 | +
|
| 51 | +def launch_chart(project, language):
|
| 52 | + res = False
|
| 53 | +
|
| 54 | +
|
| 55 | + return False
|
| 56 | +
|
| 57 | +
|
| 58 | +tasks.register(launcher)
|
Index: trunk/tools/editor_trends/wikilytics/api/forms.py |
— | — | @@ -0,0 +1,23 @@ |
| 2 | +import datetime
|
| 3 | +from django import forms
|
| 4 | +
|
| 5 | +from wikilytics.api.widgets import MonthYearWidget
|
| 6 | +from editor_trends.utils import wikiprojects
|
| 7 | +
|
| 8 | +
|
| 9 | +wiki = wikiprojects.Wiki('settings')
|
| 10 | +
|
| 11 | +
|
| 12 | +years = [year for year in xrange(2001, datetime.date.today().year + 1)]
|
| 13 | +#print wiki.supported_languages()
|
| 14 | +#print wiki.supported_projects()
|
| 15 | +
|
| 16 | +class SearchForm(forms.Form):
|
| 17 | + project = forms.CharField(initial='wiki',
|
| 18 | + widget=forms.Select(choices=wiki.supported_projects()))
|
| 19 | +
|
| 20 | + language = forms.CharField(initial='en',
|
| 21 | + widget=forms.Select(choices=wiki.supported_languages(output='django')))
|
| 22 | + print 'Project: %s' % language
|
| 23 | + date = forms.DateField(widget=MonthYearWidget(years=years))
|
| 24 | +
|
Index: trunk/tools/editor_trends/wikilytics/api/widgets.py |
— | — | @@ -0,0 +1,84 @@ |
| 2 | +import datetime
|
| 3 | +import re
|
| 4 | +
|
| 5 | +from django.forms.widgets import Widget, Select
|
| 6 | +from django.utils.dates import MONTHS
|
| 7 | +from django.utils.safestring import mark_safe
|
| 8 | +
|
| 9 | +__all__ = ('MonthYearWidget',)
|
| 10 | +
|
| 11 | +RE_DATE = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$')
|
| 12 | +
|
| 13 | +class MonthYearWidget(Widget):
|
| 14 | + """
|
| 15 | + A Widget that splits date input into two <select> boxes for month and year,
|
| 16 | + with 'day' defaulting to the first of the month.
|
| 17 | +
|
| 18 | + Based on SelectDateWidget, in
|
| 19 | +
|
| 20 | + django/trunk/django/forms/extras/widgets.py
|
| 21 | +
|
| 22 | +
|
| 23 | + """
|
| 24 | + none_value = (0, '---')
|
| 25 | + month_field = '%s_month'
|
| 26 | + year_field = '%s_year'
|
| 27 | +
|
| 28 | + def __init__(self, attrs=None, years=None, required=True):
|
| 29 | + # years is an optional list/tuple of years to use in the "year" select box.
|
| 30 | + self.attrs = attrs or {}
|
| 31 | + self.required = required
|
| 32 | + if years:
|
| 33 | + self.years = years
|
| 34 | + else:
|
| 35 | + this_year = datetime.date.today().year
|
| 36 | + self.years = range(this_year, this_year + 10)
|
| 37 | +
|
| 38 | + def render(self, name, value, attrs=None):
|
| 39 | + try:
|
| 40 | + year_val, month_val = value.year, value.month
|
| 41 | + except AttributeError:
|
| 42 | + year_val = month_val = None
|
| 43 | + if isinstance(value, basestring):
|
| 44 | + match = RE_DATE.match(value)
|
| 45 | + if match:
|
| 46 | + year_val, month_val, day_val = [int(v) for v in match.groups()]
|
| 47 | +
|
| 48 | + output = []
|
| 49 | +
|
| 50 | + if 'id' in self.attrs:
|
| 51 | + id_ = self.attrs['id']
|
| 52 | + else:
|
| 53 | + id_ = 'id_%s' % name
|
| 54 | +
|
| 55 | + month_choices = MONTHS.items()
|
| 56 | + if not (self.required and value):
|
| 57 | + month_choices.append(self.none_value)
|
| 58 | + month_choices.sort()
|
| 59 | + local_attrs = self.build_attrs(id=self.month_field % id_)
|
| 60 | + s = Select(choices=month_choices)
|
| 61 | + select_html = s.render(self.month_field % name, month_val, local_attrs)
|
| 62 | + output.append(select_html)
|
| 63 | +
|
| 64 | + year_choices = [(i, i) for i in self.years]
|
| 65 | + if not (self.required and value):
|
| 66 | + year_choices.insert(0, self.none_value)
|
| 67 | + local_attrs['id'] = self.year_field % id_
|
| 68 | + s = Select(choices=year_choices)
|
| 69 | + select_html = s.render(self.year_field % name, year_val, local_attrs)
|
| 70 | + output.append(select_html)
|
| 71 | +
|
| 72 | + return mark_safe(u'\n'.join(output))
|
| 73 | +
|
| 74 | + def id_for_label(self, id_):
|
| 75 | + return '%s_month' % id_
|
| 76 | + id_for_label = classmethod(id_for_label)
|
| 77 | +
|
| 78 | + def value_from_datadict(self, data, files, name):
|
| 79 | + y = data.get(self.year_field % name)
|
| 80 | + m = data.get(self.month_field % name)
|
| 81 | + if y == m == "0":
|
| 82 | + return None
|
| 83 | + if y and m:
|
| 84 | + return '%s-%s-%s' % (y, m, 1)
|
| 85 | + return data.get(name, None)
|
Index: trunk/tools/editor_trends/wikilytics/templates/queue.html |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +
|
| 3 | +{% block content %}
|
| 4 | +<h1>Job Status</h1>
|
| 5 | + {% for job in jobs %}
|
| 6 | + <ul>
|
| 7 | + <li>Project: {{ job.project }}</li>
|
| 8 | + <li>Language: {{ job.language }}</li>
|
| 9 | + <li>Created: {{ job.created }}</li>
|
| 10 | + <li>Finished: {{ job.finished }}</li>
|
| 11 | + <li>In progress: {{ job.in_progress }}</li>
|
| 12 | + </ul>
|
| 13 | + {% for subtasks in job %}
|
| 14 | +
|
| 15 | + {% endfor %}
|
| 16 | + {% endfor %}
|
| 17 | +<h2>Please return in a couple of hours, the dataset will be finished by then.<h2>
|
| 18 | +{% endblock %} |
\ No newline at end of file |
Index: trunk/tools/editor_trends/wikilytics/templates/search.html |
— | — | @@ -0,0 +1,16 @@ |
| 2 | +{% extends "base.html" %}
|
| 3 | +
|
| 4 | +{% block content %}
|
| 5 | + <form action="" method="get">
|
| 6 | + {% for field in form %}
|
| 7 | + <div class="fieldWrapper">
|
| 8 | + {{ field.errors }}
|
| 9 | + {{ field.label_tag }}: {{ field }}
|
| 10 | + </div>
|
| 11 | + {% endfor %}
|
| 12 | +
|
| 13 | +
|
| 14 | + <input type="submit" value="Search" />
|
| 15 | + </form>
|
| 16 | +{% endblock %}
|
| 17 | +
|
Index: trunk/tools/editor_trends/wikilytics/templates/datasets_available.html |
— | — | @@ -0,0 +1,17 @@ |
| 2 | +
|
| 3 | +{% block content %}
|
| 4 | + {% if datasets %}
|
| 5 | + <ul>
|
| 6 | + {% for dataset in datasets %}
|
| 7 | + <li>{{ dataset }}</li>
|
| 8 | + {{ dataset.count }}
|
| 9 | + {% for key,value in dataset.items %}
|
| 10 | + {{ key }} -- {{ value }}
|
| 11 | + {% endfor %}
|
| 12 | +
|
| 13 | + {% endfor %}
|
| 14 | + <ul>
|
| 15 | + {% else %}
|
| 16 | + <h1>There are no datasets available yet.</h1>
|
| 17 | + {% endif %}
|
| 18 | +{% endblock %} |
\ No newline at end of file |
Index: trunk/tools/editor_trends/wikilytics/templates/base.html |
— | — | @@ -0,0 +1,10 @@ |
| 2 | +<html> |
| 3 | + |
| 4 | + <body> |
| 5 | + |
| 6 | + {% block content %} |
| 7 | + {% endblock %} |
| 8 | + |
| 9 | + </body> |
| 10 | + |
| 11 | +</htm> |
\ No newline at end of file |
Property changes on: trunk/tools/editor_trends/wikilytics/templates/base.html |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 12 | + native |