Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Success Rate / Retention #41

Open
AustinHasten opened this issue Dec 28, 2023 · 1 comment
Open

Success Rate / Retention #41

AustinHasten opened this issue Dec 28, 2023 · 1 comment
Labels
feature New addition or enhancement onhold Needs to be scheduled

Comments

@AustinHasten
Copy link

AustinHasten commented Dec 28, 2023

Feature Description
Add a macro for Success Rate / Retention. i.e. the percentage of reviews which you passed rather than failed.

I spent a minute looking through the code to see if I could figure out how to add this myself but it's pretty dense so I just added this function to overview.py:

def true_retention(days_back=0, deck='%'):
    try:
        today = datetime.combine(date.today(), datetime.min.time())
        start_date = today - timedelta(days=days_back)
        start_epoch = start_date.timestamp() * 1000  # nanoseconds to milliseconds or something
        revlog_cmd = f'''
            SELECT
                r.ease
            FROM
                revlog r
                JOIN cards c ON r.cid = c.id
                JOIN decks d ON d.id = c.did
            WHERE
                r.type = 1
                AND r.id > {start_epoch}
                AND d.name like '{deck}'
        '''
        full_revlog = mw.col.db.all(revlog_cmd)
        passed = len([_ for _ in full_revlog if _[0] > 1])
        flunked = len([_ for _ in full_revlog if _[0] == 1])
        if (passed + flunked) < 1:
            return 'No reviews'
        true_retention = passed / (passed + flunked) * 100
        return f'{int(true_retention)}%'
    except Exception as e:
        print(e)
        return 'Error'

And use %eval{true_retention(deck='Deck Name')} as my macro, which seems to be working the way I want it to, but it would be nice if this was integrated.

Great addon, by the way.

@AustinHasten AustinHasten added the feature New addition or enhancement label Dec 28, 2023
@iamjustkoi
Copy link
Owner

Ope, thanks! Can try to see about adding something that might make this a little easier in the future.

If you wanted to try taking a whack at forking and submitting a PR I can also review that and merge it a little sooner, but I can defs look into combining this with some other requests when I'm more available (hopefully soon, but no guarantees)!

Either way, thanks for suggestion and appreciate the code/write up too!

@iamjustkoi iamjustkoi added the onhold Needs to be scheduled label Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New addition or enhancement onhold Needs to be scheduled
Projects
None yet
Development

No branches or pull requests

2 participants