Esempio n. 1
0
def tracker_callback(sender, **kwargs):

    tracker = kwargs.get('instance')
    description = None

    if not apply_points(tracker.user):
        return

    if tracker.course is not None and tracker.course.user == tracker.user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return

    if tracker.event not in NON_ACTIVITY_EVENTS:
        if not tracker.activity_exists():
            return

        type = 'activity_completed'
        points = DefaultGamificationEvent.objects.get(
            event='activity_completed').points
        if tracker.get_activity_type() == "media":
            description = "Media played: " + tracker.get_activity_title()
            type = 'mediaplayed'
            if tracker.is_first_tracker_today():
                points = DefaultGamificationEvent.objects.get(
                    event='media_started').points
            else:
                points = 0
            points += (DefaultGamificationEvent.objects.get(
                event='media_playing_points_per_interval').points * math.floor(
                    tracker.time_taken / DefaultGamificationEvent.objects.get(
                        event='media_playing_interval').points))
            if points > DefaultGamificationEvent.objects.get(
                    event='media_max_points').points:
                points = DefaultGamificationEvent.objects.get(
                    event='media_max_points').points
        else:
            description = "Activity completed: " + tracker.get_activity_title()

    if tracker.points is not None:
        points = tracker.points
        type = tracker.event
        if not description:
            description = tracker.event
    else:
        if tracker.get_activity_type() is not "media":
            if not tracker.is_first_tracker_today():
                return
            if not tracker.completed:
                return

    p = Points()
    p.points = points
    p.type = type
    p.description = description
    p.user = tracker.user
    p.course = tracker.course
    p.save()

    return
Esempio n. 2
0
def tracker_callback(sender, **kwargs):

    tracker = kwargs.get('instance')
    description = None

    print tracker.uuid

    if not apply_points(tracker.user):
        return

    if tracker.course is not None and tracker.course.user == tracker.user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return

    if tracker.event not in NON_ACTIVITY_EVENTS:
        if not tracker.activity_exists():
            return

        type = 'activity_completed'
        points = OPPIA_DEFAULT_POINTS['ACTIVITY_COMPLETED']
        if tracker.get_activity_type() == "media":
            description = "Media played: " + tracker.get_activity_title()
            type = 'mediaplayed'
            if tracker.is_first_tracker_today():
                points = OPPIA_DEFAULT_POINTS['MEDIA_STARTED']
            else:
                points = 0
            points += (
                OPPIA_DEFAULT_POINTS['MEDIA_PLAYING_POINTS_PER_INTERVAL'] *
                math.floor(tracker.time_taken /
                           OPPIA_DEFAULT_POINTS['MEDIA_PLAYING_INTERVAL']))
            if points > OPPIA_DEFAULT_POINTS['MEDIA_MAX_POINTS']:
                points = OPPIA_DEFAULT_POINTS['MEDIA_MAX_POINTS']
        else:
            description = "Activity completed: " + tracker.get_activity_title()

    if tracker.points is not None:
        points = tracker.points
        type = tracker.event
        if not description:
            description = tracker.event
    else:
        if tracker.get_activity_type() is not "media":
            if not tracker.is_first_tracker_today():
                return
            if not tracker.completed:
                return

    p = Points()
    p.points = points
    p.type = type
    p.description = description
    p.user = tracker.user
    p.course = tracker.course
    p.save()

    return
Esempio n. 3
0
def badgeaward_callback(sender, **kwargs):
    award = kwargs.get('instance')
    if not apply_points(award.user):
        return

    p = Points()
    p.points = award.badge.points
    p.type = 'badgeawarded'
    p.description = award.description
    p.user = award.user
    p.save()
Esempio n. 4
0
def signup_callback(sender, **kwargs):
    user = kwargs.get('instance')
    created = kwargs.get('created')
    if created:
        p = Points()
        p.points = settings.OPPIA_POINTS['REGISTER']
        p.type = 'signup'
        p.description = "Initial registration"
        p.user = user
        p.save()
    return
