Ejemplo n.º 1
0
def mark_exam(user_id, exam_id):
    """ Submit the assessment and mark it.
        Returns True if it went well, or False if a problem.
    """
    numquestions = Exams.get_num_questions(exam_id)
    status = Exams.get_user_status(user_id, exam_id)
    L.info("Marking assessment %s for %s, status is %s" %
           (exam_id, user_id, status))
    examtotal = 0.0
    errors = 0
    for position in range(1, numquestions + 1):
        q_id = General.get_exam_q(exam_id, position, user_id)
        if not q_id:
            L.critical(
                "Unable to retrieve exam question page %s, exam %s, for user %s"
                % (position, exam_id, user_id))
            errors += 1
            continue
        answers = DB.get_q_guesses(q_id)
        # There's a small chance they got here without ever seeing a question,
        # make sure it exists.
        DB.add_exam_q(user_id, exam_id, q_id, position)

        # First, mark the question
        try:
            marks = General.mark_q(q_id, answers)
            DB.set_q_status(q_id, 3)  # 3 = marked
            DB.set_q_marktime(q_id)
        except OaMarkerError:
            L.warn("Marker Error in question %s, exam %s, student %s!" %
                   (q_id, exam_id, user_id))
            return False
        parts = [
            int(var[1:]) for var in marks.keys()
            if re.search("^A([0-9]+)$", var) > 0
        ]
        parts.sort()

        # Then calculate the mark
        total = 0.0
        for part in parts:
            try:
                mark = float(marks['M%d' % (part, )])
            except (KeyError, ValueError):
                mark = 0
            total += mark
            DB.update_q_score(q_id, total)
        examtotal += total
    if not errors:
        Exams.set_user_status(user_id, exam_id, 5)
        Exams.set_submit_time(user_id, exam_id)
        Exams.save_score(exam_id, user_id, examtotal)
        Exams.touchuserexam(exam_id, user_id)

    if errors:
        return False
    L.info("user %s scored %s total on exam %s" %
           (user_id, examtotal, exam_id))
    return True
Ejemplo n.º 2
0
def mark_exam(user_id, exam_id):
    """ Submit the assessment and mark it.
        Returns True if it went well, or False if a problem.
    """
    numquestions = Exams.get_num_questions(exam_id)
    status = Exams.get_user_status(user_id, exam_id)
    L.info("Marking assessment %s for %s, status is %s" % (exam_id, user_id, status))
    examtotal = 0.0
    errors = 0
    for position in range(1, numquestions + 1):
        q_id = General.get_exam_q(exam_id, position, user_id)
        if not q_id:
            L.critical("Unable to retrieve exam question page %s, exam %s, for user %s" % (position, exam_id, user_id
                                                                                           )
                       )
            errors += 1
            continue
        answers = DB.get_q_guesses(q_id)
        # There's a small chance they got here without ever seeing a question,
        # make sure it exists.
        DB.add_exam_q(user_id, exam_id, q_id, position)

        # First, mark the question
        try:
            marks = General.mark_q(q_id, answers)
            DB.set_q_status(q_id, 3)    # 3 = marked
            DB.set_q_marktime(q_id)
        except OaMarkerError:
            L.warn("Marker Error in question %s, exam %s, student %s!" %
                   (q_id, exam_id, user_id))
            return False
        parts = [int(var[1:])
                 for var in marks.keys()
                 if re.search("^A([0-9]+)$", var) > 0]
        parts.sort()

        # Then calculate the mark
        total = 0.0
        for part in parts:
            try:
                mark = float(marks['M%d' % (part,)])
            except (KeyError, ValueError):
                mark = 0
            total += mark
            DB.update_q_score(q_id, total)
        examtotal += total
    if not errors:
        Exams.set_user_status(user_id, exam_id, 5)
        Exams.set_submit_time(user_id, exam_id)
        Exams.save_score(exam_id, user_id, examtotal)
        Exams.touchuserexam(exam_id, user_id)

    if errors:
        return False
    L.info("user %s scored %s total on exam %s" %
           (user_id, examtotal, exam_id))
    return True
Ejemplo n.º 3
0
def remark_prac(question):
    """ Re-mark the practice question and store the score back
        in the questions table.
    """
    answers = DB.get_q_guesses(question)
    try:
        marks = mark_q(question, answers)
    except OaMarkerError:
        return None
    parts = [int(var[1:])
             for var in marks.keys()
             if re.search("^A([0-9]+)$", var) > 0]
    parts.sort()
    total = 0.0
    for part in parts:
        try:
            mark = float(marks['M%d' % part])
        except (ValueError, TypeError, KeyError):
            mark = 0
        total += mark
    DB.update_q_score(question, total)
    DB.set_q_status(question, 3)    # 3 = marked
    return total
