Straight Reward [Official support]

Hi, I think I found a bug.

Begin at staight of length is set to 1 when using the regular dialog, and it is seen as 2 when using the old dialog by pressing down the shift key. This is true when clicking the button to reset the default values. Not sure if it is just wrongly displayed.

I am using 2.1.54. Thank you

I had a similar issue, I had to open the shortcut folder and change the default values there to my values to resolve it.

Currently, you can only configure Straight Reward through the old dialog.

Hi, does this add-on count the amount of times I press “Good” in the learning phase? I have configured my learning phase to have quite a bit more steps than the default, which works better for me.

Should I configure this add-on to start rewarding me only after I’ve finished my learning steps? So something like this:

Begin at straight length of: (learning steps + 1)

Which setting do you recommend in my case?

No, it doesn’t change the difficulty as long as the card is in the re-learning phase.

EDIT: Found the mention of the sync_log on the addon page, that answers my question. :slight_smile:

Thanks so much for your work on this addon! Is there any way to see what cards have been given a straight reward?

I’m really excited about this add-on! But I’m concerned that it isn’t working working on the reviews I sync from AnkiDroid.

I was having the v3/2.1.49 issue yesterday (notification, but no change to ease), so I upgraded AnkiDesktop to ⁨2.1.54 just to get this to work with v3. I was able to verify that the ease increase was correctly applied to the rest of my reviews on AnkiDesktop yesterday.

Today I did my reviews on AnkiDroid (v2.15.6). After sync, I got the notification that ease was updated on 15 cards. I can see those IDs in sync_log, but none of those cards show any change in the ease.

Ex. Based on my settings …
image

… easeplus was correctly calculated to 10 …
image

… but ease was not changed on that card.
image

I haven’t been able to find anything about this in any of the forums. Is this a known issue?

1 Like

I updated to 2.1.56 today (for other reasons) and I am seeing the same issue when I sync reviews from AnkiDroid. Notification that ease was updated, new records added to sync_log, but no change in ease for those cards.

1 Like

Thanks for your work in creating and maintaining this addon. Question - If a card has been tagged as a leech, does it matter as far as this addon is concerned? Can it still rise again in ease?

I can confirm from my own experience that the leech tag does not keep the ease from rising again.

1 Like

In 2.1.60, if I turn off Enable notifications and hit Save, notifications remain enabled. This happens both with my v3+FSRS profile as well as a test v2 profile. I am not sure in which version this started, because I didn’t feel a need to disable notifications until switching to FSRS, which doesn’t use ease at all, but I still like Straight Reward doing its thing in the background, just in case.

Version ⁨2.1.60 (76d88073)⁩
Python 3.9.15 Qt 6.4.2 PyQt 6.4.0
Windows 11

Having the same issue.

Pre-releas Anki 2.1.66rc1 seems to have an error in Straight Reward and can’t be used. This occurs in both Qt5 and Qt6 (Windows).

Debug info:
Anki 2.1.66 (70506aeb) Python 3.9.15 Qt 6.5.2 PyQt 6.5.2
Platform: Windows-10-10.0.22621
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-08-22 00:38:49
Add-ons possibly involved: <U+2068>Straight Reward<U+2069>

