Skip to content

Commit

Permalink
feat: add tracking log for completion events
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Aug 22, 2023
1 parent cab393a commit 5c78784
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions completion/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@

from model_utils.models import TimeStampedModel

from eventtracking import tracker

from . import waffle

log = logging.getLogger(__name__)
User = auth.get_user_model()


BLOCK_COMPLETION_CHANGED_EVENT_TYPE = 'edx.completion.block_completion.changed'


def validate_percent(value):
"""
Verify that the passed value is between 0.0 and 1.0.
Expand Down Expand Up @@ -126,6 +131,31 @@ def submit_completion(self, user, block_key, completion):
"BlockCompletion.objects.submit_completion should not be \
called when the feature is disabled."
)
"""
id = BigAutoField(primary_key=True) # pylint: disable=invalid-name
user = models.ForeignKey(User, on_delete=models.CASCADE)
context_key = LearningContextKeyField(max_length=255, db_column="course_key")
# note: this usage key may not have the run filled in for
# old mongo courses. Use the full_block_key property
# instead when you want to use/compare the usage_key.
block_key = UsageKeyField(max_length=255)
block_type = models.CharField(max_length=64)
completion = models.FloatField(validators=[validate_percent])
"""
tracker.emit(
str(BLOCK_COMPLETION_CHANGED_EVENT_TYPE),
{
'user_id': user.id,
'course_id': str(block_key.course_key),
'context_key': str(context_key),
'block_key': str(block_key),
'block_type': block_type,
'completion': completion,
'is_new': is_new,
}
)

return obj, is_new

@transaction.atomic()
Expand Down

0 comments on commit 5c78784

Please sign in to comment.