Example #1
0
def results_overview(request,user):

    user = figure_out_username_capitalization(user)

    if user in [None,'']:
        return HttpResponse('Er is een probleem. Heb je misschien een afgeschermd account?')

    return render(request,'result_overview.html',{'twitter_user':user,
                                                  'classifier_sections':ClassifierSection.objects.all().order_by('position'),
                                                  'profile_image_url':get_profile_image_url(user,settings.PASSWORD_FOLDER )})
Example #2
0
def individual_classifier_result(request,user,classifier_name):

    #Find the classifier object
    classifier = None

    for classifier_section in ClassifierSection.objects.all():

        if classifier_section.classifier_module_name in [classifier_name+'_classifier',classifier_name]:
            classifier = classifier_section
            break

    if classifier == None:
        raise Http404("No classifier with this name is defined")

    all_tweets_for_user = file_to_tweet_dict(settings.TWEET_DATAFOLDER+user+'.txt')

    try:
        #Annotated tweets group may be smaller than group of all tweets
        annotated_tweets = add_annotations_in_files_to_tweets(settings.CLASSIFICATION_DATAFOLDER + user + '.' + classifier.classifier_module_name + '.txt',
                                   classifier_name, all_tweets_for_user)
    except FileNotFoundError:
        return HttpResponse(-1);

    # Prepare saving the most extreme scores for each class for this classifier
    most_extreme_tweets = {}
    meterscores_per_class = {}

    # See what classes there are for this classifier, by taking them from a random tweet
    classes_for_this_classifier = list(
        annotated_tweets[0].automatic_classifications[classifier_name].keys())

    # For each class, take the most extreme cases
    for classname in classes_for_this_classifier:
        all_tweets_sorted_by_confidence_for_this_class = sorted(annotated_tweets, key=lambda tweet:
        tweet.automatic_classifications[classifier_name][classname], reverse=True)
        most_extreme_tweets[classname] = all_tweets_sorted_by_confidence_for_this_class[
                                                          :settings.NUMBER_OF_TWEETS_TO_SHOW_PER_CLASS]

        if classifier_section.number_of_tweets_in_score_calculation == 0:
            tweets_to_use_for_meter_score = all_tweets_sorted_by_confidence_for_this_class
        else:
            tweets_to_use_for_meter_score = all_tweets_sorted_by_confidence_for_this_class[
                                            :classifier_section.number_of_tweets_in_score_calculation]

        meterscores_per_class[classname] = calculate_meterscore_for_class_based_on_tweets(classifier_name,classname,tweets_to_use_for_meter_score)

        print(most_extreme_tweets)

    return render(request, classifier_name+'_content.html',
                  {
                   'most_extreme_tweets': most_extreme_tweets,
                   'meterscores_per_class': meterscores_per_class,
                   'profile_image_url': get_profile_image_url(user, settings.PASSWORD_FOLDER)})