Commit 3430024d by Calen Pennington

Add a temporary set_grade method to the FieldDataCache and UserStateCache

parent c3bb2e9b
......@@ -13,7 +13,7 @@ from .models import (
XModuleStudentInfoField
)
import logging
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.block_types import BlockTypeKeyV1
from opaque_keys.edx.asides import AsideUsageKeyV1
from contracts import contract, new_contract
......@@ -490,6 +490,18 @@ class UserStateCache(DjangoOrmFieldCache):
state[kvs_key.field_name] = value
field_object.state = json.dumps(state)
@contract(user_id=int, usage_key=UsageKey, score="number|None", max_score="number|None")
def set_score(self, user_id, usage_key, score, max_score):
"""
UNSUPPORTED METHOD
Set the score and max_score for the specified user and xblock usage.
"""
field_object = self._cache[usage_key]
field_object.grade = score
field_object.max_grade = max_score
field_object.save()
class UserStateSummaryCache(DjangoOrmFieldCache):
"""
......@@ -909,3 +921,15 @@ class FieldDataCache(object):
return False
return self.cache[key.scope].has(key)
@contract(user_id=int, usage_key=UsageKey, score="number|None", max_score="number|None")
def set_score(self, user_id, usage_key, score, max_score):
"""
UNSUPPORTED METHOD
Set the score and max_score for the specified user and xblock usage.
"""
assert not self.user.is_anonymous()
assert user_id == self.user.id
assert usage_key.course_key == self.course_id
self.cache[Scope.user_state].set_score(user_id, usage_key, score, max_score)
......@@ -416,24 +416,18 @@ def get_module_system_for_user(user, field_data_cache,
"""
user_id = event.get('user_id', user.id)
# Construct the key for the module
key = KeyValueStore.Key(
scope=Scope.user_state,
user_id=user_id,
block_scope_id=descriptor.location,
field_name='grade'
)
StudentModule.objects.filter(
student__id=user_id,
module_state_key=descriptor.location,
course_id=course_id,
).update(
grade=event.get('value'),
max_grade=event.get('max_value')
grade = event.get('value')
max_grade = event.get('max_value')
field_data_cache.set_score(
user_id,
descriptor.location,
grade,
max_grade,
)
# Bin score into range and increment stats
score_bucket = get_score_bucket(student_module.grade, student_module.max_grade)
score_bucket = get_score_bucket(grade, max_grade)
tags = [
u"org:{}".format(course_id.org),
......
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