Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        project = self.get_project()

        context['show_analytics'] = project.has_feature(
            Feature.SEARCH_ANALYTICS, )
        if not context['show_analytics']:
            return context

        # data for plotting the line-chart
        query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month(
            project.slug, )

        queries = []
        qs = SearchQuery.objects.filter(project=project)
        if qs.exists():
            qs = (qs.values('query').annotate(count=Count('id')).order_by(
                '-count', 'query').values_list('query', 'count'))

            # only show top 100 queries
            queries = qs[:100]

        context.update(
            {
                'queries': queries,
                'query_count_of_1_month': query_count_of_1_month,
            }, )
        return context
Exemplo n.º 2
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        project = self.get_project()
        enabled = self._is_enabled(project)
        context.update({'enabled': enabled})
        if not enabled:
            return context

        # data for plotting the line-chart
        query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month(
            project.slug, )

        queries = []
        qs = SearchQuery.objects.filter(project=project)
        if qs.exists():
            qs = (qs.values('query').annotate(count=Count('id')).order_by(
                '-count', 'query').values_list('query', 'count',
                                               'total_results'))

            # only show top 100 queries
            queries = qs[:100]

        context.update(
            {
                'queries': queries,
                'query_count_of_1_month': query_count_of_1_month,
            }, )
        return context
Exemplo n.º 3
0
def search_analytics_view(request, project_slug):
    """View for search analytics."""
    project = get_object_or_404(
        Project.objects.for_admin_user(request.user),
        slug=project_slug,
    )

    if not project.has_feature(Feature.SEARCH_ANALYTICS):
        return render(request, 'projects/projects_search_analytics.html', {
            'project': project,
            'show_analytics': False,
        })

    download_data = request.GET.get('download', False)

    # if the user has requested to download all data
    # return csv file in response.
    if download_data:
        return _search_analytics_csv_data(request, project_slug)

    # data for plotting the line-chart
    query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month(
        project_slug)
    # data for plotting the doughnut-chart
    distribution_of_top_queries = SearchQuery.generate_distribution_of_top_queries(
        project_slug,
        10,
    )
    now = timezone.now()

    queries = []
    qs = SearchQuery.objects.filter(project=project)
    if qs.exists():
        qs = (qs.values('query').annotate(count=Count('id')).order_by(
            '-count', 'query').values_list('query', 'count'))

        # only show top 100 queries
        queries = qs[:100]

    return render(
        request, 'projects/projects_search_analytics.html', {
            'project': project,
            'queries': queries,
            'show_analytics': True,
            'query_count_of_1_month': query_count_of_1_month,
            'distribution_of_top_queries': distribution_of_top_queries,
        })
Exemplo n.º 4
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        project = self.get_project()

        # data for plotting the line-chart
        query_count_of_1_month = SearchQuery.generate_queries_count_of_one_month(
            project.slug, )

        project_queries = SearchQuery.objects.filter(project=project)
        last_total_results = (project_queries.filter(query=OuterRef(
            'query')).order_by('-modified').values('total_results'))
        queries = (project_queries.values('query').annotate(
            count=Count('id'),
            total_results=Subquery(last_total_results[:1])).order_by(
                '-count', 'query').values_list('query', 'count',
                                               'total_results'))[:100]

        context.update(
            {
                'queries': queries,
                'query_count_of_1_month': query_count_of_1_month,
            }, )
        return context