From f1cc6e85976c634dc0a79ee5f9b3a5fbd753bf85 Mon Sep 17 00:00:00 2001 From: ichuang Date: Sat, 30 Mar 2013 02:01:32 +0000 Subject: [PATCH 1/3] fix psychoanalyze - make compatible with xblock --- common/lib/xmodule/xmodule/capa_module.py | 2 +- lms/djangoapps/psychometrics/psychoanalyze.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index b437478ecc..83710fd121 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -755,7 +755,7 @@ class CapaModule(CapaFields, XModule): self.system.track_function('save_problem_check', event_info) if hasattr(self.system, 'psychometrics_handler'): # update PsychometricsData using callback - self.system.psychometrics_handler(self.get_instance_state()) + self.system.psychometrics_handler(self.get_state_for_lcp()) # render problem into HTML html = self.get_problem_html(encapsulate=False) diff --git a/lms/djangoapps/psychometrics/psychoanalyze.py b/lms/djangoapps/psychometrics/psychoanalyze.py index 3e9edcc997..008a4034a5 100644 --- a/lms/djangoapps/psychometrics/psychoanalyze.py +++ b/lms/djangoapps/psychometrics/psychoanalyze.py @@ -302,12 +302,12 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key): Construct and return a procedure which may be called to update the PsychometricsData instance for the given StudentModule instance. """ - sm = studentmodule.objects.get_or_create( - course_id=course_id, - student=user, - module_state_key=module_state_key, - defaults={'state': '{}', 'module_type': 'problem'}, - ) + sm, status = StudentModule.objects.get_or_create( + course_id=course_id, + student=user, + module_state_key=module_state_key, + defaults={'state': '{}', 'module_type': 'problem'}, + ) try: pmd = PsychometricData.objects.using(db).get(studentmodule=sm) From 26f14aaf6d6be3c7d8fee91c63ef54a838ab5686 Mon Sep 17 00:00:00 2001 From: ichuang Date: Sun, 31 Mar 2013 12:21:22 +0000 Subject: [PATCH 2/3] fix psychoanalyze (compatibility with new xblock) --- lms/djangoapps/psychometrics/psychoanalyze.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/psychometrics/psychoanalyze.py b/lms/djangoapps/psychometrics/psychoanalyze.py index 008a4034a5..b6072ac997 100644 --- a/lms/djangoapps/psychometrics/psychoanalyze.py +++ b/lms/djangoapps/psychometrics/psychoanalyze.py @@ -329,7 +329,11 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key): return pmd.done = done - pmd.attempts = state['attempts'] + try: + pmd.attempts = state.get('attempts',0) + except: + log.exception("no attempts for %s (state=%s)" % (sm,sm.state)) + try: checktimes = eval(pmd.checktimes) # update log of attempt timestamps except: From febcb5113308fc5b9056558150ff70acb8a30cd0 Mon Sep 17 00:00:00 2001 From: ichuang Date: Sun, 31 Mar 2013 12:52:29 +0000 Subject: [PATCH 3/3] make psychometrics curve fitting more robust --- lms/djangoapps/psychometrics/psychoanalyze.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/psychometrics/psychoanalyze.py b/lms/djangoapps/psychometrics/psychoanalyze.py index b6072ac997..093051a3bd 100644 --- a/lms/djangoapps/psychometrics/psychoanalyze.py +++ b/lms/djangoapps/psychometrics/psychoanalyze.py @@ -246,13 +246,16 @@ def generate_plots_for_problem(problem): yset['ydat'] = ydat if len(ydat) > 3: # try to fit to logistic function if enough data points - cfp = curve_fit(func_2pl, xdat, ydat, [1.0, max_attempts / 2.0]) - yset['fitparam'] = cfp - yset['fitpts'] = func_2pl(np.array(xdat), *cfp[0]) - yset['fiterr'] = [yd - yf for (yd, yf) in zip(ydat, yset['fitpts'])] - fitx = np.linspace(xdat[0], xdat[-1], 100) - yset['fitx'] = fitx - yset['fity'] = func_2pl(np.array(fitx), *cfp[0]) + try: + cfp = curve_fit(func_2pl, xdat, ydat, [1.0, max_attempts / 2.0]) + yset['fitparam'] = cfp + yset['fitpts'] = func_2pl(np.array(xdat), *cfp[0]) + yset['fiterr'] = [yd - yf for (yd, yf) in zip(ydat, yset['fitpts'])] + fitx = np.linspace(xdat[0], xdat[-1], 100) + yset['fitx'] = fitx + yset['fity'] = func_2pl(np.array(fitx), *cfp[0]) + except Exception as err: + log.debug('Error in psychoanalyze curve fitting: %s' % err) dataset['grade_%d' % grade] = yset