My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from badges import Badge, BadgeContextType, BadgeCategory
from exercise_badges import ExerciseBadge
import logging

# All badges awarded for just barely missing streaks even though most questions are
# being answered correctly inherit from UnfinishedStreakProblemBadge
class UnfinishedStreakProblemBadge(ExerciseBadge):

def is_satisfied_by(self, *args, **kwargs):
user_data = kwargs.get("user_data", None)
user_exercise = kwargs.get("user_exercise", None)
action_cache = kwargs.get("action_cache", None)

if user_data is None or user_exercise is None or action_cache is None:
return False

# Make sure they've done the required minimum of problems in this exercise
if user_exercise.total_done < self.problems_required:
return False

# Make sure they haven't yet reached proficiency
if user_data.is_proficient_at(user_exercise.exercise):
return False

c_logs = len(action_cache.problem_logs)

# We need a history of at least 10 problem_logs in the action cache
if c_logs < 10:
return False

# Make sure the last problem is from this exercise and that they got it right
last_problem_log = action_cache.get_problem_log(c_logs - 1)
if (last_problem_log.exercise != user_exercise.exercise or not last_problem_log.correct):
return False

c_correct = 0
c_total = 0
c_logs_examined = min(50, c_logs)

# Look through the last 50 problems. If they've done at least 10 in the exercise
# and gotten at least 75% correct but haven't managed to put together a streak, give 'em the badge.
for i in range(c_logs_examined):

problem_log = action_cache.get_problem_log(c_logs - i - 1)

if problem_log.exercise == user_exercise.exercise:
c_total += 1
if problem_log.correct:
c_correct += 1

# Make sure they've done at least 10 problems in this exercise out of their last 50
if c_total < 10:
return False

# Make sure they've gotten at least 75% of their recent answers correct
if (float(c_correct) / float(c_total)) < 0.75:
return False

return True

def extended_description(self):
return "Answer more than %d problems mostly correctly in an exercise before becoming proficient" % self.problems_required

class SoCloseBadge(UnfinishedStreakProblemBadge):

def __init__(self):
UnfinishedStreakProblemBadge.__init__(self)
self.problems_required = 30
self.description = "Perseverance"
self.badge_category = BadgeCategory.BRONZE
self.points = 0

class KeepFightingBadge(UnfinishedStreakProblemBadge):

def __init__(self):
UnfinishedStreakProblemBadge.__init__(self)
self.problems_required = 40
self.description = "Steadfastness"
self.badge_category = BadgeCategory.SILVER
self.points = 0

class UndeterrableBadge(UnfinishedStreakProblemBadge):

def __init__(self):
UnfinishedStreakProblemBadge.__init__(self)
self.problems_required = 50
self.description = "Tenacity"
self.badge_category = BadgeCategory.SILVER
self.points = 0

Change log

r1054 by kamens on Jan 31, 2011   Diff
Don't differentiate b/w explicit
proficiency and assumed proficiency in
badge behavior until we clarify it in the
UI.
Go to: 
Project members, sign in to write a code review

Older revisions

r986 by kamens on Jan 11, 2011   Diff
Hand out perseverance badges after a
correct problem is finished, not after
a wrong problem is missed.
r903 by kamens on Dec 23, 2010   Diff
More badge ordering fixes -- keep
points badges at the front, but sorted
naturally. Also don't give points for
the recovery badges -- only for badges
that encourage movement through the
...
r884 by kamens on Dec 22, 2010   Diff
Unfinished streak badges were crashing
w/out anything in the action cache
All revisions of this file

File info

Size: 3316 bytes, 90 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting