Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change reading for mastery_model #3362

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,28 @@ class Command(BaseCommand):

def handle(self, *args, **options):
start = time.time()

reset_time = time.time()

mastery_model_exercise_count = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE)\
mastery_model_exercise_count = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \
.filter(Q(extra_fields__has_key='mastery_model')).order_by().count()

i = 0

while i < mastery_model_exercise_count:
chunk_time = time.time()
update_ids = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE)\
.filter(Q(extra_fields__has_key='mastery_model')).order_by("id").values_list("id", flat=True)[i: i + CHUNKSIZE]
update_ids = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \
.filter(Q(extra_fields__has_key='mastery_model')).order_by("id").values_list("id", flat=True)[i: i + CHUNKSIZE]
ContentNode.objects.filter(pk__in=update_ids).update(complete=True)
logging.info('Marked {} nodes as complete=True in {} seconds'.format(CHUNKSIZE, time.time() - chunk_time))
i += CHUNKSIZE

mastery_model_exercise_count = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \
.filter(Q(extra_fields__has_key='option.completion_criteria.mastery_model')).order_by().count()

while i < mastery_model_exercise_count:
chunk_time = time.time()
update_ids = ContentNode.objects.filter(kind_id=content_kinds.EXERCISE) \
.filter(Q(extra_fields__has_key='option.completion_criteria.mastery_model')).order_by("id").values_list("id", flat=True)[i: i + CHUNKSIZE]
ContentNode.objects.filter(pk__in=update_ids).update(complete=True)
logging.info('Marked {} nodes as complete=True in {} seconds'.format(CHUNKSIZE, time.time() - chunk_time))
i += CHUNKSIZE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def handle(self, *args, **options):
logging.info('Marking mastery_model less exercises...')
count = ContentNode.objects.exclude(complete=False).filter(kind_id=content_kinds.EXERCISE).filter(~Q(extra_fields__has_key='mastery_model')) \
.order_by().update(complete=False)

logging.info('Marked {} mastery_model less exercises(finished in {})'.format(count, time.time() - exercisestart))

count = ContentNode.objects.exclude(complete=False).filter(kind_id=content_kinds.EXERCISE).filter(~Q(extra_fields__has_key='mastery_model') & ~Q(extra_fields__has_key='option.completion_criteria.mastery_model')) \
.order_by().update(complete=False)

logging.info('Marked {} mastery_model less exercises(finished in {})'.format(count, time.time() - exercisestart))

exercisestart = time.time()
Expand Down
10 changes: 9 additions & 1 deletion contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,15 @@ def process_assessment_metadata(ccnode, kolibrinode):
randomize = exercise_data.get('randomize') if exercise_data.get('randomize') is not None else True
assessment_item_ids = [a.assessment_id for a in assessment_items]

mastery_model = {'type': exercise_data.get('mastery_model') or exercises.M_OF_N}
exercise_data_type = ""
if exercise_data.get('mastery_model'):
exercise_data_type = exercise_data.get('mastery_model')
if exercises.M_OF_N:
AtKristijan marked this conversation as resolved.
Show resolved Hide resolved
exercise_data_type = exercises.M_OF_N
if exercise_data.get('option') or exercise_data.get('option').get('completion_criteria') or exercise_data.get('option').get('completion_criteria').get('mastery_model'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be and not or here, otherwise you are trying to access .get from None, if exercise_data.get('option') is None.

I think if you fix this, the tests should pass, and we can merge this PR. We'll manage the rest in follow up work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed

exercise_data_type = exercise_data.get('option').get('completion_criteria').get('mastery_model')

mastery_model = {'type': exercise_data_type}
if mastery_model['type'] == exercises.M_OF_N:
mastery_model.update({'n': exercise_data.get('n') or min(5, assessment_items.count()) or 1})
mastery_model.update({'m': exercise_data.get('m') or min(5, assessment_items.count()) or 1})
Expand Down