Beispiel #1
0
def display(request, gid):
    graph = get_object_or_404(Graphs, pk=gid)

    #OCTAL experiment: graph linearity based on user id
    p = None
    linear = 0
    participant = 0

    if graph.study_active:
        if request.user.is_authenticated():
            p = getParticipantByUID(request.user.pk, gid)

        #user has no participant ID yet, ask them for it
        if p is None:
            return HttpResponseRedirect(urlLanding(gid))

        # make sure participant completed the presurvey
        r = handleSurveys(p, gid)
        if r is not None: return HttpResponseRedirect(r)

        linear = int(p.linear)
        participant = int(p.isParticipant())

    return render(request, "map.html",{"full_graph_skeleton":graph, 
                              "graph_name": escape(strip_tags(graph.name)),
                              "linear":linear,
                              "participant":participant,
                              "editor":int(canEdit(request,gid)),
                              "study_active": int(graph.study_active),})
Beispiel #2
0
def display(request, gid):
    graph = get_object_or_404(Graphs, pk=gid)

    #OCTAL experiment: graph linearity based on user id
    p = None
    linear = 0
    participant = 0

    if graph.study_active:
        if request.user.is_authenticated():
            p = getParticipantByUID(request.user.pk, gid)

        #user has no participant ID yet, ask them for it
        if p is None:
            return HttpResponseRedirect(urlLanding(gid))

        # make sure participant completed the presurvey
        r = handleSurveys(p, gid)
        if r is not None: return HttpResponseRedirect(r)

        linear = int(p.linear)
        participant = int(p.isParticipant())

    return render(
        request, "map.html", {
            "full_graph_skeleton": graph,
            "graph_name": escape(strip_tags(graph.name)),
            "linear": linear,
            "participant": participant,
            "editor": int(canEdit(request, gid)),
            "study_active": int(graph.study_active),
        })
Beispiel #3
0
def fetch_ex(request, gid="", tag="", qid=""):
    #does the requested concept exist in the graph?
    g = get_object_or_404(Graphs, pk=gid)
    eCon = get_object_or_404(Concepts, graph=g, tag=tag)

    if not request.user.is_authenticated(): return HttpResponse(status=403)
    user, ucreated = User.objects.get_or_create(pk=request.user.pk)

    completed = Attempts.objects.filter(concept=eCon).filter(correct=True)

    # we need to collect data by participant IDs for studies!
    p = getParticipantByUID(request.user.pk, gid)
    if g.study_active and p is None:
        return HttpResponse(status=401)

    completed = studyFilter(g, p, user, completed).values('problem').distinct()

    numComplete = completed.count()

    # filter out questions the user has answered
    pr = Problems.objects.filter(concepts=eCon).exclude(
        pk__in=[x['problem'] for x in completed])

    # how many are in this set?
    numRemaining = pr.count()

    # filter out the current question, if provided and if possible
    if qid and numRemaining > 1: pr = pr.exclude(id=int(qid))

    # if student has completed all, pick one from the total set
    if numRemaining == 0: pr = Problems.objects.filter(concepts=eCon)

    # fetch a question the user hasn't yet answered correctly
    try:
        pr = pr.order_by('?')[:1].get()
    except Problems.DoesNotExist:
        # uh oh, none to give?
        return HttpResponse(status=404)

    # fetch the question answers
    try:
        r = Responses.objects.filter(problem=pr).order_by("distract")
    except Responses.DoesNotExist:
        return HttpResponse(status=404)

    data = {
        'qid': pr.id,
        'h': pr.question,
        't': pr.qtype,
        'a': [x.response for x in r],
        'aid': fetch_attempt_id(user, p, g, eCon, pr),
        'cr': numRemaining,  # expose how many left they have
        'ct': numComplete +
        numRemaining,  # expose how many total questions in concept
    }

    return HttpResponse(json.dumps(data), mimetype='application/json')
Beispiel #4
0
def set_attempt(request, gid="", attempt="", correct=""):
    g = get_object_or_404(Graphs, pk=gid)

    if not request.user.is_authenticated(): return HttpResponse(status=403)
    u, pc = User.objects.get_or_create(pk=request.user.pk)

    attempts = Attempts.objects.filter(submitted=False).filter(graph=g)

    p = getParticipantByUID(request.user.pk, gid)
    if g.study_active and p is None:
        return HttpResponse(status=401)

    attempts = studyFilter(g, p, u, attempts)

    try:
        # only inject attempts if we have not submitted for this attempt
        attempt = attempts.get(pk=attempt)
    except Attempts.DoesNotExist, Attempts.MultipleObjectsReturned:
        attempt = None
Beispiel #5
0
def knowledge_inference(request, gid=""):
    if request.method == "GET":
        g = get_object_or_404(Graphs, pk=gid)

        if not request.user.is_authenticated(): return HttpResponse(status=403)
        u, uc = User.objects.get_or_create(pk=request.user.pk)
        p = getParticipantByUID(request.user.pk, gid)
        if g.study_active and p is None: return HttpResponse(status=401)

        ex = Attempts.objects.filter(graph=g).filter(submitted=True)
        ex = studyFilter(g, p, u, ex)
 
        inferences = []
        if ex.count() > 1:
            r = [e.get_correctness() for e in ex]
            inferences = performInference(g.concept_dict, r)
        return HttpResponse(json.dumps(inferences), mimetype='application/json')
    else:
        return HttpResponse(status=405)
Beispiel #6
0
def knowledge_inference(request, gid=""):
    if request.method == "GET":
        g = get_object_or_404(Graphs, pk=gid)

        if not request.user.is_authenticated(): return HttpResponse(status=403)
        u, uc = User.objects.get_or_create(pk=request.user.pk)
        p = getParticipantByUID(request.user.pk, gid)
        if g.study_active and p is None: return HttpResponse(status=401)

        ex = Attempts.objects.filter(graph=g).filter(submitted=True)
        ex = studyFilter(g, p, u, ex)

        inferences = []
        if ex.count() > 1:
            r = [e.get_correctness() for e in ex]
            inferences = performInference(g.concept_dict, r)
        return HttpResponse(json.dumps(inferences),
                            mimetype='application/json')
    else:
        return HttpResponse(status=405)