Wanikani Open Framework [developer thread]

@rfindley finally taking a look at what you said here about adding WK Custom SRS as a WKOF source, and was just hoping you might be able to clarify slightly how the fetcher function should work.

So far I have this:

if(wkof) {
    const wkofHandler = (config, options) => {
        return new Promise((resolve, reject) => {
            reject("Not implemented yet.");
        });
    }
    wkof.ItemData.registry.sources["wk_custom_srs"] = {
       description: "WK Custom SRS",
       fetcher: wkofHandler
    }
}

I can see from the WKOF implementation

WKOF Implementation
function get_wk_items(config, options) {
		let cfg_options = config.options || {};
		options = options || {};
		let now = new Date().getTime();

		// Endpoints that we can fetch (subjects MUST BE FIRST!!)
		let available_endpoints = ['subjects','assignments','review_statistics','study_materials'];
		let spec = wkof.ItemData.registry.sources.wk_items;
		for (let filter_name in config.filters) {
			let filter_spec = spec.filters[filter_name];
			if (!filter_spec || typeof filter_spec.set_options !== 'function') continue;
			let filter_cfg = config.filters[filter_name];
			filter_spec.set_options(cfg_options, filter_cfg.value);
		}

		// Fetch all of the endpoints
		let ep_promises = [];
		for (let idx in available_endpoints) {
			let ep_name = available_endpoints[idx];
			if (ep_name === 'subjects' || cfg_options[ep_name] === true)
				ep_promises.push(
					wkof.Apiv2.get_endpoint(ep_name, options)
					.then(process_data.bind(null, ep_name))
				);
		}
		return Promise.all(ep_promises)
		.then(function(all_data){
			return all_data[0];
		});

		//============
		function process_data(ep_name, ep_data) {
			if (ep_name === 'subjects') return ep_data;
			// Merge with 'subjects' when 'subjects' is done fetching.
			return ep_promises[0].then(cross_link.bind(null, ep_name, ep_data));
		}

		//============
		function cross_link(ep_name, ep_data, subjects) {
			for (let id in ep_data) {
				let record = ep_data[id];
				let subject_id = record.data.subject_id;
				subjects[subject_id][ep_name] = record.data;
			}
		}
	}

that it seemingly needs to handle all the endpoints? Could I e.g. only handle the subjects/id endpoint? @Kumirei my main intention is to get the script working with your Heatmap - what function/arguments etc. would it try to call in the WKOF get_items() which I need to implement in my custom source fetcher?

I’d like to get my Custom SRS script working with at least Heatmap, but also can’t spend ages working on replicating all the endpoints etc. the WK handler manages, so I’m just trying to work out what the minimum necessary would be :sweat_smile:

Sorry for all the questions, I’d love to get this working but unfortunately just have limited time to work out how to so any help would be amazing :upside_down_face:

1 Like