Exemplo n.º 1
0
def make_psychometrics_data_update_handler(course_id, user, module_state_key):
    """
    Construct and return a procedure which may be called to update
    the PsychometricData instance for the given StudentModule instance.
    """
    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)
    except PsychometricData.DoesNotExist:
        pmd = PsychometricData(studentmodule=sm)

    def psychometrics_data_update_handler(state):
        """
        This function may be called each time a problem is successfully checked
        (eg on save_problem_check events in capa_module).

        state = instance state (a nice, uniform way to interface - for more future psychometric feature extraction)
        """
        try:
            state = json.loads(sm.state)
            done = state['done']
        except:
            log.exception("Oops, failed to eval state for %s (state=%s)" %
                          (sm, sm.state))
            return

        pmd.done = done
        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:
            checktimes = []
        checktimes.append(datetime.datetime.now(UTC))
        pmd.checktimes = checktimes
        try:
            pmd.save()
        except:
            log.exception("Error in updating psychometrics data for %s" % sm)

    return psychometrics_data_update_handler
Exemplo n.º 2
0
    def handle(self, *args, **options):

        # delete all pmd

        #PsychometricData.objects.all().delete()
        #PsychometricData.objects.using(db).all().delete()

        smset = StudentModule.objects.using(db).exclude(max_grade=None)

        for sm in smset:
            url = sm.module_state_key
            location = Location(url)
            if not location.category == "problem":
                continue
            try:
                state = json.loads(sm.state)
                done = state['done']
            except:
                print "Oops, failed to eval state for %s (state=%s)" % (
                    sm, sm.state)
                continue

            if done:  # only keep if problem completed
                try:
                    pmd = PsychometricData.objects.using(db).get(
                        studentmodule=sm)
                except PsychometricData.DoesNotExist:
                    pmd = PsychometricData(studentmodule=sm)

                pmd.done = done
                pmd.attempts = state['attempts']

                # get attempt times from tracking log
                uname = sm.student.username
                tset = TrackingLog.objects.using(db).filter(
                    username=uname, event_type__contains='save_problem_check')
                tset = tset.filter(event_source='server')
                tset = tset.filter(event__contains="'%s'" % url)
                checktimes = [x.dtcreated for x in tset]
                pmd.checktimes = checktimes
                if not len(checktimes) == pmd.attempts:
                    print "Oops, mismatch in number of attempts and check times for %s" % pmd

                #print pmd
                pmd.save(using=db)

        print "%d PMD entries" % PsychometricData.objects.using(
            db).all().count()
Exemplo n.º 3
0
    def handle(self, *args, **options):

        # delete all pmd

        #PsychometricData.objects.all().delete()
        #PsychometricData.objects.using(db).all().delete()

        smset = StudentModule.objects.using(db).exclude(max_grade=None)

        for sm in smset:
            url = sm.module_state_key
            location = Location(url)
            if not location.category == "problem":
                continue
            try:
                state = json.loads(sm.state)
                done = state['done']
            except:
                print "Oops, failed to eval state for %s (state=%s)" % (sm, sm.state)
                continue

            if done:			# only keep if problem completed
                try:
                    pmd = PsychometricData.objects.using(db).get(studentmodule=sm)
                except PsychometricData.DoesNotExist:
                    pmd = PsychometricData(studentmodule=sm)

                pmd.done = done
                pmd.attempts = state['attempts']

                # get attempt times from tracking log
                uname = sm.student.username
                tset = TrackingLog.objects.using(db).filter(username=uname, event_type__contains='save_problem_check')
                tset = tset.filter(event_source='server')
                tset = tset.filter(event__contains="'%s'" % url)
                checktimes = [x.dtcreated for x in tset]
                pmd.checktimes = checktimes
                if not len(checktimes) == pmd.attempts:
                    print "Oops, mismatch in number of attempts and check times for %s" % pmd

                #print pmd
                pmd.save(using=db)

        print "%d PMD entries" % PsychometricData.objects.using(db).all().count()