Esempio n. 5
0
def tracker_callback(sender, **kwargs):

    tracker = kwargs.get('instance')
    description = None

    print tracker.uuid

    if not apply_points(tracker.user):
        return

    if tracker.course is not None and tracker.course.user == tracker.user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return

    if tracker.event not in NON_ACTIVITY_EVENTS:
        if not tracker.activity_exists():
            return

        type = 'activity_completed'
        points = OPPIA_DEFAULT_POINTS['ACTIVITY_COMPLETED']
        if tracker.get_activity_type() == "media":
            description = "Media played: " + tracker.get_activity_title()
            type = 'mediaplayed'
            if tracker.is_first_tracker_today():
                points = OPPIA_DEFAULT_POINTS['MEDIA_STARTED']
            else:
                points = 0
            points += (OPPIA_DEFAULT_POINTS['MEDIA_PLAYING_POINTS_PER_INTERVAL'] * math.floor(tracker.time_taken / OPPIA_DEFAULT_POINTS['MEDIA_PLAYING_INTERVAL']))
            if points > OPPIA_DEFAULT_POINTS['MEDIA_MAX_POINTS']:
                points = OPPIA_DEFAULT_POINTS['MEDIA_MAX_POINTS']
        else:
            description = "Activity completed: " + tracker.get_activity_title()

    if tracker.points is not None:
        points = tracker.points
        type = tracker.event
        if not description:
            description = tracker.event
    else:
        if tracker.get_activity_type() is not "media":
            if not tracker.is_first_tracker_today():
                return
            if not tracker.completed:
                return

    p = Points()
    p.points = points
    p.type = type
    p.description = description
    p.user = tracker.user
    p.course = tracker.course
    p.save()

    return
Esempio n. 6
0
def badgeaward_callback(sender, **kwargs):
    award = kwargs.get('instance')
    if not apply_points(award.user):
        return

    p = Points()
    p.points = award.badge.points
    p.type = 'badgeawarded'
    p.description = award.description
    p.user = award.user
    p.save()
    return
Esempio n. 7
0
def badgeaward_callback(sender, **kwargs):
    award = kwargs.get('instance')
    
    # check not superuser
    if award.user.is_superuser:
        return 
    
    p = Points()
    p.points = award.badge.points
    p.type = 'badgeawarded'
    p.description = award.description
    p.user = award.user
    p.save()
    return
Esempio n. 8
0
def createquiz_callback(sender, **kwargs):
    quiz = kwargs.get('instance')
    created = kwargs.get('created')
    
    if not apply_points(quiz.owner):
        return
    
    if created:
        p = Points()
        p.points = settings.OPPIA_POINTS['QUIZ_CREATED']
        p.type = 'quizcreated'
        p.description = "Quiz created: " + quiz.title
        p.user = quiz.owner
        p.save()
    return
def tracker_callback(sender, **kwargs):
    tracker = kwargs.get('instance')
    if not apply_points(tracker.user):
        return
    
    if not tracker.activity_exists():
        return
    
    if tracker.course is not None and tracker.course.user == tracker.user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return
    
    cohort_teacher = Cohort.teacher_member_now(tracker.course, tracker.user)
    if cohort_teacher is not None and settings.OPPIA_TEACHERS_EARN_POINTS is False:
        return
    
    if tracker.get_activity_type() is not "media":
        if not tracker.is_first_tracker_today():
            return
        if not tracker.completed:
            return
    
    type = 'activitycompleted'
    points = settings.OPPIA_POINTS['ACTIVITY_COMPLETED']
    if tracker.get_activity_type() == "media":
        description =  "Media played: " + tracker.get_activity_title()
        type = 'mediaplayed'
        if tracker.is_first_tracker_today():
            points = settings.OPPIA_POINTS['MEDIA_STARTED']
        else:
            points = 0
        points =  (settings.OPPIA_POINTS['MEDIA_PLAYING_POINTS_PER_INTERVAL'] * math.floor(tracker.time_taken/settings.OPPIA_POINTS['MEDIA_PLAYING_INTERVAL']))
        if points > settings.OPPIA_POINTS['MEDIA_MAX_POINTS']:
            points = settings.OPPIA_POINTS['MEDIA_MAX_POINTS']
    else:
        description = "Activity completed: " + tracker.activity_title    
       
    p = Points()
    p.points = points
    p.type = type
    p.description = description
    p.user = tracker.user
    p.course = tracker.course
    p.cohort = Cohort.student_member_now(tracker.course,tracker.user)
    p.save()
    
    # @TODO test if tracker submitted on time
    
    return
