From fa2cf6a49c31101f86395f6b1fe81b41f7c94bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Thu, 1 Nov 2012 08:22:33 +0200 Subject: [PATCH] add convert_to_perepherial flag and removed order flags --- common/lib/capa/capa/chem/chemtools.py | 42 +++++++++----------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/common/lib/capa/capa/chem/chemtools.py b/common/lib/capa/capa/chem/chemtools.py index e5a8e1a6f6..3f6100cfff 100644 --- a/common/lib/capa/capa/chem/chemtools.py +++ b/common/lib/capa/capa/chem/chemtools.py @@ -16,12 +16,11 @@ def vsepr_build_correct_answer(geometry, atoms): return correct_answer -def vsepr_grade(user_input, correct_answer, ignore_p_order=False, ignore_a_order=False, ignore_e_order=False): - """ Flags ignore_(a,p,e)_order are for checking order in axial, perepherial or equatorial positions. +def vsepr_grade(user_input, correct_answer, convert_to_perepherial=False): + """ Allowed cases: c0, a, e 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 correct_answer, type(correct_answer) @@ -31,31 +30,20 @@ def vsepr_grade(user_input, correct_answer, ignore_p_order=False, ignore_a_order if user_input['atoms']['c0'] != correct_answer['atoms']['c0']: return False - # not order-aware comparisons - for ignore in [(ignore_p_order, 'p'), (ignore_e_order, 'e'), (ignore_a_order, 'a')]: - if ignore[0]: - # collecting atoms: - 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 + if convert_to_perepherial: + # convert user_input from (a,e,e1,e2) to (p) + # correct_answer must be set in (p) using this flag + user_input['atoms'] = {'p' + str(i): v for i, v in enumerate(user_input['atoms'].values())} - # order-aware comparisons - for ignore in [(ignore_p_order, 'p'), (ignore_e_order, 'e'), (ignore_a_order, 'a')]: - if not ignore[0]: - # collecting atoms: - 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 '2nd', ignore[0], ignore[1], a_user, a_correct - if len(a_user) != len(a_correct): - return False - if len(a_correct) == 0: - continue - if a_user != a_correct: - return False + for ea_position in ['p', 'a', 'e', 'e1', 'e2']: + # collecting atoms: + 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(ea_position)] + # print a_user, a_correct + if len(a_user) != len(a_correct): + return False + if sorted(a_user) != sorted(a_correct): + return False return True