[Userscript] Self-Study Quiz

:point_right: [v3.0.0] - Migrated to Wanikani Open Framework and APIv2

2 Likes

There are some UI issues with dragging the settings box. If you drag it up quickly, you can actually make it go above the visible part of the browser window, making it so you canā€™t continue to move the dialog. Resizing the dialog fixes this issue.

Also, what does the ā€œInclude this sourceā€ setting do? Is it just a namespacing type of thing?

Thatā€™s entirely jquery UI, though I might be able to do a post-drag check and correction.
Iā€™m not totally happy with some of jquery UIā€™s behavior, but I also donā€™t want to write my own (ugh!).

Via the Open Framework, scripters can add external sources of data, like a Core10k deck, which will then have its own tab next to Wanikani in the Items section. If you want to create a preset that only quizzes you on Core10k vocab, you would uncheck the ā€œInclude this sourceā€ on the Wanikani tab, and check it on the ā€œCore10kā€ tab.

I see, so itā€™s basically a way to add entirely different items to self quiz with your script.

Can you give an example for how Iā€™d add a filter? I have a handful I want to add. Also, whatā€™s your thought on best practice for bundling a bunch together versus including a separate script per additional filter?

wkof.ItemData.registry.sources.wk_items.filters.percent_filter = {
    type: 'number',
    label: 'Percent Correct',
    filter_func: percent_filter_func,
    set_options: function(options){options.review_statistics = true;},
    hover_tip: 'Filter items by accuract (in percent)'
}
function percent_filter_func(filter_value, item) {
    if (item.review_statistics === undefined) return false;
    var percent = item.review_statistics.percentage_correct;
    if (percent === null || percent === undefined) return false;
    if (percent < filter_value)
        return true;
    else
        return false;
}

Iā€™ll probably create a ā€œFilter Packā€ script, which will have its own [Menu -> Scripts: Settings -> Open Framework Filter Pack]. That will open a separate Settings dialog where users can check which filters they want to register, so only desired ones will appear in the Self Study Quiz settings dialog (and any other script that uses the registry).

If you want to start by just bundling filters into a single script, or start your own filter pack like I described, that would be a good start.

[edit: by the way, I created a ā€˜buttonā€™ filter type in case you want to make a popup dialog for setting up a multi-criteria filter. Iā€™m not ready to delve deeper to create a cascaded ā€˜complexā€™ type yet.]

1 Like

Would this just be to avoid cluttering the Self Study Quiz settings (and other script) UI? From what I could tell, each filter option is disabled by default, so including extra ones wouldnā€™t be harmful, just a potential eyesore. Is that right?

Sorry for all the questions, I just want to understand how it all works.

Essentially, yes. While testing, I had a handful of filters for testing specific item sets, and it was annoying having to wade through a large number of filters, even if most of them are disabled. I donā€™t like clutter, and I can envision there eventually being a large filter pack (especially when Core10k is implemented), so I wanted a way to hide ones Iā€™m not using. I imagine there are other people who would want to do the same.

1 Like

Looks like youā€™re not handling when a filter is deleted. Or rather, it looks like you are explicitly throwing an exception when that happens. I added the exact code you pasted above with the filter called percent_filter and tested it, saving a value for it in the settings. Then I replaced it with a filter I actually wanted to add. Trying to test the new filter, I get the following error:

VM1467:138 Uncaught (in promise) Error: wkof.ItemData.get_item() - Invalid filter "percent_filter"
    at apply_filters (<anonymous>:138:41)
    at <anonymous>:60:13

Yeah, I noticed that just before quitting for dinner. The preset saved in your settings is calling for a filter to be used, yet that filter doesnā€™t exist. The framework is properly complaining that youā€™re asking it to use a filter that doesnā€™t exist.

It looks like I need to check in the Self-Study Quiz if a filter is missing, and just remove it from the preset.

Gotcha. This could definitely use some more documentation by the way. I was having trouble getting my filter to work on first page load, and I realized it was because I didnā€™t have set_options: function(options) { options.assignments = true; }.

I just installed this and am using Chrome. No matter what options I choose, it takes a little while to load and then says, ā€œNo questions found!ā€ Suggestions on what I should do or look at to resolve this?

Hehā€¦ yeah, it was only a prototype until 3 hours ago :slight_smile:

1 Like

If you set the left drop-down the ā€œAll Questionsā€ and the right one to ā€œAll Wanikani Itemsā€, you still get ā€œNo questions found!ā€ ?

If so, check your Javascript console for errors. Press F12 and click on the ā€˜Consoleā€™ tab, and post a snapshot of any errors.

Correct.

image

Based on those errors, it looks like the ItemData module isnā€™t loaded.

In the Javascript console, does it say ā€˜undefinedā€™ when you type the following (and press enter)?

wkof.ItemData

If so, what happens when you type this?

wkof.include('ItemData')

If all else fails, you could try clearing the wkof cache:

wkof.file_cache.clear()

Then refresh the page.

Yes, undefined

If so, what happens when you type this?

wkof.include(ā€˜ItemDataā€™)

image

If all else fails, you could try clearing the wkof cache:
wkof.file_cache.clear()
Then refresh the page.

No dice. I still get ā€œno questionsā€ and this in the console:
image

@rfindley Yay for minor UI bugs! Open the settings and go to the Items tab. Change the name of a preset but donā€™t save. Close the settings dialog, and reopen it. The name of the preset in the Edit Preset Name input has gone back to the previous/saved value. But the Presets List shows the new/unsaved value.

I missed a step in what I intended to have you do.

After this:

wkof.include('ItemData')

Try this again:

wkof.ItemData

You shouldnā€™t get undefined anymore. If you do, then the module is having trouble loading for some reason, in which case it would help to check the Network tab to scroll back and see if there are any files that didnā€™t load (highlighted in red).

Iā€™ve got a fix for this. It was introduced during the big refactoring :-/
Iā€™ll upload after fixing the other issue (missing filter).

Ok, so now I get this:
image

Nothing highlighted in red in the Network tab.