Esempio n. 10
0
def tracker_callback(sender, **kwargs):
    tracker = kwargs.get('instance')
    if not apply_points(tracker.user):
        return

    if not tracker.activity_exists():
        return

    if tracker.course is not None and tracker.course.user == tracker.user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return

    if tracker.get_activity_type() is not "media":
        if not tracker.is_first_tracker_today():
            return
        if not tracker.completed:
            return

    type = 'activitycompleted'
    points = settings.OPPIA_POINTS['ACTIVITY_COMPLETED']
    if tracker.get_activity_type() == "media":
        description = "Media played: " + tracker.get_activity_title()
        type = 'mediaplayed'
        if tracker.is_first_tracker_today():
            points = settings.OPPIA_POINTS['MEDIA_STARTED']
        else:
            points = 0
        points = (settings.OPPIA_POINTS['MEDIA_PLAYING_POINTS_PER_INTERVAL'] *
                  math.floor(tracker.time_taken /
                             settings.OPPIA_POINTS['MEDIA_PLAYING_INTERVAL']))
        if points > settings.OPPIA_POINTS['MEDIA_MAX_POINTS']:
            points = settings.OPPIA_POINTS['MEDIA_MAX_POINTS']
    else:
        description = "Activity completed: " + tracker.get_activity_title()

    p = Points()
    p.points = points
    p.type = type
    p.description = description
    p.user = tracker.user
    p.course = tracker.course
    p.save()

    # @TODO test if tracker submitted on time

    return
Esempio n. 11
0
def createquiz_callback(sender, **kwargs):
    warnings.warn(
        "oppia.signals.createquiz_callback() is deprecated and will be removed in Oppia server 0.11.0.",
        RemovedInOppia0110Warning, 2)
    quiz = kwargs.get('instance')
    created = kwargs.get('created')

    if not apply_points(quiz.owner):
        return

    if created:
        p = Points()
        p.points = OPPIA_DEFAULT_POINTS['QUIZ_CREATED']
        p.type = 'quizcreated'
        p.description = "Quiz created: " + quiz.title
        p.user = quiz.owner
        p.save()
    return
Esempio n. 12
0
def createquiz_callback(sender, **kwargs):
    warnings.warn(
        "oppia.signals.createquiz_callback() is deprecated and will be removed in Oppia server 0.11.0.",
        RemovedInOppia0110Warning, 2)
    quiz = kwargs.get('instance')
    created = kwargs.get('created')

    if not apply_points(quiz.owner):
        return

    if created:
        p = Points()
        p.points = OPPIA_DEFAULT_POINTS['QUIZ_CREATED']
        p.type = 'quizcreated'
        p.description = "Quiz created: " + quiz.title
        p.user = quiz.owner
        p.save()
    return
Esempio n. 13
0
def tracker_process_points(tracker, type, description, points):
    if tracker.points is not None:
        points = tracker.points
        type = tracker.event
        if not description:
            description = tracker.event
    else:
        if tracker.get_activity_type() != "media":
            if not tracker.is_first_tracker_today():
                return
            if not tracker.completed:
                return

    p = Points()
    p.points = points
    p.type = type
    p.description = description
    p.user = tracker.user
    p.course = tracker.course
    p.save()
