-
Notifications
You must be signed in to change notification settings - Fork 147
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
holocronweaver
wants to merge
15
commits into
kerrickstaley:main
Choose a base branch
from
holocronweaver:options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
28766a3
Add deck options via new OptionsGroup class.
holocronweaver eab7246
Add per-note options and a deck creation time.
holocronweaver 685d962
Ensure deck creation time is an integer.
holocronweaver ebacc3c
Fix a few typos and a minor interface inconsistency.
holocronweaver cd261da
Rename note.level -> stage to reduce ambiguity.
holocronweaver 6eb44fa
Minor coding style improvement.
holocronweaver 96606ec
Document deck and note options.
holocronweaver 0fa1870
Internally document note and deck options further.
holocronweaver a5a8d00
Fix a couple field name typos in apgk_col.
holocronweaver 4d0449a
Update tests to create OptionGroups.
holocronweaver 61b18b5
Add Card.status to allow suspending and burying cards.
holocronweaver bda7097
Move note options to CardOptions and try to match database field names.
holocronweaver 8286fbc
Merge 'upstream/master' into options.
holocronweaver 0a13191
Remove CardOptions and set options directly on Card or via Note.
holocronweaver d9fd190
Avoid relative commits in __init__.py
holocronweaver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add per-note options and a deck creation time.
* A correct deck creation time is necessary since card due dates are defined relative to it.
- Loading branch information
commit eab7246ee80a67512067a0cda73433609d290514
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from cached_property import cached_property | ||
from copy import copy | ||
import json | ||
from datetime import datetime | ||
import hashlib | ||
import json | ||
import os | ||
import pystache | ||
import sqlite3 | ||
|
@@ -155,25 +156,30 @@ class Card: | |
def __init__(self, ord_): | ||
self.ord = ord_ | ||
|
||
def write_to_db(self, cursor, now_ts, deck_id, note_id): | ||
self.interval = 0 | ||
|
||
def write_to_db(self, cursor, now_ts, deck_id, note_id, | ||
level, due, interval, ease, reps_til_grad): | ||
cursor.execute('INSERT INTO cards VALUES(null,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);', ( | ||
note_id, # nid | ||
deck_id, # did | ||
self.ord, # ord | ||
now_ts, # mod | ||
-1, # usn | ||
0, # type (=0 for non-Cloze) | ||
0, # queue | ||
0, # due | ||
0, # ivl | ||
0, # factor | ||
0, # reps | ||
0, # lapses | ||
0, # left | ||
0, # odue | ||
0, # odid | ||
0, # flags | ||
"", # data | ||
note_id, # nid - note ID | ||
deck_id, # did - deck ID | ||
self.ord, # ord - which card template it corresponds | ||
now_ts, # mod - modification time as epoch seconds | ||
-1, # usn - value of -1 indicates need to push to server | ||
level, # type - 0=new, 1=learning, 2=review | ||
level, # queue - same as type unless buried | ||
due, # due - new: unused | ||
# learning: due time as integer seconds since epoch | ||
# review: integer days relative to deck creation | ||
interval, # ivl - positive days, negative seconds | ||
ease, # 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" | ||
reps_til_grad, # left - reps left until graduation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto here. This should be called |
||
0, # odue - only used when card is in filtered deck | ||
0, # odid - only used when card is in filtered deck | ||
0, # flags - currently unused | ||
"", # data - currently unused | ||
)) | ||
|
||
|
||
|
@@ -189,6 +195,12 @@ def __init__(self, model=None, fields=None, sort_field=None, tags=None, guid=Non | |
# guid was defined as a property | ||
pass | ||
|
||
self.level = 0 | ||
self.due = 0 | ||
self.interval = 0 | ||
self.ease = 1000 | ||
self.reps_til_grad = 0 | ||
|
||
@property | ||
def sort_field(self): | ||
return self._sort_field or self.fields[0] | ||
|
@@ -234,7 +246,9 @@ def write_to_db(self, cursor, now_ts, deck_id): | |
|
||
note_id = cursor.lastrowid | ||
for card in self.cards: | ||
card.write_to_db(cursor, now_ts, deck_id, note_id) | ||
card.write_to_db(cursor, now_ts, deck_id, note_id, | ||
self.level, self.due, self.interval, | ||
self.ease, self.reps_til_grad) | ||
|
||
def _format_fields(self): | ||
return '\x1f'.join(self.fields) | ||
|
@@ -249,7 +263,7 @@ def __init__(self, options_id=1, name='Default'): | |
self.options_group_name = name | ||
# General. | ||
self.max_time_per_answer = 60 | ||
self.show_timer = False # 'false' | ||
self.show_timer = False | ||
self.autoplay_audio = True | ||
self.replay_audio_for_answer = True | ||
# New. | ||
|
@@ -259,7 +273,7 @@ def __init__(self, options_id=1, name='Default'): | |
self.graduating_interval = 1 | ||
self.easy_interval = 4 | ||
self.starting_ease = 2500 | ||
self.new_bury_related_cards = True # 'true' | ||
self.new_bury_related_cards = True | ||
# Reviews. | ||
self.max_reviews_per_day = 100 | ||
self.easy_bonus = 1.3 | ||
|
@@ -302,6 +316,7 @@ def __init__(self, deck_id=None, name=None, options=None): | |
self.models = {} # map of model id to model | ||
self.description = '' | ||
self.options = options | ||
self.creation_time = datetime.now() | ||
|
||
def add_note(self, note): | ||
self.notes.append(note) | ||
|
@@ -317,6 +332,8 @@ def write_to_db(self, cursor, now_ts): | |
params = self.options._format_fields() | ||
|
||
params.update({ | ||
'creation_time': self.creation_time.timestamp(), | ||
'modification_time': self.creation_time.timestamp() * 1000, | ||
'name': self.name, | ||
'deck_id': self.deck_id, | ||
'models': json.dumps(models), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all these properties should be attributes of the
Card
object, not theNote
object, since you can set them per-card.So the user would do something like this:
If you have a use case for setting attributes on all cards, you can add a helper function like this:
Note: you can skip adding
ease
,ivl
, etc as keyword arguments toCard.__init__
. UnlikeNote
andDeck
, the user generally doesn't directly initializeCard
instances; instead, they're implicitly initialized when the user creates theNote
. So it doesn't make sense to setCard
attributes via keyword arguments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okydoke! I actually planned for and forgot to do this, heh.