Esempio n. 1
0
def topic_ordering(request, dataset, analysis, order_by):
    request.session['topic-sort'] = order_by
    request.session['topic-page'] = 1
    name_scheme_id = request.session['current_name_scheme_id']
    ret_val = dict()
    topics = Topic.objects.filter(analysis__name=analysis,
            analysis__dataset__name=dataset)
    topics, _, num_pages = clean_topics_from_session(topics, request.session)
    ret_val['topics'] = [vars(AjaxTopic(topic, get_topic_name(topic,
        name_scheme_id))) for topic in topics]
    ret_val['num_pages'] = num_pages
    ret_val['page'] = 1
    return HttpResponse(simplejson.dumps(ret_val))
Esempio n. 2
0
def filtered_topics_response(request, dataset, analysis):
    name_scheme_id = request.session['current_name_scheme_id']
    analysis = Analysis.objects.get(dataset__name=dataset, name=analysis)
    topics = analysis.topic_set
    request.session['topic-page'] = 1
    topics, filter_form, num_pages = clean_topics_from_session(topics,
            request.session)
    ret_val = dict()
    ret_val['filter_form'] = filter_form.__unicode__()
    ret_val['topics'] = [vars(AjaxTopic(topic, get_topic_name(topic,
        name_scheme_id))) for topic in topics]
    ret_val['num_pages'] = num_pages
    ret_val['page'] = request.session.get('topic-page', 1)
    return HttpResponse(simplejson.dumps(ret_val))
Esempio n. 3
0
def get_topic_page(request, dataset, analysis, number):
    request.session['topic-page'] = int(number)
    name_scheme_id = request.session['current_name_scheme_id']
    ret_val = dict()
    topics = request.session.get('topics-list', None)
    if not topics:
        topics = Topic.objects.filter(analysis__name=analysis,
                analysis__dataset__name=dataset)
    num_per_page = request.session.get('topics-per-page', 20)
    page = int(number)
    topics, num_pages, _ = paginate_list(topics, page, num_per_page)
    ret_val['topics'] = [vars(AjaxTopic(topic, get_topic_name(topic, name_scheme_id))) for topic in topics]
    ret_val['num_pages'] = num_pages
    ret_val['page'] = page
    return HttpResponse(simplejson.dumps(ret_val))
Esempio n. 4
0
def similar_topics(request, dataset, analysis, topic, measure):
    name_scheme_id = request.session['current_name_scheme_id']
    ret_val = dict()
    request.session['topic-similarity-measure'] = measure
    analysis = Analysis.objects.get(dataset__name=dataset, name=analysis)
    topic = analysis.topic_set.get(number=topic)
    measure = analysis.pairwisetopicmetric_set.get(name=measure)
    similar_topics = topic.pairwisetopicmetricvalue_originating.\
            select_related().filter(metric=measure).order_by('-value')[1:11]
    
    topics = []
    values = []
    for t in similar_topics:
        values += [t.value]
        similar_topic = t.topic2
        topic_name = get_topic_name(similar_topic, name_scheme_id)
        topics += [vars(AjaxTopic(similar_topic, topic_name))]
    ret_val['values'] = values
    ret_val['topics'] = topics
    return HttpResponse(simplejson.dumps(ret_val))
Esempio n. 5
0
def similar_topic_list_widget(request, topic):
    w = Widget("Most Similar Topics", "topics/similar_topics")
    similarity_measures = topic.analysis.pairwisetopicmetric_set.all()
    if similarity_measures:
        name_scheme_id = request.session['current_name_scheme_id']
        measure = request.session.get('topic-similarity-measure', None)
        if measure:
            measure = similarity_measures.get(name=measure)
        else:
            measure = similarity_measures[0]

        similar_topics = topic.pairwisetopicmetricvalue_originating.\
                select_related().filter(metric=measure).order_by('-value')
        entries = []
        for t in similar_topics[1:11]:
            topic = t.topic2
            number = topic.number
            name = str(number) + ': ' + get_topic_name(topic, name_scheme_id)
            entries.append(TopicSimilarityEntry(name, number, t.value))
        w['similar_topics'] = entries
        w['similarity_measures'] = similarity_measures
        w['similarity_measure'] = measure
    
    return w
Esempio n. 6
0
 def get_context_data(self, request, **kwargs):
     context = super(TopicView, self).get_context_data(request, **kwargs)
     
     dataset = context['dataset']
     analysis = context['analysis']
     topic = kwargs['topic'] if 'topic' in kwargs else None
     extra_filters = kwargs['extra_filters'] if 'extra_filters' in kwargs else []
     
     #TODO: clean up this context by moving widget-specific entries into widget contexts
     
     
     context['highlight'] = 'topics_tab'
     context['tab'] = 'topic'
     context['extra_widgets'] = []
 
     context['sort_form'] = SortTopicForm(analysis)
 
     sort_by = request.session.get('topic-sort', 'name')
     context['sort_form'].fields['sort'].initial = sort_by
 
     # Get the name scheme stuff ready
     name_schemes = TopicNameScheme.objects.filter(
             analysis=analysis).order_by('name')
     context['nameschemes'] = name_schemes
     if 'current_name_scheme_id' not in request.session:
         request.session['current_name_scheme_id'] = name_schemes[0].id
 
     current_name_scheme_id = request.session['current_name_scheme_id']
     current_name_scheme = TopicNameScheme.objects.get(id=current_name_scheme_id)
     context['currentnamescheme'] = current_name_scheme
 
     # Filter, sort, and paginate the topics
     if topic:
         topic = get_object_or_404(Topic, number=topic, analysis=analysis)
     topics = analysis.topic_set
     topics, filter_form, num_pages = clean_topics_from_session(topics,
             request.session, extra_filters, topic)
     page_num = request.session.get('topic-page', 1)
     context['topics'] = topics
     context['filter'] = filter_form
     context['num_pages'] = num_pages
     context['page_num'] = page_num
     if not topic:
         topic = context['topics'][0]
     context['topic'] = topic
     
     context['topic_url'] = context['topics_url'] + '/' + str(topic.number)
 
     context['metrics'] = topic.topicmetricvalue_set.all()
 
     topic_name = get_topic_name(topic, current_name_scheme.id)
 
     context['topic_name'] = topic_name
 
     # Build the bread crumb
     context['breadcrumb'] = BreadCrumb().item(dataset).item(analysis).topic(topic.number, topic_name)
     context['view_description'] = 'Topic "'+topic_name + '"'
     
     context['tabs'] = tabs(request, topic, context['topic_url'], \
                            context['IMAGES'], context['currentnamescheme'].name)
     
     return context