Esempio n. 14
0
def course_download_callback(sender, **kwargs):
    user = kwargs.get('user')
    course = kwargs.get('course')
    
    # check not superuser
    if user.is_superuser:
        return 
    
    if not course.is_first_download(user):
        return 
    
    p = Points()
    p.points = settings.OPPIA_POINTS['COURSE_DOWNLOADED']
    p.type = 'coursedownloaded'
    p.description = "Course downloaded: " + course.get_title()
    p.user = user
    p.course = course
    p.cohort = Cohort.student_member_now(course,user)
    p.save()
    return
Esempio n. 15
0
def course_download_callback(sender, **kwargs):
    user = kwargs.get('user')
    course = kwargs.get('course')
    if not apply_points(user):
        return
    
    if course.user == user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return
    
    if not course.is_first_download(user):
        return 
    
    p = Points()
    p.points = settings.OPPIA_POINTS['COURSE_DOWNLOADED']
    p.type = 'coursedownloaded'
    p.description = "Course downloaded: " + course.get_title()
    p.user = user
    p.course = course
    p.save()
    return
Esempio n. 16
0
def course_download_callback(sender, **kwargs):
    warnings.warn(
        "oppia.signals.course_download_callback() is deprecated and will be removed in Oppia server 0.11.0.",
        RemovedInOppia0110Warning, 2)
    user = kwargs.get('user')
    course = kwargs.get('course')
    if not apply_points(user):
        return

    if course.user == user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return

    if not course.is_first_download(user):
        return

    p = Points()
    p.points = OPPIA_DEFAULT_POINTS['COURSE_DOWNLOADED']
    p.type = 'coursedownloaded'
    p.description = "Course downloaded: " + course.get_title()
    p.user = user
    p.course = course
    p.save()
    return
Esempio n. 17
0
def course_download_callback(sender, **kwargs):
    warnings.warn(
        "oppia.signals.course_download_callback() is deprecated and will be removed in Oppia server 0.11.0.",
        RemovedInOppia0110Warning, 2)
    user = kwargs.get('user')
    course = kwargs.get('course')
    if not apply_points(user):
        return

    if course.user == user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return

    if not course.is_first_download(user):
        return

    p = Points()
    p.points = OPPIA_DEFAULT_POINTS['COURSE_DOWNLOADED']
    p.type = 'coursedownloaded'
    p.description = "Course downloaded: " + course.get_title()
    p.user = user
    p.course = course
    p.save()
    return
Esempio n. 18
0
def tracker_callback(sender, **kwargs):
    tracker = kwargs.get('instance')
    
    # check not superuser
    if tracker.user.is_superuser:
        return 
    
    if not tracker.is_first_tracker_today():
        return
    
    if not tracker.activity_exists():
        return
    
    if not tracker.completed:
        return
    
    type = 'activitycompleted'
    points = settings.OPPIA_POINTS['ACTIVITY_COMPLETED']
    if tracker.get_activity_type() == "media":
        description =  "Media played: " + tracker.get_activity_title()
        type = 'mediaplayed'
        points = settings.OPPIA_POINTS['MEDIA_PLAYED']
    else:
        description = "Activity completed: " + tracker.get_activity_title()    
       
    p = Points()
    p.points = points
    p.type = type
    p.description = description
    p.user = tracker.user
    p.course = tracker.course
    p.cohort = Cohort.student_member_now(tracker.course,tracker.user)
    p.save()
    
    # test if tracker submitted on time
    
    return
