Help with userscript for getting # of items in each SRS stage

I’m a script newbie, creating a seemingly simple script, but I’m at a loss as to how to get the information I want from the wanikani API.

I’m looking for the number of items currently in each SRS stage. For example, 23 in SRS1, 19 in SRS2, etc. Sort of like the dashboard page which shows Apprentice, Guru, … counts, but for each stage.

Any of you script masters out there want to give a newbie some tips? Or point me to a script I can swipe code from?

Thanks

this script uses the WaniKani Open Framework to retrieve the ‘items in queue’ and counts them by SRS stage, giving you the totals per stage.
Good luck experimenting!

2 Likes

As @rwesterhof suggests, WK Open Framework is the way to go here.

Something like this should get you what you need:

wkof.include('ItemData')
wkof
    .ready('ItemData')
	.then(() => wkof.ItemData.get_items('assignments'))
	.then(items =>  wkof.ItemData.get_index(items, "srs_stage_name"))
	.then(index => {
		const burned_count = index['Burned'].length;
		const guru_2_count = index['Guru II'].length;
		// ...
	});
3 Likes

Ah - actually, this one is reasonably fast :slight_smile: It’ll work! Thanks

Building the full index just to get the array lengths might be overkill, I simply included it since it’s already there. You could certainly build your own loop over the items list.
However, you should definitely use WKOF to query the API, as it is able to cache requests across scripts.

1 Like

Thanks - that makes sense. I’ll play with that. Your method was already much faster (and more compact) than the code I borrowed from WaniKani Dashboard SRS and Leech Breakdown. I suspect the delay is just getting all the items in the first place.

I’m using this on the Dashboard, so I can get a close approximation just by grabbing the apprentice, guru, master, enlightened, and burned numbers from the page text :slight_smile:

LOL - I also learned some new javascript techniques from your code - thanks. I used to work for Sun Microsystems as a Java developer, and C & C++ before Java was around, so Javascript feels familiar but has some syntax I don’t know yet. Always fun to learn…

1 Like

JavaScript has grown a lot in recent years. I don’t like the ecosystem around node.js and npm, but the language itself is quite fun with stuff like arrow functions, destructuring and async/await.
The problem is, of course, that adding all this stuff keeps increasing the language’s complexity, making it hard to keep up with how to use it properly and even harder to learn it initially.

2 Likes