Skip to content

Commit

Permalink
add default argument to repeat function (#38)
Browse files Browse the repository at this point in the history
* add default argument to repeat function

* get rid of weird blue underlines between pairs of shields
  • Loading branch information
joshdavham authored Jul 8, 2024
1 parent ecef41f commit 7f5a5d3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 21 deletions.
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
<em>🧠🔄 Build your own Spaced Repetition System in Python 🧠🔄 </em>
</div>
<br />
<div align="center">
<a href="https://pypi.org/project/fsrs/">
<img src="https://img.shields.io/pypi/v/fsrs">
</a>
<a href="https://github.com/open-spaced-repetition/py-fsrs/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-brightgreen.svg">
</a>
<a href="https://github.com/psf/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg">
</a>
<div align="center" style="text-decoration: none;">
<a href="https://pypi.org/project/fsrs/"><img src="https://img.shields.io/pypi/v/fsrs"></a>
<a href="https://github.com/open-spaced-repetition/py-fsrs/blob/main/LICENSE" style="text-decoration: none;"><img src="https://img.shields.io/badge/License-MIT-brightgreen.svg"></a>
<a href="https://github.com/psf/black" style="text-decoration: none;"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
</div>
<br />

Expand All @@ -38,7 +32,6 @@ Import and initialize the FSRS scheduler

```python
from fsrs import *
from datetime import datetime, UTC, timezone

f = FSRS()
```
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -118,4 +110,4 @@ scheduled_days = card_object.scheduled_days

## License

Distributed under the MIT License. See `LICENSE` for more information.
Distributed under the MIT License. See `LICENSE` for more information.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion src/fsrs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.1.0"
__version__ = "2.2.0"

from .fsrs import FSRS, Card

Expand Down
5 changes: 4 additions & 1 deletion src/fsrs/fsrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_fsrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7f5a5d3

Please sign in to comment.