From 7f5a5d3eb5f0bcf8be5258627a5b698d9652211d Mon Sep 17 00:00:00 2001 From: Joshua Hamilton Date: Sun, 7 Jul 2024 20:56:01 -0500 Subject: [PATCH] add default argument to repeat function (#38) * add default argument to repeat function * get rid of weird blue underlines between pairs of shields --- README.md | 28 ++++++++++------------------ pyproject.toml | 2 +- src/fsrs/__init__.py | 2 +- src/fsrs/fsrs.py | 5 ++++- tests/test_fsrs.py | 19 +++++++++++++++++++ 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 25a5732..d3dadc5 100644 --- a/README.md +++ b/README.md @@ -6,16 +6,10 @@ 🧠🔄 Build your own Spaced Repetition System in Python 🧠🔄
-
- - - - - - - - - +
+ + +

@@ -38,7 +32,6 @@ Import and initialize the FSRS scheduler ```python from fsrs import * -from datetime import datetime, UTC, timezone f = FSRS() ``` @@ -49,12 +42,9 @@ Create a new Card object card_object = Card() ``` -Review the card at a specified time +Review the card ```python -# all py-fsrs cards must be UTC and timezone-aware -review_time = datetime.now(UTC) - -scheduling_cards = f.repeat(card_object, review_time) +scheduling_cards = f.repeat(card_object) ``` Choose a rating and update the card object @@ -74,10 +64,12 @@ card_object = scheduling_cards[card_rating].card See when the card is due next ```python +from datetime import datetime, timezone + due = card_object.due # how much time between when the card is due and now -time_delta = due - datetime.now(UTC) +time_delta = due - datetime.now(timezone.utc) print(f"Card due: at {repr(due)}") print(f"Card due in {time_delta.seconds} seconds") @@ -118,4 +110,4 @@ scheduled_days = card_object.scheduled_days ## License -Distributed under the MIT License. See `LICENSE` for more information. \ No newline at end of file +Distributed under the MIT License. See `LICENSE` for more information. diff --git a/pyproject.toml b/pyproject.toml index 1d513b5..454d48e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "fsrs" -version = "2.1.1" +version = "2.2.0" description = "Free Spaced Repetition Scheduler" readme = "README.md" authors = [{ name = "Jarrett Ye", email = "jarrett.ye@outlook.com" }] diff --git a/src/fsrs/__init__.py b/src/fsrs/__init__.py index dafda40..eb0fedf 100644 --- a/src/fsrs/__init__.py +++ b/src/fsrs/__init__.py @@ -1,4 +1,4 @@ -__version__ = "2.1.0" +__version__ = "2.2.0" from .fsrs import FSRS, Card diff --git a/src/fsrs/fsrs.py b/src/fsrs/fsrs.py index c1c0f0a..cf4d721 100644 --- a/src/fsrs/fsrs.py +++ b/src/fsrs/fsrs.py @@ -13,7 +13,10 @@ def __init__(self) -> None: self.DECAY = -0.5 self.FACTOR = 0.9 ** (1 / self.DECAY) - 1 - def repeat(self, card: Card, now: datetime) -> dict[int, SchedulingInfo]: + def repeat(self, card: Card, now: datetime = None) -> dict[int, SchedulingInfo]: + + if now is None: + now = datetime.now(timezone.utc) if (now.tzinfo is None) or (now.tzinfo != timezone.utc): raise ValueError("datetime must be timezone-aware and set to UTC") diff --git a/tests/test_fsrs.py b/tests/test_fsrs.py index 07d3491..024ba7a 100644 --- a/tests/test_fsrs.py +++ b/tests/test_fsrs.py @@ -72,6 +72,25 @@ def test_repeat(self): print(ivl_history) assert ivl_history == [0, 5, 16, 43, 106, 236, 0, 0, 12, 25, 47, 85, 147] + def test_repeat_default_arg(self): + + f = FSRS() + + card_object = Card() + + # repeat time is not specified + scheduling_cards = f.repeat(card_object) + + card_rating = Rating.Good + + card_object = scheduling_cards[card_rating].card + + due = card_object.due + + time_delta = due - datetime.now(timezone.utc) + + assert time_delta.seconds > 500 # due in approx. 8-10 minutes + def test_datetime(self): f = FSRS()