Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deck and note options. #12

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove CardOptions and set options directly on Card or via Note.
  • Loading branch information
holocronweaver committed Sep 2, 2017
commit 0a13191f57ac2b64ce48b0207b32b8618585354a
47 changes: 24 additions & 23 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 ##
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per above comment, please move this out of the Note class and into the Card class.


"""SRS learning stage.
0 = new, 1 = learning, 2 = review."""
self.type = stage
Expand Down Expand Up @@ -201,35 +206,29 @@ 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
if self.status:
queue = -self.status
else:
queue = self.options.type
queue = self.type

cursor.execute('INSERT INTO cards VALUES(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);', (
note_id, # nid - note ID
deck_id, # did - deck 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 @@ -279,16 +278,18 @@ def guid(self, val):
self._guid = val

def set_card_options(self, options):
"""If `options` is a single CardOptions, apply it to all cards. If
`options` is a list of CardOptions, apply each CardOptions to the
"""If `options` is a single dict of field-value pairs, apply it to all
cards. If `options` is a list of dicts, apply each dict to the
card of the same index.
"""
try:
for i, card in enumerate(self.cards):
card.options = options[i]
except TypeError:
for option, value in options[i].items():
setattr(card, option, value)
except KeyError:
for card in self.cards:
card.options = options
for option, value in options.items():
setattr(card, option, value)

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