Commit fa2cf6a4 by Александр

add convert_to_perepherial flag and removed order flags

parent e4c49f3a
...@@ -16,12 +16,11 @@ def vsepr_build_correct_answer(geometry, atoms): ...@@ -16,12 +16,11 @@ def vsepr_build_correct_answer(geometry, atoms):
return correct_answer return correct_answer
def vsepr_grade(user_input, correct_answer, ignore_p_order=False, ignore_a_order=False, ignore_e_order=False): def vsepr_grade(user_input, correct_answer, convert_to_perepherial=False):
""" Flags ignore_(a,p,e)_order are for checking order in axial, perepherial or equatorial positions. """
Allowed cases: Allowed cases:
c0, a, e c0, a, e
c0, p c0, p
Not implemented and not tested cases when p with a or e (no need for now)
""" """
# print user_input, type(user_input) # print user_input, type(user_input)
# print correct_answer, type(correct_answer) # print correct_answer, type(correct_answer)
...@@ -31,30 +30,19 @@ def vsepr_grade(user_input, correct_answer, ignore_p_order=False, ignore_a_order ...@@ -31,30 +30,19 @@ def vsepr_grade(user_input, correct_answer, ignore_p_order=False, ignore_a_order
if user_input['atoms']['c0'] != correct_answer['atoms']['c0']: if user_input['atoms']['c0'] != correct_answer['atoms']['c0']:
return False return False
# not order-aware comparisons if convert_to_perepherial:
for ignore in [(ignore_p_order, 'p'), (ignore_e_order, 'e'), (ignore_a_order, 'a')]: # convert user_input from (a,e,e1,e2) to (p)
if ignore[0]: # correct_answer must be set in (p) using this flag
# collecting atoms: user_input['atoms'] = {'p' + str(i): v for i, v in enumerate(user_input['atoms'].values())}
a_user = [v for k, v in user_input['atoms'].items() if k.startswith(ignore[1])]
a_correct = [v for k, v in correct_answer['atoms'].items() if k.startswith(ignore[1])]
# print ignore[0], ignore[1], a_user, a_correct
if len(a_user) != len(a_correct):
return False
if sorted(a_user) != sorted(a_correct):
return False
# order-aware comparisons for ea_position in ['p', 'a', 'e', 'e1', 'e2']:
for ignore in [(ignore_p_order, 'p'), (ignore_e_order, 'e'), (ignore_a_order, 'a')]:
if not ignore[0]:
# collecting atoms: # collecting atoms:
a_user = [v for k, v in user_input['atoms'].items() if k.startswith(ignore[1])] a_user = [v for k, v in user_input['atoms'].items() if k.startswith(ea_position)]
a_correct = [v for k, v in correct_answer['atoms'].items() if k.startswith(ignore[1])] a_correct = [v for k, v in correct_answer['atoms'].items() if k.startswith(ea_position)]
# print '2nd', ignore[0], ignore[1], a_user, a_correct # print a_user, a_correct
if len(a_user) != len(a_correct): if len(a_user) != len(a_correct):
return False return False
if len(a_correct) == 0: if sorted(a_user) != sorted(a_correct):
continue
if a_user != a_correct:
return False return False
return True return True
......
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