Esempio n. 19
0
def quizattempt_callback(sender, **kwargs):
    quiz_attempt = kwargs.get('instance')

    quiz = quiz_attempt.quiz

    # find out if this quiz is part of a course
    course = None
    digest = quiz_attempt.get_quiz_digest()
    if digest is not None:
        # TODO - what are chances of 2 courses having the exact same activity? and what to do if they do?
        acts = Activity.objects.filter(digest=digest)
        for a in acts:
            course = a.section.course

    if quiz_attempt.points is not None:
        p = Points()
        p.points = quiz_attempt.points
        p.type = 'quiz_attempt'
        p.user = quiz_attempt.user
        p.description = quiz_attempt.event
        p.course = course
        # Points are sent in the quiz attempt tracker, so don't save them twice
        # p.save()
        return

    # Check user doesn't own the quiz
    if quiz.owner == quiz_attempt.user:
        return

    if not apply_points(quiz_attempt.user):
        return

    # find out is user is part of the cohort for this course
    if course is not None and course.user == quiz_attempt.user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return
     
    if quiz_attempt.is_first_attempt():
        # If it's the first time they've attempted this quiz award points
        p = Points()
        p.points = OPPIA_DEFAULT_POINTS['QUIZ_FIRST_ATTEMPT']
        p.type = 'firstattempt'
        p.user = quiz_attempt.user
        p.description = "Bonus points for your first attempt at: " + quiz.title
        p.course = course
        p.save()

        # add percentage points for their first attempt
        if quiz_attempt.get_score_percent() > 0:
            p = Points()
            p.points = quiz_attempt.get_score_percent()
            p.type = 'firstattemptscore'
            p.description = "Score for first attempt at quiz: " + quiz.title
            p.user = quiz_attempt.user
            p.course = course
            p.save()

        # if you get 100% on first attempt get bonus of 50 points
        if quiz_attempt.get_score_percent() >= OPPIA_DEFAULT_POINTS['QUIZ_FIRST_ATTEMPT_THRESHOLD']:
            p = Points()
            p.points = OPPIA_DEFAULT_POINTS['QUIZ_FIRST_ATTEMPT_BONUS']
            p.type = 'firstattemptbonus'
            p.description = "Bonus points for getting 100% in first attempt at quiz: " + quiz.title
            p.user = quiz_attempt.user
            p.course = course
            p.save()

    elif quiz_attempt.is_first_attempt_today():
        # If it's the first time today they've attempted this quiz award 10 points
        p = Points()
        p.points = OPPIA_DEFAULT_POINTS['QUIZ_ATTEMPT']
        p.type = 'quizattempt'
        p.user = quiz_attempt.user
        p.description = "Quiz attempt at: " + quiz.title
        p.course = course
        p.save()

    return
Esempio n. 20
0
def quizattempt_callback(sender, **kwargs):
    quiz_attempt = kwargs.get('instance')

    quiz = quiz_attempt.quiz

    # find out if this quiz is part of a course
    course = None
    digest = quiz_attempt.get_quiz_digest()
    if digest is not None:
        # TODO - what are chances of 2 courses having the exact same activity? and what to do if they do?
        acts = Activity.objects.filter(digest=digest)
        for a in acts:
            course = a.section.course

    # Check user doesn't own the quiz
    if quiz.owner == quiz_attempt.user:
        return

    if not apply_points(quiz_attempt.user):
        return

    # find out is user is part of the cohort for this course
    if course is not None and course.user == quiz_attempt.user and settings.OPPIA_COURSE_OWNERS_EARN_POINTS is False:
        return

    if quiz_attempt.is_first_attempt():
        # If it's the first time they've attempted this quiz award points
        p = Points()
        p.points = DefaultGamificationEvent.objects.get(event='quiz_first_attempt').points
        p.type = 'firstattempt'
        p.user = quiz_attempt.user
        p.description = "Bonus points for your first attempt at: " + quiz.title
        p.course = course
        p.save()

        # add percentage points for their first attempt
        if quiz_attempt.get_score_percent() > 0:
            p = Points()
            p.points = quiz_attempt.get_score_percent()
            p.type = 'firstattemptscore'
            p.description = "Score for first attempt at quiz: " + quiz.title
            p.user = quiz_attempt.user
            p.course = course
            p.save()

        # if you get 100% on first attempt get bonus of 50 points
        if quiz_attempt.get_score_percent() >= DefaultGamificationEvent.objects.get(event='quiz_first_attempt_threshold').points:
            p = Points()
            p.points = DefaultGamificationEvent.objects.get(event='quiz_first_attempt_bonus').points
            p.type = 'firstattemptbonus'
            p.description = "Bonus points for getting 100% in first attempt at quiz: " + quiz.title
            p.user = quiz_attempt.user
            p.course = course
            p.save()

    elif quiz_attempt.is_first_attempt_today():
        # If it's the first time today they've attempted this quiz award 10 points
        p = Points()
        p.points = DefaultGamificationEvent.objects.get(event='quiz_attempt').points
        p.type = 'quizattempt'
        p.user = quiz_attempt.user
        p.description = "Quiz attempt at: " + quiz.title
        p.course = course
        p.save()

    return
