Skip to main content

Implemented the SuperMemo-2/SM-2 algorithm for spaced repetition learning.

Project description

SuperMemo2

Python Version Download Coverage

A package that implemented the spaced repetition algorithm SuperMemo-2/SM-2 for you to quickly calculate your next review date for whatever you are learning.

:package: PyPI page

Table of Contents


Motivation

The goal was to have an efficient way to calculate the next review date for studying/learning. Removes the burden of remembering the algorithm, equations, and math from the users.


Installation and Supported Versions

Package Install

Install and upate the package using pip:

pip3 install -U supermemo2


To Play Around with the Code

Download the code:

git clone https://github.com/alankan886/SuperMemo2.git

Install dependencies to run the code:

pip3 install -r requirements.txt

supermemo2 supports Python 3.7+.


A Simple Example

We start with a recall quality of 3, and the review date defaults to today (let's pretend it's 2021-01-01).

Using the current values from the first review can help us calculate for the second review.

Grab the current values from the first review, and update the recall quality. Then calculate the next review date.

>>> from supermemo2 import first_review
>>> smtwo = first_review(3)
>>> print(smtwo.review_date)
2021-01-02
>>> record = smtwo.as_dict(curr=True)
>>> record["quality"] = 5
>>> smtwo.calc(**record)
>>> print(smtwo.review_date)
2021-01-08


Features

:mega: Calculates the next review date of the task following the SuperMemo-2/SM-2 algorithm.
:mega: The first_review method to create a new instance at ease without having to know the initial values.
:mega: The modify method to modify existing instance values that recalculates the new values.
:mega: The json and dict methods to export the instance values and to help calculate the next review date.


Potential Features

  • Allow users to pass the review date as a string in many formats.
  • Provide a modified option to configure the intervals for repetitions 1 and 2. And an option to reduce quality responses to 4, since 0 to 2 doesn't do much.


What is SuperMemo-2?

:movie_camera: If you are curious of what spaced repetition is, check this short video out.

:pushpin: A longer but interactive article on spaced repetition learning.

:paperclip: The SuperMemo-2 Algorithm

What are the "values"?

The values are the:

  • Quality: The quality of recalling the answer from a scale of 0 to 5.
    • 5: perfect response.
    • 4: correct response after a hesitation.
    • 3: correct response recalled with serious difficulty.
    • 2: incorrect response; where the correct one seemed easy to recall.
    • 1: incorrect response; the correct one remembered.
    • 0: complete blackout.
  • Easiness: The easiness factor, a multipler that affects the size of the interval, determine by the quality of the recall.
  • Interval: The gap/space between your next review.
  • Repetitions: The count of correct response (quality >= 3) you have in a row.

:pencil2: quality from 0 to 2 doesn't have much impact; it doesn't affect the easiness. If you are building a program on top of this package, you may group them as one response. So instead of 6 responses, you have 4 (5, 4, 3, and incorrect response).


API Reference

Main Interface

supermemo2.first_review(quality, review_date=datetime.date.today())

      Calcualtes next review date without having to know the initial values,       and returns an SMTwo object with new values.

      Parameters:

  • quality(int) - the quality of the response/recall from a scale of 0 to 5.
  • review_date (Optional[datetime.date]) - the last review date.

      Returns: SMTwo object

      Return Type: supermemo2.SMTwo

      Usage:

>>> from supermemo2 import first_review
>>> from datetime import date
>>> smtwo = first_review(3, date(2021, 1, 1))
>>> print(smtwo.review_date)
2021-01-02

supermemo2.modify(instance, quality=None, easiness=None, interval=None, repetitions=None, review_date=None)

      Modifies previously inserted values.

      Parameters:

  • instance (SMTwo) - the SMTwo instance to modify.
  • quality (Optional[int]) - the quality value to replace the previous quality value.
  • easiness (Optional[float])- the easiness value to replace the previous easiness value.
  • interval (Optional[int]) - the interval value to replace the previous interval value.
  • repetitions (Optional[int]) - the repetitions value to replace the previous reptitions value.
  • review_date (Optional[datetime.date]) - the review date to replace the previous review date.

      Returns: None

      Return Type: None

      Usage:

>>> from supermemo2 import first_review, modify
>>> smtwo = first_review(3)
>>> print(smtwo.quality)
3
>>> modify(smtwo, quality=5)
>>> print(smtwo.quality)
5

Exceptions

exception supermemo2.exceptions.CalcNotCalledYet       Other methods are called before the values are calculated.

Lower-Level Classes

class supermemo2.SMTwo()

      Generates all the instances and contains the tools.

      I would not recommend directly generating an instance from this class.

