Commit 1717782c by Piotr Mitros

Merge pull request #1776 from MITx/feature/ichuang/psychometrics-fix

fix psychometrics to be compatible with new xblocks
parents 56d5f13b febcb511
...@@ -783,7 +783,7 @@ class CapaModule(CapaFields, XModule): ...@@ -783,7 +783,7 @@ class CapaModule(CapaFields, XModule):
self.system.track_function('save_problem_check', event_info) self.system.track_function('save_problem_check', event_info)
if hasattr(self.system, 'psychometrics_handler'): # update PsychometricsData using callback 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 # render problem into HTML
html = self.get_problem_html(encapsulate=False) html = self.get_problem_html(encapsulate=False)
......
...@@ -246,13 +246,16 @@ def generate_plots_for_problem(problem): ...@@ -246,13 +246,16 @@ def generate_plots_for_problem(problem):
yset['ydat'] = ydat yset['ydat'] = ydat
if len(ydat) > 3: # try to fit to logistic function if enough data points 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]) try:
yset['fitparam'] = cfp cfp = curve_fit(func_2pl, xdat, ydat, [1.0, max_attempts / 2.0])
yset['fitpts'] = func_2pl(np.array(xdat), *cfp[0]) yset['fitparam'] = cfp
yset['fiterr'] = [yd - yf for (yd, yf) in zip(ydat, yset['fitpts'])] yset['fitpts'] = func_2pl(np.array(xdat), *cfp[0])
fitx = np.linspace(xdat[0], xdat[-1], 100) yset['fiterr'] = [yd - yf for (yd, yf) in zip(ydat, yset['fitpts'])]
yset['fitx'] = fitx fitx = np.linspace(xdat[0], xdat[-1], 100)
yset['fity'] = func_2pl(np.array(fitx), *cfp[0]) 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 dataset['grade_%d' % grade] = yset
...@@ -302,12 +305,12 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key): ...@@ -302,12 +305,12 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key):
Construct and return a procedure which may be called to update Construct and return a procedure which may be called to update
the PsychometricsData instance for the given StudentModule instance. the PsychometricsData instance for the given StudentModule instance.
""" """
sm = studentmodule.objects.get_or_create( sm, status = StudentModule.objects.get_or_create(
course_id=course_id, course_id=course_id,
student=user, student=user,
module_state_key=module_state_key, module_state_key=module_state_key,
defaults={'state': '{}', 'module_type': 'problem'}, defaults={'state': '{}', 'module_type': 'problem'},
) )
try: try:
pmd = PsychometricData.objects.using(db).get(studentmodule=sm) pmd = PsychometricData.objects.using(db).get(studentmodule=sm)
...@@ -329,7 +332,11 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key): ...@@ -329,7 +332,11 @@ def make_psychometrics_data_update_handler(course_id, user, module_state_key):
return return
pmd.done = done 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: try:
checktimes = eval(pmd.checktimes) # update log of attempt timestamps checktimes = eval(pmd.checktimes) # update log of attempt timestamps
except: except:
......
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