Anki/anki/groups.py
Damien Elmes bb79b0e17c add new 'groups' concept, refactor deletions
Users who want to study small subsections at one time (eg, "lesson 14") are
currently best served by creating lots of little decks. This is because:
- selective study is a bit cumbersome to switch between
- the graphs and statitics are for the entire deck
- selective study can be slow on mobile devices - when the list of cards to
  hide/show is big, or when there are many due cards, performance can suffer
- scheduling can only be configured per deck

Groups are intended to address the above problems. All cards start off in the
same group, but they can have their group changed. Unlike tags, cards can only
be a member of a single group at once time. This allows us to divide the deck
up into a non-overlapping set of cards, which will make things like showing
due counts for a single category considerably cheaper. The user interface
might want to show something like a deck browser for decks that have more than
one group, showing due counts and allowing people to study each group
individually, or to study all at once.

Instead of storing the scheduling config in the deck or the model, we move the
scheduling into a separate config table, and link that to the groups table.
That way a user can have multiple groups that all share the same scheduling
information if they want.

And deletion tracking is now in a single table.
2011-04-28 09:23:28 +09:00

54 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Copyright: Damien Elmes <anki@ichi2.net>
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
import simplejson, time
from anki.db import *
groupsTable = Table(
'groups', metadata,
Column('id', Integer, primary_key=True),
Column('modified', Float, nullable=False, default=time.time),
Column('name', UnicodeText, nullable=False),
Column('confId', Integer, nullable=False))
# maybe define a random cutoff at say +/-30% which controls exit interval
# variation - 30% of 1 day is 0.7 or 1.3 so always 1 day; 30% of 4 days is
# 2.8-5.2, so any time from 3-5 days is acceptable
defaultConf = {
'new': {
'delays': [0.5, 3, 10],
'ints': [1, 7, 4],
},
'lapse': {
'delays': [0.5, 3, 10],
'ints': [1, 7, 4],
'mult': 0
},
'initialFactor': 2.5,
'suspendLeeches': True,
'leechFails': 16,
}
groupConfigTable = Table(
'groupConfig', metadata,
Column('id', Integer, primary_key=True),
Column('modified', Float, nullable=False, default=time.time),
Column('name', UnicodeText, nullable=False),
Column('config', UnicodeText, nullable=False,
default=unicode(simplejson.dumps(defaultConf))))
class GroupConfig(object):
def __init__(self, name):
self.name = name
self.id = genID()
self.config = defaultConf
def save(self):
self._config = simplejson.dumps(self.config)
self.modified = time.time()
mapper(GroupConfig, groupConfigTable, properties={
'_config': groupConfigTable.c.config,
})