<commit_before>__author__ = 'leif'

import os
import sys
import datetime
# Django
from django.template.context import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
from models import DocumentsExamined
from models import TaskDescription, TopicQuerySuggestion
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.utils import simplejson
from django.core.exceptions import ObjectDoesNotExist
from ifind.search import Query, Response
import pickle
from urllib import urlencode

# Whoosh
from whoosh.index import open_dir

# Cache for autocomplete trie
from django.core import cache

# Timing Query
import timeit

# Experiments
from experiment_functions import get_topic_relevant_count
from experiment_functions import get_experiment_context, print_experiment_context
from experiment_functions import mark_document, log_event
from experiment_functions import time_search_experiment_out,getPerformance, getQueryResultPerformance, get_query_performance_metrics, log_performance
from experiment_configuration import my_whoosh_doc_index_dir
from experiment_configuration import experiment_setups
from time import sleep
from threading import Thread
import json

from result_cache import make_key, get_response, do_cache_pages

ix = open_dir(my_whoosh_doc_index_dir)
ixr = ix.reader()


@login_required
def show_document(request, whoosh_docid):
    #check for timeout
    sys.stdout.flush()
    if time_search_experiment_out(request):
        return HttpResponseRedirect('/treconomics/timeout/')

    context = RequestContext(request)
    ec = get_experiment_context(request)
    uname = ec["username"]
    taskid = ec["taskid"]

    condition = ec["condition"]
    current_search = request.session['queryurl']

    # get document from index
    fields = ixr.stored_fields(int(whoosh_docid))
    title = fields["title"]
    content = fields["content"]
    docnum = fields["docid"]
    doc_date = fields["timedate"]
    doc_source = fields["source"]
    docid = whoosh_docid
    topicnum = ec["topicnum"]

    def get_document_rank():<commit_msg>added doc click event logging<commit_after>__author__ = 'leif'

import os
import sys
import datetime
# Django
from django.template.context import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
from models import DocumentsExamined
from models import TaskDescription, TopicQuerySuggestion
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.utils import simplejson
from django.core.exceptions import ObjectDoesNotExist
from ifind.search import Query, Response
import pickle
from urllib import urlencode

# Whoosh
from whoosh.index import open_dir

# Cache for autocomplete trie
from django.core import cache

# Timing Query
import timeit

# Experiments
from experiment_functions import get_topic_relevant_count
from experiment_functions import get_experiment_context, print_experiment_context
from experiment_functions import mark_document, log_event
from experiment_functions import time_search_experiment_out,getPerformance, getQueryResultPerformance, get_query_performance_metrics, log_performance
from experiment_configuration import my_whoosh_doc_index_dir
from experiment_configuration import experiment_setups
from time import sleep
from threading import Thread
import json

from result_cache import make_key, get_response, do_cache_pages

ix = open_dir(my_whoosh_doc_index_dir)
ixr = ix.reader()


@login_required
def show_document(request, whoosh_docid):
    #check for timeout
    sys.stdout.flush()
    if time_search_experiment_out(request):
        return HttpResponseRedirect('/treconomics/timeout/')

    context = RequestContext(request)
    ec = get_experiment_context(request)
    uname = ec["username"]
    taskid = ec["taskid"]

    condition = ec["condition"]
    current_search = request.session['queryurl']

    log_event(event="DOC_CLICKED",
                  request=request,
                  whooshid=whoosh_docid)


    # get document from index
    fields = ixr.stored_fields(int(whoosh_docid))
    title = fields["title"]
    content = fields["content"]
    docnum = fields["docid"]
    doc_date = fields["timedate"]
    doc_source = fields["source"]
    docid = whoosh_docid
    topicnum = ec["topicnum"]



    def get_document_rank():
{'fraction_non_alphanumeric': 0.06140917905623788, 'fraction_numerical': 0.0, 'mean_word_length': 5.650429799426934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7057964', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1256, 'n_words': 362}