Caught exception:
Traceback (most recent call last):
  File "aqt.webview", line 46, in cmd
  File "aqt.webview", line 153, in _onCmd
  File "aqt.webview", line 665, in _onBridgeCmd
  File "aqt.reviewer", line 581, in _linkHandler
  File "aqt.reviewer", line 449, in _answerCard
  File "_aqt.hooks", line 4224, in __call__
  File "C:\Users\shigg\AppData\Roaming\Anki2\addons21\957961234\src\lib\review_hook.py", line 100, in <lambda>
    lambda ease_tuple, reviewer, card: on_will_answer_card(
  File "C:\Users\shigg\AppData\Roaming\Anki2\addons21\957961234\src\lib\review_hook.py", line 84, in on_will_answer_card
    check_straight_reward(gains, reviewer, card, ease_tuple[1])
  File "C:\Users\shigg\AppData\Roaming\Anki2\addons21\957961234\src\lib\review_hook.py", line 70, in check_straight_reward
    reviewer.set_scheduling_states(reviewer._state_mutation_key, next_states)
TypeError: set_scheduling_states() takes 2 positional arguments but 3 were given

Same error here with Anki 2.1.66 on Linux:

Informazioni di debug:
Anki 2.1.66 (cf16ce1d) Python 3.11.3 Qt 6.5.2 PyQt 6.5.2
Platform: Linux-6.4.12-arch1-1-x86_64-with-glibc2.38
Flags: frz=False ao=True sv=3
Add-ons, last update check: 2023-08-26 20:51:28
Add-on che potrebbero essere coinvolti: <U+2068>Straight Reward<U+2069>

Caught exception:
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/aqt/webview.py", line 607, in handler
    cb(val)
  File "/usr/lib/python3.11/site-packages/aqt/reviewer.py", line 574, in _onAnswerButton
    self._answerCard(self._defaultEase())
  File "/usr/lib/python3.11/site-packages/aqt/reviewer.py", line 449, in _answerCard
    proceed, ease = gui_hooks.reviewer_will_answer_card(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/_aqt/hooks.py", line 3433, in __call__
    ease_tuple = filter(ease_tuple, reviewer, card)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/marco/.local/share/Anki2/addons21/957961234/src/lib/review_hook.py", line 100, in <lambda>
    lambda ease_tuple, reviewer, card: on_will_answer_card(
                                       ^^^^^^^^^^^^^^^^^^^^
  File "/home/marco/.local/share/Anki2/addons21/957961234/src/lib/review_hook.py", line 84, in on_will_answer_card
    check_straight_reward(gains, reviewer, card, ease_tuple[1])
  File "/home/marco/.local/share/Anki2/addons21/957961234/src/lib/review_hook.py", line 70, in check_straight_reward
    reviewer.set_scheduling_states(reviewer._state_mutation_key, next_states)
TypeError: Reviewer.set_scheduling_states() takes 2 positional arguments but 3 were given

Hi, if you just updated your Anki to 2.1.66 and you’re getting the error posted above, I was able to fix it by doing the following:

  1. Navigate into the addon’s “lib” folder (for me it’s “…/Anki2/addons21/957961234/src/lib/”)
  2. Replace the entirety of “review_hook.py” with the following:
from typing import Tuple

from aqt import mw
from aqt.gui_hooks import (
    reviewer_will_answer_card,
    reviewer_did_answer_card,
    review_did_undo,
)

from aqt.utils import tooltip

from anki.hooks import card_will_flush
from anki.consts import CARD_TYPE_REV, REVLOG_REV
from anki.collection import Collection
from anki.cards import Card

from .logic import (
    get_straight_len,
    get_easeplus,
    notifications_enabled,
    review_success,
    Button,
)

def display_success(straightlen: int, easeplus: int):
    MSG = (
        f"Succeeded {straightlen} times in a row.<br>"
        f"Gained <b>{easeplus}</b> Ease Factor!"
    )

    tooltip(MSG)


def card_success(card: Card, answer: Button) -> bool:
    # CARD_TYPE_* does not match to REVLOG_*, because 3 is RELRN as card type, but CRAM as revlog
    return card.type == CARD_TYPE_REV and review_success((REVLOG_REV, answer))


def from_rescheduling_deck(card: Card) -> bool:
    # check whether it is a filtered deck ("dynamic") which does not reschedule
    return (
        not mw.col.decks.is_filtered(card.did) or mw.col.decks.get(card.did)["resched"]
    )

class SetSchedulingStatesRequest:
    def __init__(self, key, states):
        self.key = key
        self.states = states

def check_straight_reward(
    gains: dict,
    reviewer,
    card: Card,
    rating: int,
) -> None:
    if not card_success(card, rating) or not from_rescheduling_deck(card):
        return

    # plus one for the current success
    straightlen = get_straight_len(card.id) + 1
    easeplus = get_easeplus(card, straightlen)

    if not easeplus:
        return

    if reviewer._v3:
        next_states = reviewer.get_scheduling_states()

        if rating == 3:
            next_states.good.normal.review.ease_factor += easeplus / 1000
        else:
            next_states.easy.normal.review.ease_factor += easeplus / 1000

        request = SetSchedulingStatesRequest(reviewer._state_mutation_key, next_states)
        reviewer.set_scheduling_states(request)
    else:
        gains[card.id] = easeplus

    if notifications_enabled(card):
        display_success(straightlen, int(easeplus / 10))


def on_will_answer_card(
    gains: dict,
    ease_tuple: tuple[bool, int],
    reviewer,
    card: Card,
) -> tuple[bool, int]:
    check_straight_reward(gains, reviewer, card, ease_tuple[1])
    return ease_tuple


def flush_with_straight_reward(gains: dict, card: Card) -> None:
    if card.id not in gains:
        return

    card.factor += gains[card.id]
    del gains[card.id]


def init_review_hook():
    gains = {}

    reviewer_will_answer_card.append(
        lambda ease_tuple, reviewer, card: on_will_answer_card(
            gains, ease_tuple, reviewer, card
        ),
    )

    card_will_flush.append(
        lambda card: flush_with_straight_reward(gains, card),
    )

It should work again.

From checking the github, it is my understanding that there have been commits to the repo to provide a patch for 2.1.66 users in the future, correct? I am not very technically inclined, so I just wanted to make sure. Thank you and everyone who contributes to the project for their work!

Hi! I have been experiencing this error message occasionally after installing the add on. Haven’t touched any of the default settings, please help!

Error 
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed. 
If the issue only occurs when add-ons are enabled, please use the Tools>Add-ons menu item to disable some add-ons and restart Anki, repeat until you discover the add-on that is causing the problem. 
When you've discovered the add-on that is causing the problem, please report the issue on the add-ons section of our support site. 
Debug info:
Anki 2.1.66 (70506aeb) Python 3.9.15 Qt 6.5.2 PyQt 6.5.2
Platform: Windows-10-10.0.18362
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-10-25 17:21:35
Add-ons possibly involved: <U+2068>Straight Reward<U+2069>

Caught exception:
Traceback (most recent call last):
  File "aqt.reviewer", line 449, in _answerCard
  File "_aqt.hooks", line 4224, in __call__
  File "C:\Users\SONY\AppData\Roaming\Anki2\addons21\957961234\src\lib\review_hook.py", line 100, in <lambda>
    lambda ease_tuple, reviewer, card: on_will_answer_card(
  File "C:\Users\SONY\AppData\Roaming\Anki2\addons21\957961234\src\lib\review_hook.py", line 84, in on_will_answer_card
    check_straight_reward(gains, reviewer, card, ease_tuple[1])
  File "C:\Users\SONY\AppData\Roaming\Anki2\addons21\957961234\src\lib\review_hook.py", line 70, in check_straight_reward
    reviewer.set_scheduling_states(reviewer._state_mutation_key, next_states)
TypeError: set_scheduling_states() takes 2 positional arguments but 3 were given

Oh I see some others are receiving the same error message. Sorry for spam, I’m quite new to the forum ;-;

Got this error with the newest update today.

"Error
An add-on you installed failed to load. If problems persist, please go to the Tools>Add-ons menu, and disable or delete the add-on.

When loading ‘⁨Straight Reward⁩’:
⁨Traceback (most recent call last):
File “aqt.addons”, line 246, in loadAddons
File “/Users/rikr0x/Library/Application Support/Anki2/addons21/957961234/init.py”, line 40, in
from .src import init
File “/Users/rikr0x/Library/Application Support/Anki2/addons21/957961234/src/init.py”, line 2, in
from .lib import init_review_hook, init_sync_hook
File “/Users/rikr0x/Library/Application Support/Anki2/addons21/957961234/src/lib/init.py”, line 1, in
from .review_hook import init_review_hook
File “/Users/rikr0x/Library/Application Support/Anki2/addons21/957961234/src/lib/review_hook.py”, line 9, in
from anki.scheduler.v3 import SetSchedulingStatesRequest
ImportError: cannot import name ‘SetSchedulingStatesRequest’ from ‘anki.scheduler.v3’ (unknown location)"

Error on the most recent version:

Anki 23.10 (51a10f09) Python 3.9.15 Qt 6.5.3 PyQt 6.5.3
Platform: Windows-10-10.0.19045
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-11-02 15:41:40

When loading Straight Reward:
Traceback (most recent call last):
File “aqt.addons”, line 244, in loadAddons
File “C:\Users\jatri\AppData\Roaming\Anki2\addons21\957961234_init_.py”, line 40, in
from .src import init
File “C:\Users\jatri\AppData\Roaming\Anki2\addons21\957961234\src_init_.py”, line 2, in
from .lib import init_review_hook, init_sync_hook
File “C:\Users\jatri\AppData\Roaming\Anki2\addons21\957961234\src\lib_init_.py”, line 1, in
from .review_hook import init_review_hook
File “C:\Users\jatri\AppData\Roaming\Anki2\addons21\957961234\src\lib\review_hook.py”, line 4, in
from aqt.gui_hooks import (
ImportError: cannot import name ‘review_did_undo’ from ‘aqt.gui_hooks’ (unknown location)