Module sbx.core

Core Study Box classes

Example Scripts

Create a file

from sbx.core.card import Card

# Create a card with given path (doesn't need to exist)
card = Card("jit.md")
card.front = "What does JIT stands for in JIT compiler?"
card.back = "Just in time"
card.save()
  • This will create a card file jit.md

Export a card to .json

import json
from sbx.core.card import Card

# This card need to exist
card = Card("./tests/box/test-card-2.md")

data = {"front": card.front, "back": card.back, "meta": card.meta.to_dict()}
# Accessing '.front' will automatically load the full card details from file
print(json.dumps(data, indent="  "))
  • This prints
{
  "front": "How do I display `\"World World\"` in Python?",
  "back": "```python\nprint(\"World World\")\n```",
  "meta": {
    "a": 4,
    "b": 9.744000000000002,
    "c": 1.4000000000000001,
    "next": 1592667591,
    "last": 1591825710,
    "pastq": "2104335",
    "reps": 7,
    "algo": "sm2",
    "sbx": "v1"
  }
}

Get a list of cards

import pprint
from sbx.core.study import CardStack

cards = CardStack("./tests/box", recursive=True, include_unscheduled=True)
pprint.pprint([x.path for x in cards.iter()])
  • This prints
['tests/box/test-card-3.md',
 'tests/box/test-card-zero.md',
 'tests/box/test-card-2.md',
 'tests/box/test-card.md',
 'tests/box/test-card-leech-zero.md',
 'tests/box/test-card-ok.md',
 'tests/box/test-card-leech.md']

SBX File Format

  • Study box uses markdown files with HTML comments.

Structure

1|<!-- | {"a": 0, "b": 1, "c": 1.3, "reps": 7, "last": 1591825714, 
    "next": 1591912114, "pastq": "2105302", "algo": "sm2", "sbx": "v1"} | -->
2|<!-- [[FRONT]] -->
3|# Front of the card goes here
4|
5|<!-- [[BACK]] -->
6|* This is the back of the card
7|
  • Files without headers are ignored. So it's safer to have files such as README.md.
  • In every card file first line need to contain an HTML comment with an embedded JSON content.
    • In addition to this JSON should be surrounded by PIPEs. (PIPE is not expected to be present in JSON strings)
  • Why are all headers in first line?
    • Only need to load first line to see if it's scheduled & other meta data.
    • We can load rest of the file if required.

Registers

  • JSON header will have following registers.
{
# ----- Optional ----
"a"           # number
"b"           # number
"c"           # number
"d"           # number
"e"           # number
"f"           # bool
"g"           # bool
"h"           # string
# ---- Required ----
"reps"        # number
"last"        # number
"next"        # number
"pastq"       # string
"algo": "sm2" # string
"sbx": "v1",  # string
}
  • Why registers?
    • Support different algorithms using a same structure.
    • Only used for optional registers that are used by an algorithm.
    • Algorithm oblivious create & reset commands.
  • "sbx" key should be present and it should contain version of studybox which created card.
    • Future versions of studybox should be able to convert older formats. (Maybe with some issues such as resetting card)
  • "algo" key should contain algorithm used to store information.
    • If a different algorithm is later used it may reset the data or use them if compatible.
  • "pastq" key contains past qualities (will only keep 20).

Body

  • Body will immediately follow the header.
  • [[FRONT]] denotes front of the card. (This goes on until [[BACK]] is encountered)
  • [[BACK]] this denotes back of the card. (This goes until end of the file)
  • You should have an empty newline after both FRONT and BACK sections.
Expand source code
"""
Core Study Box classes


.. include:: ../../docs/EXAMPLES.md
.. include:: ../../docs/FILE_FORMAT.md
"""

Sub-modules

sbx.core.card

Contains important Card, CardMeta, CardAlgo classes

sbx.core.study

Contains classes used for selecting cards to study

sbx.core.utility

Utilities used in the code