Best way to get the current review item's SRS level?

I’m making a script and I need to get the current review item’s SRS level, but I’m kind of lost how I can do that. I’ve looked through a bunch of scripts and documentation for the Wanikani API and the Wanikani Open Framework and I’m pretty lost as it all seems like a ton of code for getting a single value. Is there a quick and easy way of getting this?

For clarity I’m talking about getting the SRS stage of the current item when you are doing reviews.

2 Likes

Traveling and not close to a computer so I can only talk at a high level.

Basically, use wkof to create an array of all subjects (an array of objects). Then lookup the ID of the subject you are reviewing within that array. The SRS_stage is a property of that individual object. I think but I’m not completely sure that the object array of subjects is indexed by ID by default. If not you need to create an index first.

4 Likes

I would use the WKOF. Something like this should work (untested, writing from memory). You would call get_current_item_srs() which would return the srs level.

// Setup
// --------------------------------------------------
if (!wkof) {
    // Alert user that they have to install WKOF
}

wkof.include('ItemData')
wkof.ready('ItemData').then(get_items)

// Store items globally so you don't have to get them from WKOF every time
let item, items_by_id;
async function get_items() {
    items = await wkof.ItemData.get_items('assignments')
    items_by_id = wkof.ItemData.get_index(items, 'subject_id')
}


// Functions to get SRS level
// --------------------------------------------------

// Get current item's SRS level
function get_current_item_srs() {
    const review_item = $.jStorage.get('currentItem')
    const item = items_by_id[review_item.id]
    return get_srs_level(item)

// Extract SRS level from WKOF item
function get_srs_level(wkof_item) {
    return wkof_item?.assignments?.srs_stage ?? -1
}
3 Likes

I suspected something like that looking at the documentation, although I was lost on how I’d go from the item to the ID, thanks!

1 Like

So assignments is all items in the review queue? :thinking:

Thanks! That’s much closer to the level of simplicity I was hoping for!

1 Like

The assignment for an item contains all the user’s information about that item; e.g. srs stage and when it will be available next. Through the WK API this has to be fetched separately, but WKOF combines it with the data. I believe every item that is unlocked has a corresponding assignment.

1 Like

Oh right, I was confused about the terminology!

In any case it all works great so thanks!

1 Like