How to get SRS stats with V2 API?

There isn’t a simple getter for SRS totals (although it would be really convenient if the srs_stages endpoint added an item_total property…), so what I ended up doing for my userscript was having to loop through all items and accumulate counters for each SRS stage.

const wkSRSTotals = [0, 0, 0, 0, 0, 0, 0, 0, 0];
const config = {
    wk_items: {
        options: {assignments: true}
    }
};
window.wkof.ItemData.get_items(config).then((processItems) => {
    for (let item of processItems) {
        const srsLevel = item && item.assignments && item.assignments.srs_stage;
        if (srsLevel != null) {
            wkSRSTotals[srsLevel - 1]++;
        }
    }
})

I’m using the open framework API wrappers here for userscript convenience, but you could technically implement the same logic using the base API in any language…

2 Likes