Ejemplo n.º 4
0
def remark_prac(question):
    """ Re-mark the practice question and store the score back
        in the questions table.
    """
    answers = DB.get_q_guesses(question)
    try:
        marks = mark_q(question, answers)
    except OaMarkerError:
        return None
    parts = [
        int(var[1:]) for var in marks.keys()
        if re.search("^A([0-9]+)$", var) > 0
    ]
    parts.sort()
    total = 0.0
    for part in parts:
        try:
            mark = float(marks['M%d' % part])
        except (ValueError, TypeError, KeyError):
            mark = 0
        total += mark
    DB.update_q_score(question, total)
    DB.set_q_status(question, 3)  # 3 = marked
    return total
Ejemplo n.º 5
0
def render_q_html(q_id, readonly=False):
    """ Fetch the question html and get it ready for display - replacing
        links with appropriate targets and filling in form details."""
    try:
        q_id = int(q_id)
        assert q_id > 0
    except (ValueError, TypeError, AssertionError):
        L.warn("renderQuestionHTML(%s,%s) called with bad qid?" % (q_id, readonly))
    qt_id = DB.get_q_parent(q_id)
    try:
        qt_id = int(qt_id)
        assert qt_id > 0
    except (ValueError, TypeError, AssertionError):
        L.warn("renderQuestionHTML(%s,%s), getparent failed? " % (q_id, readonly))
    variation = DB.get_q_variation(q_id)
    version = DB.get_q_version(q_id)
    data = DB.get_q_att(qt_id, "qtemplate.html", variation, version)
    if not data:
        L.warn("Unable to retrieve qtemplate for q_id: %s" % q_id)
        return "QuestionError"
    try:
        out = unicode(data, "utf-8")
    except UnicodeDecodeError:
        try:
            out = unicode(DB.get_q_att(qt_id, "qtemplate.html", variation, version),
                          "latin-1")
        except UnicodeDecodeError as err:
            L.error("unicode error decoding qtemplate for q_id %s: %s" % (q_id, err))
            raise
    out = out.replace("This question is not verified yet, please report any error!", "")

    out = out.replace("ANS_", "Q_%d_ANS_" % (q_id,))
    out = out.replace("$IMAGES$",
                      "%s/att/qatt/%s/%s/%s/" %
                      (OaConfig.parentURL, qt_id, version, variation))
    out = out.replace("$APPLET$",
                      "%s/att/qatt/%s/%s/%s/" %
                      (OaConfig.parentURL, qt_id, version, variation))
    out = out.replace("$STATIC$",
                      "%s/att/qtatt/%s/%s/%s/" %
                      (OaConfig.parentURL, qt_id, version, variation))
    if readonly:
        out = out.replace("<INPUT ", "<INPUT READONLY ")
        out = out.replace("<SELECT ", "<SELECT DISABLED=DISABLED STYLE='color: black;'")
    guesses = DB.get_q_guesses(q_id)
    for guess in guesses.keys():
        # noinspection PyComparisonWithNone
        if guesses[guess] == None:  # If it's 0 we want to leave it alone
            guesses[guess] = ""
        if guesses[guess] == "None":
            guesses[guess] = ""
            # for each question
    if guesses:
        for ques in range(25, 0, -1):
            if ("G%d" % ques) in guesses:
                out = out.replace("VAL_%d" % ques, htmlesc(guesses["G%d" % ques]))
                for part in range(50, 0, -1):
                    if guesses["G%d" % ques] == "%s.0" % part or guesses["G%d" % ques] == "%s" % part:
                        out = out.replace("Oa_SEL_%d_%d" % (ques, part),
                                          "SELECTED")
                        out = out.replace("Oa_CHK_%d_%d" % (ques, part),
                                          "CHECKED")
                    else:
                        out = out.replace("Oa_SEL_%d_%d" % (ques, part),
                                          "")
                        out = out.replace("Oa_CHK_%d_%d" % (ques, part),
                                          "")
            else:
                out = out.replace("VAL_%d" % (ques,), "")
    for ques in range(25, 0, -1):
        out = out.replace("VAL_%d" % (ques,), "")
    return out
