This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sites release dashboard (bug 623359). Snuck in unit test for dumbo run.
Channel handling for version select box still missing.
- Loading branch information
Showing
18 changed files
with
322 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os, os.path, sys, subprocess, pipes | ||
import bz2 | ||
from shutil import rmtree | ||
from tempfile import mkdtemp | ||
|
||
from dumbo.util import system | ||
|
||
from django.conf import settings | ||
from settings import path | ||
|
||
from website_issues.mapreduce.normalize_to_tsv import normalize_unix | ||
|
||
def _system(args, more_env={}): | ||
print >> sys.stderr, 'Calling:', " ".join(args) | ||
env = os.environ.copy() | ||
env.update(more_env) | ||
process = subprocess.Popen(" ".join(args), shell=True, | ||
env=env, | ||
stdout=sys.stdout, | ||
stderr=sys.stderr) | ||
return os.waitpid(process.pid, 0)[1] / 256 | ||
|
||
|
||
def generate_sites(source, skip_load=False, only_clean=False): | ||
dest_dir = os.path.join(settings.TSV_EXPORT_DIR, "sites") | ||
if not os.path.exists(dest_dir): | ||
os.mkdir(dest_dir) | ||
if only_clean: | ||
print "Removing output at %s" % dest_dir | ||
rmtree(dest_dir) | ||
return | ||
print "Using work/output directory: %s" % dest_dir | ||
|
||
if source is None: | ||
source = os.path.join(settings.TSV_EXPORT_DIR, 'opinions.tsv.bz2') | ||
if not os.path.exists(source): | ||
raise Exception("Missing input file: %s" % source) | ||
if source.endswith(".bz2"): | ||
print "Decompressing %s" % source | ||
# we need to decompress the file to disk for dumbo to work with it | ||
infile = bz2.BZ2File(source) | ||
outname = os.path.join(dest_dir, | ||
os.path.basename(source[:-len(".bz2")])) | ||
with open(outname, "w+") as outfile: | ||
for line in infile: outfile.write(line) | ||
infile.close() | ||
source = outname | ||
|
||
mapreduce_dir = path("apps/website_issues/mapreduce") | ||
|
||
dumbo_job_file = os.path.join(mapreduce_dir, "job.py") | ||
show_counters = os.path.join(mapreduce_dir, "show_counters.py") | ||
|
||
if dest_dir is None: dest_dir = mkdtemp() | ||
dest = os.path.join(dest_dir, "clustered_comments.tsv.coded") | ||
if os.path.exists(dest): os.remove(dest) | ||
|
||
print "Generating site from %s using dumbo (unix backend)." % source | ||
|
||
q = lambda s: pipes.quote(s) | ||
python_env = {"PYTHONPATH": q(":".join(sys.path))} | ||
_system(["dumbo start", q(dumbo_job_file), | ||
"-input", q(source), "-output", q(dest), | ||
"2>&1 | python", q(show_counters)], | ||
more_env=python_env) | ||
|
||
print "Exporting result to %s" % dest_dir | ||
normalize_unix(open(dest, "r"), dest_dir) | ||
|
||
database = settings.DATABASES["website_issues"]["NAME"] | ||
print "Loading results into sites database: %s" % database | ||
if skip_load: return | ||
|
||
print "Loading results into sites database." | ||
sql_load = os.path.join(mapreduce_dir, "load.sql") | ||
sql_filter = """sed "s/INFILE '/INFILE '%s\\//g" """ % \ | ||
q(dest_dir).replace('/', '\\/') | ||
_system(["cat", q(sql_load), | ||
"|" , sql_filter, | ||
"| python ./manage.py dbshell --database=%s" % database], | ||
more_env=python_env) | ||
normalize_unix(open(dest, "r"), dest_dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
import dumbo | ||
from dumbo.lib import identitymapper, identityreducer | ||
|
||
# Prepare the job environment. This is like manage.py, but for dumbo jobs. | ||
# The PYTHONPATH for the app needs to be set in the environment. | ||
try: | ||
try: import settings_local as settings | ||
except ImportError: import settings | ||
except ImportError: | ||
import sys | ||
sys.stderr.write("Dumbo job cannot find settings. Is the path OK?\n") | ||
sys.stderr.write("PYTHONPATH: %r" % sys.path) | ||
sys.exit(1) | ||
from django.core.management import setup_environ | ||
setup_environ(settings) | ||
|
||
from website_issues.mapreduce import tasks | ||
|
||
|
||
"""Dumbo job that can be executed on a hadoop cluster.""" | ||
|
||
|
||
def runner(job): | ||
job.additer(tasks.SiteSummaryMapper, tasks.CommentClusteringReducer) | ||
job.additer(identitymapper, tasks.ClusterIdReducer) | ||
job.additer(identitymapper, tasks.SummarySizeReducer) | ||
job.additer(identitymapper, tasks.SummaryIdReducer) | ||
job.additer(identitymapper, tasks.DenormalizingReducer) | ||
job.additer(identitymapper, identityreducer) | ||
job.additer(tasks.SiteSummaryMapper, tasks.CommentClusteringReducer) | ||
job.additer(identitymapper, tasks.ClusterIdReducer) | ||
job.additer(identitymapper, tasks.SummarySizeReducer) | ||
job.additer(identitymapper, tasks.SummaryIdReducer) | ||
job.additer(identitymapper, tasks.DenormalizingReducer) | ||
job.additer(identitymapper, identityreducer) | ||
|
||
if __name__ == "__main__": | ||
dumbo.main(runner) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
apps/website_issues/templates/website_issues/includes/macros.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% macro button(form, name, value='', label='', title='', classes='') %} | ||
{% set sel = (form.cleaned_data[name] == value) %} | ||
<a class="{{ 'selected' if sel else ''}} {{ classes }}" | ||
href="{{ sites_url(form,**{name: value}) }}">{{ label }}</a> | ||
{% endmacro %} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/website_issues/templates/website_issues/includes/sites_content.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{% from 'website_issues/includes/macros.html' import button %} | ||
|
||
<div class="col left"> | ||
<form method="get" action="{{ url('website_issues') }}" id="filters" class="filters segments block"> | ||
|
||
<div class="choice"> | ||
<h3>{{ _('Product') }}</h3> | ||
<div> | ||
{{ products_block(products, product) }} | ||
{{ versions_block(versions, version) }} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
{% if request.channel != "release" %} | ||
<div class="choice" id="filter_type"> | ||
<h3>{{ _('Type of Feedback') }}</h3> | ||
<div> | ||
<ul> | ||
<li>{{ button(form, 'sentiment', '', label=_('All', 'sites_search_all_feedback'), title=_('All feedback')) }}</li> | ||
<li>{{ button(form, 'sentiment', 'happy', label=_('Praise'), title=_('Praise only')) }}</li> | ||
<li>{{ button(form, 'sentiment', 'sad', label=_('Issues'), title=_('Issues only')) }}</li> | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %} | ||
|
||
<div class="choice" id="filter_platform"> | ||
<h3>{{ _('Platforms') }}</h3> | ||
<div> | ||
<ul> | ||
<li>{{ button(form, 'os', '', label=_('All', 'sites_search_all_platforms'), title=_('All platforms')) }}</li> | ||
{% for os in oses %} | ||
<li>{{ button(form, 'os', os.short, label=os.short, title=os.pretty) }}</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
{# TODO add minimum feedback count choice | ||
<div class="choice"> | ||
<h3>Min Related</h3> | ||
|
||
<div> | ||
<ul> | ||
<!-- | ||
--><li><a class="selected" href="search.html" title="No minimum">Any</a></li><!-- | ||
--><li><a class="" href="search.html" title="25+ messages">25</a></li><!-- | ||
--><li><a class="" href="search.html" title="50+ messages">50</a></li><!-- | ||
--><li><a class="" href="search.html" title="100+ messages">100</a></li><!-- | ||
--><li><a class="" href="search.html" title="250+ messages">250</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
#} | ||
|
||
</form> | ||
</div><!-- | ||
--><div class="col middle wide"> | ||
<div id="themes" class="block"> | ||
{% if not site %} | ||
{% include "website_issues/includes/sites_list.html" %} | ||
{% else %} | ||
{% include "website_issues/includes/single_site.html" %} | ||
{% endif %} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.