calc(quality, easiness, interval, repetitions, review_date)

      Calculates the values. For the first review, the initial/previous values       would be 2.5 for easiness, 1 for interval and 1 for repetitions.

      Parameters:

  • quality (Optional[int]) - the quality value received from the last calculation.
  • easiness (Optional[float])- the easiness value received from the last calculation.
  • interval (Optional[int]) - the interval value received from the last calculation.
  • repetitions (Optional[int]) - the repetitions value received from the last calculation.
  • review_date (Optional[datetime.date]) - the review date received from the last calculation.

      Returns: None

      Return Type None

      Usage:

>>> from supermemo2.models import SMTwo
>>> from datetime import date
>>> smtwo = SMTwo()
>>> smtwo.calc(3, 2.5, 1, 1, date(2021, 1, 1))
>>> print(smtwo.review_date)
2021-01-02

json(prev=None, curr=None)

      Returns a string of the values in JSON format.

      Parameters:

  • prev (Optional[bool]) - If true, export only previous values.
  • curr (Optional[bool]) - If true, export only current values.

      Returns: String in JSON format

      Return Type String

      Usage:

>>> from supermemo2 import first_visit
>>> from datetime import date
>>> smtwo = first_visit(3, date(2021, 1, 1))
>>> print(smtwo.json())
'{"quality": 3, "prev_easiness": 2.5, "prev_interval": 1, "prev_repetitions": 1, "prev_review_date": datetime.date(2021, 1, 1),"easiness": 2.36, "interval": 2, "repetitions": 1, "review_date": datetime.date(2021, 1, 2)}'

dict(prev=None, curr=None)

      Returns a the values in dictionary format.

      Parameters:

  • prev (Optional[bool]) - If true, export only previous values.
  • curr (Optional[bool]) - If true, export only current values.

      Returns: Dictionary

      Return Type Dict

      Usage:

>>> from supermemo2 import first_visit
>>> from datetime import date
>>> smtwo = first_visit(3, date(2021, 1, 1))
>>> print(smtwo.dict())
'{"quality": 3, "prev_easiness": 2.5, "prev_interval": 1, "prev_repetitions": 1, "prev_review_date": datetime.date(2021, 1, 1),"easiness": 2.36, "interval": 2, "repetitions": 1, "review_date": datetime.date(2021, 1, 2)}'

class supermemo2.SMTwo.Prev(easiness, interval, repetitions, review_date)

      Stores the previous values.

      Parameters:

  • easiness (float)- the previous easiness value.
  • interval (int) - the previous interval value.
  • repetitions (int) - the previous repetitions value.
  • review_date (datetime.date) - the previous review date.

Testing

Assuming you dowloaded the code and installed requirements.

Run the tests

pytest tests

Check test coverages

pytest --cov=supermemo2
---------- coverage: platform darwin, python 3.7.6-final-0 -----------
Name                       Stmts   Miss  Cover
----------------------------------------------
supermemo2/__init__.py         1      0   100%
supermemo2/api.py             27      0   100%
supermemo2/exceptions.py       4      0   100%
supermemo2/model.py           94      0   100%
supermemo2/util.py             3      0   100%
----------------------------------------------
TOTAL                        129      0   100%

Changelog

1.0.0 2020-12-31 Complete rebuild, Update recommended

  • Build new SMTwo class using the attrs package.
  • Provie API methods to quickly access the SMTwo class.
  • Develop 100% coverage integration and unit tests in a TDD manner.
  • Write new documentation.

0.1.0 2020-07-14 Add tests, Update not required

  • Add passing unit tests with a coverage of 100%.

0.0.4 2020-07-10 Minor bug fix, Update recommended

  • Fix interval calculation error when q < 3.

0.0.3 2020-07-06 Documentation Update, Update not required

  • Add new section about SuperMemo-2 in documentation, and fix some formats in README.

0.0.2 2020-07-05 Refactor feature, Update recommended

  • Refactor the supermemo2 algorithm code into a simpler structure, and remove unnecessary methods in the class.

0.0.1 2020-07-02 Feature release

  • Initial Release

Credits

  1. attrs
  2. pytest
  3. The SuperMemo-2 Algorithm

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supermemo2-1.0.0.tar.gz (8.3 kB view details)

Uploaded Source

File details

Details for the file supermemo2-1.0.0.tar.gz.

File metadata

  • Download URL: supermemo2-1.0.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.7.6

File hashes

Hashes for supermemo2-1.0.0.tar.gz
Algorithm Hash digest
SHA256 90e1dfc0a43d853d5390e92490f9d0a4e79c87901163a3d9d800a935d7ed1527
MD5 8d93a303c758b94c5d2562781399acaf
BLAKE2b-256 928192336746c86c06277fb9189f1a60ebec6129b2e0577cb6c29783abcb97fa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page