Ejemplo n.º 6
0
    out = out.replace("This question is not verified yet, please report any error!", "")

    out = out.replace("ANS_", "Q_%d_ANS_" % (q_id,))
    out = out.replace("$IMAGES$",
                      "%s/att/qatt/%s/%s/%s/" %
                      (OaConfig.parentURL, qt_id, version, variation))
    out = out.replace("$APPLET$",
                      "%s/att/qatt/%s/%s/%s/" %
                      (OaConfig.parentURL, qt_id, version, variation))
    out = out.replace("$STATIC$",
                      "%s/att/qtatt/%s/%s/%s/" %
                      (OaConfig.parentURL, qt_id, version, variation))
    if readonly:
        out = out.replace("<INPUT ", "<INPUT READONLY ")
        out = out.replace("<SELECT ", "<SELECT DISABLED=DISABLED STYLE='color: black;'")
    guesses = DB.get_q_guesses(q_id)
    for guess in guesses.keys():
        # noinspection PyComparisonWithNone
        if guesses[guess] == None:  # If it's 0 we want to leave it alone
            guesses[guess] = ""
        if guesses[guess] == "None":
            guesses[guess] = ""
            # for each question
    if guesses:
        for ques in range(25, 0, -1):
            if ("G%d" % ques) in guesses:
                out = out.replace("VAL_%d" % ques, htmlesc(guesses["G%d" % ques]))
                for part in range(50, 0, -1):
                    if guesses["G%d" % ques] == "%s.0" % part or guesses["G%d" % ques] == "%s" % part:
                        out = out.replace("Oa_SEL_%d_%d" % (ques, part),
                                          "SELECTED")
Ejemplo n.º 7
0
def render_q_html(q_id, readonly=False):
    """ Fetch the question html and get it ready for display - replacing
        links with appropriate targets and filling in form details."""
    try:
        q_id = int(q_id)
        assert q_id > 0
    except (ValueError, TypeError, AssertionError):
        L.warn("renderQuestionHTML(%s,%s) called with bad qid?" %
               (q_id, readonly))
    qt_id = DB.get_q_parent(q_id)
    try:
        qt_id = int(qt_id)
        assert qt_id > 0
    except (ValueError, TypeError, AssertionError):
        L.warn("renderQuestionHTML(%s,%s), getparent failed? " %
               (q_id, readonly))
    variation = DB.get_q_variation(q_id)
    version = DB.get_q_version(q_id)
    data = DB.get_q_att(qt_id, "qtemplate.html", variation, version)
    if not data:
        L.warn("Unable to retrieve qtemplate for q_id: %s" % q_id)
        return "QuestionError"
    try:
        out = unicode(data, "utf-8")
    except UnicodeDecodeError:
        try:
            out = unicode(
                DB.get_q_att(qt_id, "qtemplate.html", variation, version),
                "latin-1")
        except UnicodeDecodeError as err:
            L.error("unicode error decoding qtemplate for q_id %s: %s" %
                    (q_id, err))
            raise
    out = out.replace(
        "This question is not verified yet, please report any error!", "")

    out = out.replace("ANS_", "Q_%d_ANS_" % (q_id, ))
    out = out.replace(
        "$IMAGES$", "%s/att/qatt/%s/%s/%s/" %
        (OaConfig.parentURL, qt_id, version, variation))
    out = out.replace(
        "$APPLET$", "%s/att/qatt/%s/%s/%s/" %
        (OaConfig.parentURL, qt_id, version, variation))
    out = out.replace(
        "$STATIC$", "%s/att/qtatt/%s/%s/%s/" %
        (OaConfig.parentURL, qt_id, version, variation))
    if readonly:
        out = out.replace("<INPUT ", "<INPUT READONLY ")
        out = out.replace("<SELECT ",
                          "<SELECT DISABLED=DISABLED STYLE='color: black;'")
    guesses = DB.get_q_guesses(q_id)
    for guess in guesses.keys():
        # noinspection PyComparisonWithNone
        if guesses[guess] == None:  # If it's 0 we want to leave it alone
            guesses[guess] = ""
        if guesses[guess] == "None":
            guesses[guess] = ""
            # for each question
    if guesses:
        for ques in range(25, 0, -1):
            if ("G%d" % ques) in guesses:
                out = out.replace("VAL_%d" % ques,
                                  htmlesc(guesses["G%d" % ques]))
                for part in range(50, 0, -1):
                    if guesses["G%d" % ques] == "%s.0" % part or guesses[
                            "G%d" % ques] == "%s" % part:
                        out = out.replace("Oa_SEL_%d_%d" % (ques, part),
                                          "SELECTED")
                        out = out.replace("Oa_CHK_%d_%d" % (ques, part),
                                          "CHECKED")
                    else:
                        out = out.replace("Oa_SEL_%d_%d" % (ques, part), "")
                        out = out.replace("Oa_CHK_%d_%d" % (ques, part), "")
            else:
                out = out.replace("VAL_%d" % (ques, ), "")
    for ques in range(25, 0, -1):
        out = out.replace("VAL_%d" % (ques, ), "")
    return out