open-spaced-repetition / py-fsrs

Python Package for FSRS
https://pypi.org/project/fsrs/
MIT License
145 stars 23 forks source link

Review Log elapsed days confusion #15

Closed GraesonB closed 1 year ago

GraesonB commented 1 year ago

I'm trying to write a test for review logs for the Rust library and I'm using this library as the source of truth. However, when I generate logs, the elapsed_days isn't making sense to me.

Here's my quick and dirty code:

from datetime import datetime
from src.fsrs import FSRS, Card, Rating
import random
from rich import print

fsrs = FSRS()
card = Card()

ratings = (
    Rating.Good,
    Rating.Good,
    Rating.Good,
    Rating.Good,
    Rating.Good,
    Rating.Good,
    Rating.Again,
    Rating.Again,
    Rating.Good,
    Rating.Good,
    Rating.Good,
    Rating.Good,
    Rating.Good,
)

now = datetime(2023, 4, 18)
logs = []
for rating in ratings:
    scheduling_cards = fsrs.repeat(card, now)
    card = scheduling_cards[rating].card
    log = scheduling_cards[rating].review_log
    logs.append(log)
    now = card.due

for log in logs:
    print(vars(log))

Here's the output:

{'rating': <Rating.Good: 3>, 'elapsed_days': 0, 'scheduled_days': 0, 'review': datetime.datetime(2023, 4, 18, 0, 0), 'state': <State.New: 0>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 2, 'scheduled_days': 0, 'review': datetime.datetime(2023, 4, 18, 0, 10), 'state': <State.Learning: 1>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 7, 'scheduled_days': 2, 'review': datetime.datetime(2023, 4, 20, 0, 10), 'state': <State.Review: 2>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 21, 'scheduled_days': 7, 'review': datetime.datetime(2023, 4, 27, 0, 10), 'state': <State.Review: 2>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 58, 'scheduled_days': 21, 'review': datetime.datetime(2023, 5, 18, 0, 10), 'state': <State.Review: 2>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 145, 'scheduled_days': 58, 'review': datetime.datetime(2023, 7, 15, 0, 10), 'state': <State.Review: 2>}
{'rating': <Rating.Again: 1>, 'elapsed_days': 0, 'scheduled_days': 145, 'review': datetime.datetime(2023, 12, 7, 0, 10), 'state': <State.Review: 2>}
{'rating': <Rating.Again: 1>, 'elapsed_days': 0, 'scheduled_days': 0, 'review': datetime.datetime(2023, 12, 7, 0, 15), 'state': <State.Relearning: 3>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 10, 'scheduled_days': 0, 'review': datetime.datetime(2023, 12, 7, 0, 20), 'state': <State.Relearning: 3>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 24, 'scheduled_days': 10, 'review': datetime.datetime(2023, 12, 17, 0, 20), 'state': <State.Review: 2>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 53, 'scheduled_days': 24, 'review': datetime.datetime(2024, 1, 10, 0, 20), 'state': <State.Review: 2>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 112, 'scheduled_days': 53, 'review': datetime.datetime(2024, 3, 3, 0, 20), 'state': <State.Review: 2>}
{'rating': <Rating.Good: 3>, 'elapsed_days': 224, 'scheduled_days': 112, 'review': datetime.datetime(2024, 6, 23, 0, 20), 'state': <State.Review: 2>}

For the second review, it says the elapsed days is 2, but the review dates are on the same day just 10 minutes apart. This isn't expected behaviour, is it?

L-M-Sherlock commented 1 year ago

Thanks for this report. I find that I swap elapsed_days and scheduled_days in creating the ReviewLog. I will fix it as soon as possible.