Custom Scheduling new/learning cards

So I’ve been trying to get this to work for days. It just isn’t working accurately.
In the logs I’m getting clearly the right numbers. The scheduledSecs for hard and good are correct in the console, but when I study, the buttons show default timers. And it seems no matter how much I dig into the open source code or guides on scheduling, i can’t find why this isn’t exactly correct.

To be precise I want to make sure the time since last studied is what the card calculates for my ‘ease’ during the learning steps. Graduating to the anki scheduler as soon as it reaches a few days as set in the settings under ‘graduating interval’. This way If i set the phone down for the night, and remember a card with an interval of 5m, it’ll recognize that I actually remembered that card for 10h and set the next interval appropriately. This is a personal pet peeve of mine that destroys my motivation without. Even if it’s illogical, it’s something I really need.

The problem is i can’t seem to get it to display the proper time, even if the scheduledSecs is accurate. It’s not updating. I’ve even tried using a timeout to ensure it’s updated a bit after rendering. It won’t change. Sometimes, if i answer a card, then undo and the buttons have updated.

This code isn’t perfect in what I want but it’s the current attempt to at least consistently update the buttons.

const now = Date.now();
const answeredSecs = typeof answered_at_millis === "number"
  ? (now - answered_at_millis) / 1000
  : 0;

const maxElapsedSecs = Math.max(
  states.current?.normal?.learning?.elapsedSecs ?? 0,
  states.again?.normal?.learning?.elapsedSecs ?? 0,
  states.hard?.normal?.learning?.elapsedSecs ?? 0,
  answeredSecs,
  1
);

states.hard.normal.learning.scheduledSecs = Math.round(maxElapsedSecs * 1);
states.good.normal.learning.scheduledSecs = Math.round(maxElapsedSecs * 2.5);

Everything I read says this should work just fine. I’ve tried it a thousand different other ways but this SHOULD be working. It’s just not. Logs say it’s working:
JS info :32 Updated HARD scheduledSecs: 958
JS info :33 Updated GOOD scheduledSecs: 2395

But the card says ‘hard 2m’ ‘good 3m’.

2 Likes

Still unsure, been trying other logs and even consulted some AI over if I’m missing something obvious, nothing to be found.

I tested your code and it was successfully modifying the answer button values for me in learning steps. The only possible issues I can see are these:

  • You’re not checking if states.good.normal.learning.scheduledSecs is defined, so it’ll crash when you’re on the last learning step and the good answer is review.scheduledDays and not learning.scheduledDays.
    • You do have at least 2 learning steps defined?
  • You’re assuming you’re always in a normal deck, so the code won’t work in a filtered deck where, e.g. the good state could be states.good.filtered.rescheduling.originalState... instead of states.good.normal....

What do you see logged when you add these console.logs?

const now = Date.now();
const answeredSecs = typeof answered_at_millis === "number"
  ? (now - answered_at_millis) / 1000
  : 0;

const maxElapsedSecs = Math.max(
  states.current?.normal?.learning?.elapsedSecs ?? 0,
  states.again?.normal?.learning?.elapsedSecs ?? 0,
  states.hard?.normal?.learning?.elapsedSecs ?? 0,
  answeredSecs,
  1
);

console.log('maxElapsedSecs', maxElapsedSecs, 'before states', JSON.stringify(states, null, 4));

states.hard.normal.learning.scheduledSecs = Math.round(maxElapsedSecs * 1);
states.good.normal.learning.scheduledSecs = Math.round(maxElapsedSecs * 2.5);

console.log('hard',Math.round(maxElapsedSecs * 1), 'good', Math.round(maxElapsedSecs * 2.5), 'after states', JSON.stringify(states, null, 4));