Commit 8ce53ed8 by Felix Sun

Got rid of answer signatures - these don't work with approximate answers at all.…

Got rid of answer signatures - these don't work with approximate answers at all.  Instead, implemented comparison-based hint matching.

Tests are broken, hint manager is probably broken.
parent 4ee8111c
...@@ -917,6 +917,27 @@ class NumericalResponse(LoncapaResponse): ...@@ -917,6 +917,27 @@ class NumericalResponse(LoncapaResponse):
# TODO: add check_hint_condition(self, hxml_set, student_answers) # TODO: add check_hint_condition(self, hxml_set, student_answers)
def answer_compare(self, a, b):
"""
Outside-facing function that lets us compare two numerical answers,
with this problem's tolerance.
"""
return compare_with_tolerance(
evaluator(dict(), dict(), a),
evaluator(dict(), dict(), b),
self.tolerance
)
def validate_answer(self, answer):
"""
Returns whether this answer is in a valid form.
"""
try:
evaluator(dict(), dict(), answer)
return True
except StudentInputError:
return False
def get_answers(self): def get_answers(self):
return {self.answer_id: self.correct_answer} return {self.answer_id: self.correct_answer}
...@@ -1858,6 +1879,24 @@ class FormulaResponse(LoncapaResponse): ...@@ -1858,6 +1879,24 @@ class FormulaResponse(LoncapaResponse):
return "incorrect" return "incorrect"
return "correct" return "correct"
def answer_compare(self, a, b):
"""
An external interface for comparing whether a and b are equal.
"""
internal_result = self.check_formula(a, b, self.samples)
return internal_result == "correct"
def validate_answer(self, answer):
"""
Returns whether this answer is in a valid form.
"""
var_dict_list = self.randomize_variables(self.samples)
try:
self.hash_answers(answer, var_dict_list)
return True
except StudentInputError:
return False
def strip_dict(self, d): def strip_dict(self, d):
''' Takes a dict. Returns an identical dict, with all non-word ''' Takes a dict. Returns an identical dict, with all non-word
keys and all non-numeric values stripped out. All values also keys and all non-numeric values stripped out. All values also
......
...@@ -3,18 +3,14 @@ ...@@ -3,18 +3,14 @@
<%def name="get_hint()"> <%def name="get_hint()">
% if best_hint != '': % if len(hints) > 0:
<h4> Hints from students who made similar mistakes: </h4> <h4> Hints from students who made similar mistakes: </h4>
<ul> <ul>
<li> ${best_hint} </li> % for hint in hints:
% endif <li> ${hint} </li>
% if rand_hint_1 != '': % endfor
<li> ${rand_hint_1} </li> </ul>
% endif
% if rand_hint_2 != '':
<li> ${rand_hint_2} </li>
% endif % endif
</ul>
</%def> </%def>
<%def name="get_feedback()"> <%def name="get_feedback()">
...@@ -66,17 +62,13 @@ ...@@ -66,17 +62,13 @@
<div id="answer-tabs"> <div id="answer-tabs">
<ul> <ul>
% for answer in answer_to_hints: % for answer in user_submissions:
<li><a href="#previous-answer-${unspace(answer)}"> ${answer} </a></li> <li><a href="#previous-answer-${unspace(answer)}"> ${answer} </a></li>
% endfor % endfor
</ul> </ul>
% for answer, pk_dict in answer_to_hints.items(): % for answer in user_submissions:
<% <div class = "previous-answer" id="previous-answer-${unspace(answer)}" data-answer="${answer}">
import json
all_pks = json.dumps(pk_dict.keys())
%>
<div class = "previous-answer" id="previous-answer-${unspace(answer)}" data-answer="${answer}" data-all-pks='${all_pks}'>
<div class = "hint-inner-container"> <div class = "hint-inner-container">
<p> <p>
What hint would you give a student who made the same mistake you did? Please don't give away the answer. What hint would you give a student who made the same mistake you did? Please don't give away the answer.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment