Module:User:Erutuon/parameter census

local export = {} local Array = require "Module:array" local sorted_pairs = require "Module:table".sortedPairs

-- Modified from function in Module:User:Erutuon/lang stuff local function ToC_item(title, level) level = level or 2 local equals = ("="):rep(level) return ' \n' .. equals .. title .. equals .. '\n \n' end

local function show_parameter_census(census) local output = Array output:insert(ToC_item("Parameter census", 3)) output:insert {| class="wikitable sortable" ! name !! count for parameter, count in sorted_pairs(census) do		output:insert(:format(parameter, count)) end output:insert "|}" return output:concat end
 * + Parameter census
 * %s || %d
 * %s || %d

local parameter_separator = ","

-- beginning of CJK Unified Ideographs (U+4E00-U+9FFF), -- which don't change in NFC local start_code_point = 0x4E00

local make_parameter_lookup = function (census) local parameter_names = {} for set in pairs(census) do		set = mw.text.split(set, parameter_separator) for _, name in ipairs(set) do			parameter_names[name] = true end end local parameter_names = Array.keys(parameter_names):sort local lookup = {} for i, name in pairs(parameter_names) do		lookup[name] = mw.ustring.char(start_code_point + i - 1) end return lookup end

local function make_parameter_sortkey_maker(census) local lookup = make_parameter_lookup(census) return function(parameter_set) return tostring(parameter_set):gsub("([^,]+),?", lookup) end end

local function compare_by_key(key_maker) return function(a, b)		return key_maker(a) < key_maker(b) end end

local function show_parameter_set_census(census) local output = Array local make_parameter_sortkey = make_parameter_sortkey_maker(census) output:insert(ToC_item("Parameter set census", 3)) output:insert {| class="wikitable sortable" ! parameter set !! count for parameter_set, count in sorted_pairs(census, compare_by_key(make_parameter_sortkey)) do		output:insert(:format(make_parameter_sortkey(parameter_set), parameter_set, count)) end output:insert "|}" return output:concat end
 * + Parameter set census
 * data-sort-value="%s" | %s || %d
 * data-sort-value="%s" | %s || %d

function export.show(frame) local output = Array local jsonl = mw.text.trim(mw.text.unstripNoWiki(frame.args[1])) local lines = mw.text.split(jsonl, "\n") output:insert(ToC_item("All parameters")) output:insert(show_parameter_census(mw.text.jsonDecode(lines[1]))) output:insert "\n" output:insert(show_parameter_set_census(mw.text.jsonDecode(lines[2]))) output:insert(ToC_item("Nonempty parameters")) output:insert "\n" output:insert(show_parameter_census(mw.text.jsonDecode(lines[3]))) output:insert "\n" output:insert(show_parameter_set_census(mw.text.jsonDecode(lines[4]))) return output:concat end

return export