Esempio n. 21
0
def quizattempt_callback(sender, **kwargs):
    quiz_attempt = kwargs.get('instance')
    
    # Check user doesn't own the quiz
    quiz = quiz_attempt.quiz
    if quiz.owner == quiz_attempt.user:
        return
    
    # give points to quiz owner
    if quiz_attempt.is_first_attempt_today() and not quiz.owner.is_superuser:
        p = Points()
        p.points = settings.OPPIA_POINTS['QUIZ_ATTEMPT_OWNER']
        p.user = quiz.owner
        p.type = 'userquizattempt'
        p.description = quiz_attempt.user.username + " attempted your quiz: " + quiz.title
        p.save() 
     
    # check not superuser
    if quiz_attempt.user.is_superuser:
        return 
    
    # find out if this quiz is part of a course
    course = None
    digest = quiz_attempt.get_quiz_digest()
    if digest is not None:
        # TODO - what are chances of 2 courses having the exact same activity? and what to do if they do?
        acts = Activity.objects.filter(digest=digest)
        for a in acts:
            course = a.section.course
        
    # find out is user is part of the cohort for this course
    cohort = None
    if course is not None:
        cohort = Cohort.student_member_now(course,quiz_attempt.user)
              
    if quiz_attempt.is_first_attempt():
        # If it's the first time they've attempted this quiz award points
        p = Points()
        p.points = settings.OPPIA_POINTS['QUIZ_FIRST_ATTEMPT']
        p.type = 'firstattempt'
        p.user = quiz_attempt.user
        p.description = "Bonus points for your first attempt at: " + quiz.title
        p.course = course
        p.cohort = cohort
        p.save()
    
        # add percentage points for their first attempt
        if quiz_attempt.get_score_percent() > 0:
            p = Points()
            p.points = quiz_attempt.get_score_percent()
            p.type = 'firstattemptscore'
            p.description = "Score for first attempt at quiz: " + quiz.title
            p.user = quiz_attempt.user
            p.course = course
            p.cohort = cohort
            p.save()
        
        # if you get 100% on first attempt get bonus of 50 points
        if quiz_attempt.get_score_percent() >= settings.OPPIA_POINTS['QUIZ_FIRST_ATTEMPT_THRESHOLD']:
            p = Points()
            p.points = settings.OPPIA_POINTS['QUIZ_FIRST_ATTEMPT_BONUS']
            p.type = 'firstattemptbonus'
            p.description = "Bonus points for getting 100% in first attempt at quiz: " + quiz.title
            p.user = quiz_attempt.user
            p.course = course
            p.cohort = cohort
            p.save()
            
    elif quiz_attempt.is_first_attempt_today():
        # If it's the first time today they've attempted this quiz award 10 points
        p = Points()
        p.points = settings.OPPIA_POINTS['QUIZ_ATTEMPT']
        p.type = 'quizattempt'
        p.user = quiz_attempt.user
        p.description = "Quiz attempt at: " + quiz.title
        p.course = course
        p.cohort = cohort
        p.save()
    
    return