예제 #1
0
def trends(request, date_start, date_end):
    """AJAX action returning a summary of frequent terms."""
    opinions = Opinion.objects.between(date_start, date_end).filter(
        product=DASH_PROD.id)
    frequent_terms = Term.objects.frequent(
        opinions=opinions)[:settings.TRENDS_COUNT]
    # TODO use real product here
    data = {'terms': stats.frequent_terms(qs=frequent_terms)}
    return jingo.render(request, 'dashboard/trends.html', data)
예제 #2
0
파일: views.py 프로젝트: reedloden/reporter
def trends(request, date_start, date_end):
    """AJAX action returning a summary of frequent terms."""
    term_params = {
        'date_start': date_start,
        'date_end': date_end,
        'product': request.default_app.id,
        'version': simplify_version(LATEST_BETAS[request.default_app]),
    }
    frequent_terms = Term.objects.frequent(
        **term_params)[:settings.TRENDS_COUNT]
    data = {'terms': stats.frequent_terms(qs=frequent_terms)}
    return jingo.render(request, 'dashboard/trends.html', data)
예제 #3
0
 def test_frequent_stats(self):
     """Test frequent terms weights."""
     ts = Term.objects.frequent()
     freq = frequent_terms(qs=ts)
     eq_(len(freq), 2)
예제 #4
0
 def test_frequent_stats(self):
     """Test frequent terms weights."""
     ts = Term.objects.frequent()
     freq = frequent_terms(qs=ts)
     eq_(len(freq), 2)
예제 #5
0
파일: views.py 프로젝트: chowse/reporter
def dashboard(request):
    """Front page view."""

    # Defaults
    app = request.default_app
    version = simplify_version(LATEST_BETAS[app])

    # Frequent terms
    term_params = {
        'product': app.id,
        'version': version,
    }

    frequent_terms = Term.objects.frequent(
        **term_params)[:settings.TRENDS_COUNT]

    # opinions queryset for demographics
    latest_opinions = Opinion.objects.browse(**term_params)
    latest_beta = Opinion.objects.filter(version=version, product=app.id)

    # Sites clusters
    sites = SiteSummary.objects.filter(version__exact=version).filter(
        positive__exact=None).filter(os__exact=None)[:settings.TRENDS_COUNT]

    # search form to generate various form elements.
    search_form = ReporterSearchForm()

    try:
        c = Client()
        search_opts = dict(product=app.short, version=version)
        c.query('', meta=('type', 'locale', 'os', 'day_sentiment'), **search_opts)
        metas = c.meta
        daily = c.meta.get('day_sentiment', {})
        chart_data = dict(series=[
            dict(name=_('Praise'), data=daily['praise']),
            dict(name=_('Issues'), data=daily['issue']),
            dict(name=_('Suggestion'), data=daily['suggestion']),
            ],
            )
        total = c.total_found
    except SearchError:
        metas = {}
        total = latest_beta.count()
        chart_data = None

    data = {'opinions': latest_opinions.all()[:settings.MESSAGES_COUNT],
            'opinion_count': total,
            'opinion_types': OPINION_TYPES,
            'OPINION_PRAISE': OPINION_PRAISE,
            'OPINION_ISSUE': OPINION_ISSUE,
            'OPINION_SUGGESTION': OPINION_SUGGESTION,
            'product': app.short,
            'products': PROD_CHOICES,
            'sentiments': get_sentiment(metas.get('type', [])),
            'terms': stats.frequent_terms(qs=frequent_terms),
            'demo': dict(locale=metas.get('locale'), os=metas.get('os')),
            'sites': sites,
            'version': version,
            'versions': VERSION_CHOICES[app],
            'search_form': search_form,
            'chart_data_json': json.dumps(chart_data),
           }

    if not request.mobile_site:
        template = 'dashboard/dashboard.html'
    else:
        template = 'dashboard/mobile/dashboard.html'
    return jingo.render(request, template, data)
예제 #6
0
파일: views.py 프로젝트: jlongster/reporter
def dashboard(request):
    """Beta dashboard."""
    # Defaults
    prod = request.default_prod
    version = Version(LATEST_BETAS[prod]).simplified

    search_form = ReporterSearchForm()
    # Frequent terms
    term_params = {
        'product': prod.id,
        'version': version,
    }

    frequent_terms = Term.objects.frequent(
        **term_params)[:settings.TRENDS_COUNT]

    # opinions queryset for demographics
    latest_opinions = Opinion.objects.browse(**term_params)
    latest_beta = Opinion.objects.filter(version=version, product=prod.id)

    # Sites clusters
    sites = SiteSummary.objects.filter(version__exact=version).filter(
        positive__exact=None).filter(
        platform__exact=None)[:settings.TRENDS_COUNT]

    try:
        c = Client()
        search_opts = dict(product=prod.short, version=version)
        c.query('', meta=('type', 'locale', 'platform', 'day_sentiment'),
                **search_opts)
        metas = c.meta
        daily = c.meta.get('day_sentiment', {})
        chart_data = dict(series=[
            dict(name=_('Praise'), data=daily['praise']),
            dict(name=_('Issues'), data=daily['issue']),
            dict(name=_('Ideas'), data=daily['idea']),
            ])
        total = c.total_found
    except SearchError:
        metas = {}
        total = latest_beta.count()
        chart_data = None

    data = {'opinions': latest_opinions.all()[:settings.MESSAGES_COUNT],
            'opinion_count': total,
            'product': prod,
            'products': PROD_CHOICES,
            'sentiments': get_sentiment(metas.get('type', [])),
            'terms': stats.frequent_terms(qs=frequent_terms),
            'locales': metas.get('locale'),
            'platforms': metas.get('platform'),
            'sites': sites,
            'version': version,
            'versions': VERSION_CHOICES[prod],
            'chart_data_json': json.dumps(chart_data),
            'defaults': get_defaults(search_form),
            'search_form': search_form,
           }

    if not request.mobile_site:
        template = 'dashboard/beta.html'
    else:
        template = 'dashboard/mobile/beta.html'
    return jingo.render(request, template, data)
예제 #7
0
        page = search_opts.get('page', 1)

        try:
            c = Client()
            opinions = c.query(query, **search_opts)
        except SearchError, e:
            return jingo.render(request, 'search/unavailable.html',
                                {'search_error': e}, status=500)

    else:
        query = ''
        opinions = None

    if opinions:
        pager = Paginator(opinions, pp)
        # If page request (9999) is out of range, deliver last page of results.
        try:
            data['page'] = pager.page(page)
        except (EmptyPage, InvalidPage):
            data['page'] = pager.page(pager.num_pages)

        data['opinions'] = data['page'].object_list
        data['sent'] = stats.sentiment(qs=opinions)
        data['demo'] = stats.demographics(qs=opinions)

        frequent_terms = Term.objects.frequent(
            opinions=opinions)[:settings.TRENDS_COUNT]
        data['terms'] = stats.frequent_terms(qs=frequent_terms)

    return jingo.render(request, 'search/search.html', data)