~kevang/mnemosyne-proj/grade-shortcuts-improvements

« back to all changes in this revision

Viewing changes to mnemosyne/mnemosyne/libmnemosyne/card.py

  • Committer: pbienst
  • Date: 2008-08-04 16:13:00 UTC
  • Revision ID: svn-v3-trunk0:e5e6b78b-db40-0410-9517-b98c64f8d2c1:trunk:497
Progress dump.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
import md5, time
8
8
 
9
 
from mnemosyne.libmnemosyne.plugin_manager import get_database, get_scheduler
 
9
from mnemosyne.libmnemosyne.plugin_manager import *
10
10
 
11
11
 
12
12
 
14
14
#
15
15
# Card
16
16
#
17
 
# Note that we store a card_type_id, as opposed to a card_type, because
18
 
# otherwise we can't use pickled databases, as the card_types themselves are
19
 
# not stored in the database. It is also closer the SQL implementation.
20
 
#
21
 
# 'fact_view' indicate different cards generated from the same fact data,
22
 
# like reverse cards. TODO: do we need a mapping from this integer to a
23
 
# description?
24
 
#
25
 
# For UI simplicity reasons, the user is not allowed to deleted one of a set
26
 
# of related cards, only to deactivate them. This is a second, orthogonal
27
 
# selection mechanism to see if cards are active, together with not being
28
 
# in a deactivated category.
 
17
#   Essentially the coming together of a Fact and a FactView.
29
18
#
30
19
##############################################################################
31
20
 
37
26
    #
38
27
    ##########################################################################
39
28
            
40
 
    def __init__(self, grade, fact, fact_view, cat_names, id=None):
41
 
 
42
 
        self.fact       = fact
43
 
        self.fact_view  = fact_view
44
 
        self.active     = True
45
 
 
46
 
        db = get_database()
47
 
 
48
 
        self.cat = []
49
 
        for cat_name in cat_names:
50
 
            self.cat.append(db.get_or_create_category_with_name(cat_name))
 
29
    def __init__(self, grade, fact, fact_view, id=None):
 
30
 
 
31
        self.fact      = fact
 
32
        self.fact_view = fact_view
51
33
        
52
34
        self.reset_learning_data() # TODO: see where this is used and merge.
53
35
 
54
36
        # The initial grading is seen as the first repetition.
 
37
 
 
38
        # TODO: check if the way we do this now still treats imports
 
39
        # on equal footing.
55
40
        
56
41
        self.grade = grade
57
42
        self.acq_reps = 1
59
44
 
60
45
        self.last_rep = start_date.days_since_start()
61
46
 
62
 
        self.easiness = db.average_easiness()
 
47
        self.easiness = get_database.average_easiness()
63
48
 
64
49
        if id is not None:
65
50
            self.new_id()
149
134
 
150
135
    ##########################################################################
151
136
    #
 
137
    # is_active
 
138
    #
 
139
    #   TODO: benchmark
 
140
    #
 
141
    ##########################################################################
 
142
 
 
143
    def is_active(self):
 
144
        
 
145
        for c in self.cat:
 
146
            if c.active == False:
 
147
                return False
 
148
 
 
149
        for view in get_card_type_by_id(self.fact.card_type_id).fact_views:
 
150
            if view.active == False:
 
151
                return False
 
152
            
 
153
        return True
 
154
 
 
155
    
 
156
 
 
157
    ##########################################################################
 
158
    #
152
159
    # interval
153
160
    #
154
161
    ##########################################################################
156
163
    def interval(self):
157
164
        return self.next_rep - self.last_rep
158
165
    
159
 
        
 
166
 
 
167
 
 
168
# TODO: see which of these we still need and if they could be moved to
 
169
# database
 
170
 
 
171
 
160
172
    ##########################################################################
161
173
    #
162
174
    # sort_key: needed?
177
189
    def sort_key_newest(self):
178
190
        return self.acq_reps + self.ret_reps
179
191
 
180
 
 
181
 
 
182
 
    ##########################################################################
183
 
    #
184
 
    # is_active
185
 
    #
186
 
    ##########################################################################
187
 
 
188
 
    def is_active(self):
189
 
 
190
 
        if self.active == False:
191
 
            return False
192
 
        
193
 
        for c in self.cat:
194
 
            if c.active == False:
195
 
                return False
196
 
            for fact_view in c.inactive_fact_views[self.fact.card_type_id]:
197
 
                if self.fact_view == fact_viev:
198
 
                    return False
199
 
            
200
 
        return True
201
 
    
202
 
 
203
 
# TODO: see which of these we still need and if they could be moved to
204
 
# database
205
 
 
206
192
    
207
193
    
208
194
    ##########################################################################
214
200
    def is_new(self):
215
201
        return (self.acq_reps == 0) and (self.ret_reps == 0)
216
202
    
217
 
    
218
 
    
219
 
    ##########################################################################
220
 
    #
221
 
    # is_overdue
222
 
    #
223
 
    ##########################################################################
224
 
    
225
 
    def is_overdue(self):
226
 
        return (self.grade >= 2) and (self.is_in_active_category()) and \
227
 
               (days_since_start > self.next_rep)
228
203
 
229
204
    ##########################################################################
230
205
    #
244
219
    def days_until_next_rep(self):
245
220
        return self.next_rep - days_since_start
246
221
    
247
 
 
248
 
    ##########################################################################
249
 
    #
250
 
    # qualifies_for_learn_ahead
251
 
    #
252
 
    ##########################################################################
253
 
    
254
 
    def qualifies_for_learn_ahead(self):
255
 
        return (self.grade >= 2) and (self.is_in_active_category()) and \
256
 
               (get_days_since_start() < self.next_rep) 
257
222
        
258
223
    ##########################################################################
259
224
    #