Skip to content

Commit

Permalink
Remove CardOptions and set options directly on Card or via Note.
Browse files Browse the repository at this point in the history
  • Loading branch information
holocronweaver committed Sep 2, 2017
1 parent 8286fbc commit d41d693
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions genanki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ def to_json(self, now_ts, deck_id):
}


class CardOptions:
def __init__(self, stage=0, status=0, due=0, interval=0,
class Card:
def __init__(self, ord,
stage=0, status=0, due=0, interval=0,
ease_factor=0, reps_left_til_grad=0):
self.ord = ord

## Options ##

"""SRS learning stage.
0 = new, 1 = learning, 2 = review."""
self.type = stage
Expand Down Expand Up @@ -201,12 +206,6 @@ def reps_left_til_grad(self):
def reps_left_til_grad(self, value):
self.left = value


class Card:
def __init__(self, ord, options=None):
self.ord = ord
self.options = options or CardOptions()

def write_to_db(self, cursor, now_ts, deck_id, note_id):
if self.options.status:
queue = -self.options.status
Expand All @@ -219,17 +218,17 @@ def write_to_db(self, cursor, now_ts, deck_id, note_id):
self.ord, # ord - which card template it corresponds to
now_ts, # mod - modification time as seconds since Unix epoch
-1, # usn - value of -1 indicates need to push to server
self.options.type, # type - 0=new, 1=learning, 2=review
self.type, # type - 0=new, 1=learning, 2=review
queue, # queue - same as type, but
# -1=suspended, -2=user buried, -3=sched buried
self.options.due, # due - new: unused
# learning: due time as integer seconds since Unix epoch
# review: integer days relative to deck creation
self.options.ivl, # ivl - positive days, negative seconds
self.options.factor, # factor - integer ease factor used by SRS, 2500 = 250%
self.due, # due - new: unused
# learning: due time as integer seconds since Unix epoch
# review: integer days relative to deck creation
self.ivl, # ivl - positive days, negative seconds
self.factor, # factor - integer ease factor used by SRS, 2500 = 250%
0, # reps - number of reviews
0, # lapses - # times card went from "answered correctly" to "answered incorrectly"
self.options.left, # left - reps left until graduation
self.left, # left - reps left until graduation
0, # odue - only used when card is in filtered deck
0, # odid - only used when card is in filtered deck
0, # flags - currently unused
Expand Down Expand Up @@ -285,10 +284,12 @@ def set_card_options(self, options):
"""
try:
for i, card in enumerate(self.cards):
card.options = options[i]
for option, value in options[i]:
setattr(card, option, value)
except TypeError:
for card in self.cards:
card.options = options
for option, value in options:
setattr(card, option, value)

def write_to_db(self, cursor, now_ts, deck_id):
cursor.execute('INSERT INTO notes VALUES(null,?,?,?,?,?,?,?,?,?,?);', (
Expand Down

0 comments on commit d41d693

Please sign in to comment.