Implemented the SM-2 algorithm for spaced repetition learning.
Project description
SuperMemo2
A package that implemented the spaced repetition algorithm SM-2 for you to quickly calculate your next review date for whatever you are learning.
📌 Note: The algorithm SM-2 doesn't equal to the computer implementation SuperMemo2. In fact, the 3 earliest implementations (SuperMemo1, SuperMemo2 and SuperMemo3) all used algorithm SM-2. I didn't notice that when I first published the package on PyPI, and I can't change the package name.
Table of Contents
- Motivation
- Installing and Supported Versions
- A Simple Example
- Features
- What is SM-2?
- Code Reference
- Testing
- Changelog
- Credits
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:
pip 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:
pip install -r requirements.txt
supermemo2 supports Python 3.8+
A Simple Example
from supermemo2 import first_review, review
# first review
# using quality=4 as an example, read below for what each value from 0 to 5 represents
# review date would default to datetime.utcnow() (UTC timezone) if not provided
first_review = first_review(4, "2024-06-22")
# review prints { "easiness": 2.36, "interval": 1, "repetitions": 1, "review_datetime": "2024-06-23 01:06:02"))
# second review
second_review = review(4, first_review["easiness"], first_review["interval"], first_review["repetitions"], first_review["review_datetime"])
# review prints similar to example above.
Features
📣 Calculates the review date of the task following the SM-2 algorithm.
📣 The first_review method to calculate the review date at ease without having to know the initial values.
What is SM-2?
🎥 If you are curious of what spaced repetition is, check this short video out.
📌 A longer but interactive article on spaced repetition learning.
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.
Code Reference
first_review( quality, review_datetime=None**)**
function that calcualtes the next review datetime for the your first review without having to know the initial values, and returns a dictionary containing the new values.
Parameters:
- quality (int) - the recall quality of the review.
- review_datetime (str or datetime.datetime) - optional parameter, the datetime in ISO format up to seconds in UTC timezone of the review.
Returns: dictionary containing values like quality, easiness, interval, repetitions and review_datetime.
Return Type: Dict
Usage:
from supermemo2 import first_review
# using default datetime.utcnow() if you just reviewed it
first_review(3)
# providing string date in Year-Month-Day format
first_review(3, "2024-06-22")
# providing date object date
from datetime import datetime
d = datetime(2024, 1, 1)
first_review(3, d)
review( quality, easiness, interval, repetitions, review_datetime=None )
Calcualtes the next review date based on previous values, and returns a dictionary containing the new values.
Parameters:
- quality (int) - the recall quality of the review.
- easiness (float) - the easiness determines the interval.
- interval (int) - the interval between the latest review date and the next review date.
- repetitions (int) - the count of consecutive reviews with quality larger than 2.
- review_datetime (str or datetime.datetime) - optional parameter, the datetime in ISO format up to seconds in UTC timezone of the review.
Returns: dictionary containing values like quality, easiness, interval, repetitions and review_datetime.
Return Type: Dict
Usage:
from supermemo2 import first_review, review
# using previous values from first_review call
r = first_review(3)
# using default datetime.utcnow() if you just reviewed it
review(3, r["easiness"], r["interval"], r["repetitions"])
# providing review_datetime from previous review
review(3, r["easiness"], r["interval"], r["repetitions"], r["review_datetime"])
# providing string review_datetime
review(3, r["easiness"], r["interval"], r["repetitions"], "2024-01-01")
# providing datetime object review_datetime
from datetime import datetime
d = datetime(2024, 1, 1)
review(3, r["easiness"], r["interval"], r["repetitions"], d)
Testing
Assuming you dowloaded the code and installed requirements.
Run the tests
pytest tests/
Check test coverages
pytest --cov
Check coverage on Codecov.
Changelog
3.0.0 (2024-06-22): Major changes/rebuild, Update recommended
- Rewrote the code to remove the class structure, simplfying the code and usability.
- Update to provide datetime instead of just date, more specific with when to review.
2.0.0 (2021-03-28): Major changes/rebuild, Update recommended
- Rebuilt and simplfied the package.
1.0.3 (2021-01-30): Minor bug fix, Update recommended
- Re-evaluate the default date argument to first_review() on each call.
1.0.2 (2021-01-18): Major and Minor bug fix, Update recommended
- Add required attrs package version to setup.py.
- Allow users to access SMTwo model.
- Fix E-Factor calculation when q < 3.
1.0.1 (2021-01-02): Fix tests, update README and add Github actions, Update not required
- Add missing assertions to test_api.py.
- Update README badges and fix format.
- Add Github actions to run tests against Python versions 3.6 to 3.9 in different OS, and upload coverage to Codecov.
1.0.0 (2021-01-01): Complete rebuild, Update recommended
- Build a new SMTwo class using the attrs package.
- Provide 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 SM-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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file supermemo2-3.0.0.tar.gz
.
File metadata
- Download URL: supermemo2-3.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 840c24490ebedd416b528e5cbd5dc98f3c2fdc371fcd1cb9008767fd80947d52 |
|
MD5 | 849831791a399f8ae74092cf2fc7dcb6 |
|
BLAKE2b-256 | 85533e680a301a6530b76a29aa244411a23c9a2878d8a0aae05bd56320fa905d |
File details
Details for the file supermemo2-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: supermemo2-3.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15d7d3e205e9642f088e689f37faf15a5991ec843bb6b9bf64f836a0863129c5 |
|
MD5 | 796bbb0fd1e77bf7ec74a279d8d90620 |
|
BLAKE2b-256 | e13043865a58190a343a735e0cb23b5f437bc4b6a37e264870ae584fa6334886 |