<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.roatpkz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AFetchItemStats</id>
	<title>Module:FetchItemStats - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.roatpkz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AFetchItemStats"/>
	<link rel="alternate" type="text/html" href="https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;action=history"/>
	<updated>2026-05-24T18:11:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;diff=20217&amp;oldid=prev</id>
		<title>Hefner: Replaced content with &quot;local p = {}  function p.defaultVersion(itemname)     -- For obtaining default version, you don&#039;t need to query SMW.     return itemname end  function p.value(itemname)     -- For obtaining value, you don&#039;t need to query SMW.     -- Instead, directly return the item name.     return itemname end  function p.getImage(itemname)     -- Just return the item name for fetching the image.     return itemname end  return p&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;diff=20217&amp;oldid=prev"/>
		<updated>2024-05-03T15:41:45Z</updated>

		<summary type="html">&lt;p&gt;Replaced content with &amp;quot;local p = {}  function p.defaultVersion(itemname)     -- For obtaining default version, you don&amp;#039;t need to query SMW.     return itemname end  function p.value(itemname)     -- For obtaining value, you don&amp;#039;t need to query SMW.     -- Instead, directly return the item name.     return itemname end  function p.getImage(itemname)     -- Just return the item name for fetching the image.     return itemname end  return p&amp;quot;&lt;/p&gt;
&lt;a href=&quot;https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;amp;diff=20217&amp;amp;oldid=4305&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Hefner</name></author>
	</entry>
	<entry>
		<id>https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;diff=4305&amp;oldid=prev</id>
		<title>Hefner: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;diff=4305&amp;oldid=prev"/>
		<updated>2024-03-30T22:33:09Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:33, 30 March 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Hefner</name></author>
	</entry>
	<entry>
		<id>https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;diff=4304&amp;oldid=prev</id>
		<title>Wilderness&gt;Theslamprogram: Add is members only prop to equipment stats</title>
		<link rel="alternate" type="text/html" href="https://wiki.roatpkz.com/index.php?title=Module:FetchItemStats&amp;diff=4304&amp;oldid=prev"/>
		<updated>2022-05-12T03:07:50Z</updated>

		<summary type="html">&lt;p&gt;Add is members only prop to equipment stats&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Note: This module is not meant to be invoked directly, and instead is intended to be used from other modules.&lt;br /&gt;
local exchange = require(&amp;#039;Module:Exchange&amp;#039;)&lt;br /&gt;
local yesno = require(&amp;#039;Module:Yesno&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Obtain information about which version of an item is the default version of the item&lt;br /&gt;
-- if no switch infoobox is present, the item name itself will be returned.&lt;br /&gt;
-- The second return value is the actual pagename of the page that is retrieved in the SMW call, taking redirects into account.&lt;br /&gt;
function p.defaultVersion(itemname)&lt;br /&gt;
	if not itemname or itemname == &amp;#039;&amp;#039; then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local item = mw.smw.ask({&amp;quot;[[&amp;quot; .. itemname .. &amp;quot;]]&amp;quot;, &amp;quot;?Default version&amp;quot;})&lt;br /&gt;
	if not item then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	item = item[1]&lt;br /&gt;
	local defver = item[&amp;#039;Default version&amp;#039;]&lt;br /&gt;
	if defver then&lt;br /&gt;
		return itemname .. &amp;#039;#&amp;#039; .. defver, item[1]&lt;br /&gt;
	else&lt;br /&gt;
		return itemname, item[1]&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Get item value from its page based on name.&lt;br /&gt;
-- If a switch infobox is present on the entered page, the price for the item version that is shown by default is fetched.&lt;br /&gt;
function p.value(itemname)&lt;br /&gt;
	if not itemname or itemname == &amp;#039;&amp;#039; then&lt;br /&gt;
		return 0&lt;br /&gt;
	end&lt;br /&gt;
	local item = mw.smw.ask({&amp;quot;[[&amp;quot; .. itemname .. &amp;quot;]]&amp;quot;, &amp;quot;?Default version&amp;quot;, &amp;quot;?Value&amp;quot;})&lt;br /&gt;
	if not item then&lt;br /&gt;
		return -1&lt;br /&gt;
	end&lt;br /&gt;
	item = item[1]&lt;br /&gt;
	local value = 0&lt;br /&gt;
	if item[&amp;#039;Value&amp;#039;] == nil then&lt;br /&gt;
	    local itemversion = item[&amp;#039;Default version&amp;#039;]&lt;br /&gt;
	    if not itemversion then&lt;br /&gt;
	    	return 0&lt;br /&gt;
	    end&lt;br /&gt;
	    local default = mw.smw.ask({&amp;quot;[[&amp;quot; .. itemname .. &amp;quot;#&amp;quot; .. itemversion .. &amp;quot;]]&amp;quot;, &amp;quot;?Value&amp;quot;})[1]&lt;br /&gt;
	    if default[&amp;#039;Value&amp;#039;] ~= nil then&lt;br /&gt;
	        value = default[&amp;#039;Value&amp;#039;]&lt;br /&gt;
	    end&lt;br /&gt;
	else&lt;br /&gt;
	    value = item[&amp;#039;Value&amp;#039;]&lt;br /&gt;
	end&lt;br /&gt;
	return value&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function undoSort(pages, statslist)&lt;br /&gt;
	local lookup = {}&lt;br /&gt;
	for i, page in ipairs(pages) do&lt;br /&gt;
		lookup[string.lower(page)] = i&lt;br /&gt;
	end&lt;br /&gt;
	local ret = {}&lt;br /&gt;
	for _, stats in ipairs(statslist) do&lt;br /&gt;
		local i = lookup[string.lower(stats[1])]&lt;br /&gt;
		-- if i==nil then an item was referred to by their redirect page; cannot undo sorting&lt;br /&gt;
		assert(i ~= nil, string.format(&amp;quot;Cannot use `sort=no` for redirect pages. Ensure the item \&amp;quot;%s\&amp;quot; is a direct link to the page&amp;quot;, stats[1]))&lt;br /&gt;
		ret[i] = stats&lt;br /&gt;
	end&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Fetches equipment stats, image, and weight for a list of pages. &lt;br /&gt;
-- First argument: a list of pages&lt;br /&gt;
-- Second argument: the sort keys for the returned data (array of keys); if equal to {&amp;#039;no&amp;#039;} the order used in the first parameter is used.&lt;br /&gt;
-- Third argument: the order in which these sort keys should be (asc / desc / reverse / random)&lt;br /&gt;
function p.equipmentStats(pages, keys, orders)&lt;br /&gt;
	-- mw.logObject(keys)&lt;br /&gt;
	if keys == nil then&lt;br /&gt;
		keys = {}&lt;br /&gt;
		orders = {}&lt;br /&gt;
	elseif orders == nil then&lt;br /&gt;
		orders = {}&lt;br /&gt;
	end&lt;br /&gt;
    local prop = {&lt;br /&gt;
        astab  = &amp;#039;Stab attack bonus&amp;#039;,&lt;br /&gt;
        aslash = &amp;#039;Slash attack bonus&amp;#039;,&lt;br /&gt;
        acrush = &amp;#039;Crush attack bonus&amp;#039;,&lt;br /&gt;
        amagic = &amp;#039;Magic attack bonus&amp;#039;,&lt;br /&gt;
        arange = &amp;#039;Range attack bonus&amp;#039;,&lt;br /&gt;
        dstab  = &amp;#039;Stab defence bonus&amp;#039;,&lt;br /&gt;
        dslash = &amp;#039;Slash defence bonus&amp;#039;,&lt;br /&gt;
        dcrush = &amp;#039;Crush defence bonus&amp;#039;,&lt;br /&gt;
        dmagic = &amp;#039;Magic defence bonus&amp;#039;,&lt;br /&gt;
        drange = &amp;#039;Range defence bonus&amp;#039;,&lt;br /&gt;
        str    = &amp;#039;Strength bonus&amp;#039;,&lt;br /&gt;
        mdmg   = &amp;#039;Magic Damage bonus&amp;#039;,&lt;br /&gt;
        rstr   = &amp;#039;Ranged Strength bonus&amp;#039;,&lt;br /&gt;
        prayer = &amp;#039;Prayer bonus&amp;#039;,&lt;br /&gt;
        weight = &amp;#039;Weight&amp;#039;,&lt;br /&gt;
        image  = &amp;#039;Image&amp;#039;,&lt;br /&gt;
        subobj = &amp;#039;Has subobject&amp;#039;,&lt;br /&gt;
        membs  = &amp;quot;Is members only&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    local query = {}&lt;br /&gt;
&lt;br /&gt;
    -- Build query&lt;br /&gt;
    table.insert(query, string.format(&amp;#039;[[%s]]&amp;#039;, table.concat(pages, &amp;#039; || &amp;#039;)))&lt;br /&gt;
    table.insert(query, &amp;#039;?=#-&amp;#039;)&lt;br /&gt;
    for k, p in pairs(prop) do&lt;br /&gt;
        table.insert(query, string.format(&amp;#039;?%s #- = %s&amp;#039;, p, k))&lt;br /&gt;
    end&lt;br /&gt;
    if #keys &amp;gt; 0 and yesno(keys[1], true) then -- do not sort if keys[1] is &amp;#039;no&amp;#039;&lt;br /&gt;
        local sprops = {}&lt;br /&gt;
        for _, k in ipairs(keys) do&lt;br /&gt;
            table.insert(sprops, prop[k])&lt;br /&gt;
        end&lt;br /&gt;
        query.sort = table.concat(sprops, &amp;#039;, &amp;#039;)&lt;br /&gt;
    end&lt;br /&gt;
    if #orders &amp;gt; 0 then&lt;br /&gt;
        query.order = table.concat(orders, &amp;#039;, &amp;#039;)&lt;br /&gt;
    end&lt;br /&gt;
    query.offset = 0&lt;br /&gt;
    query.limit = 500&lt;br /&gt;
&lt;br /&gt;
    -- Fetch the data&lt;br /&gt;
    -- mw.logObject(query)&lt;br /&gt;
    local t1 = os.clock()&lt;br /&gt;
    local smwdata = mw.smw.ask(query)&lt;br /&gt;
    local t2 = os.clock()&lt;br /&gt;
&lt;br /&gt;
    local smw_max_conditions = 16&lt;br /&gt;
&lt;br /&gt;
    if not smwdata or #smwdata == 0 then&lt;br /&gt;
        if #pages &amp;gt; smw_max_conditions then&lt;br /&gt;
            error(&amp;#039;smw query failed (your table probably have too many items)&amp;#039;)&lt;br /&gt;
        end&lt;br /&gt;
    &lt;br /&gt;
        smwdata = {}&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- Post-process the data&lt;br /&gt;
    if keys[1] and not yesno(keys[1], true) then&lt;br /&gt;
    	smwdata = undoSort(pages, smwdata)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
    local data = {}&lt;br /&gt;
&lt;br /&gt;
    for _, i in ipairs(smwdata) do &lt;br /&gt;
        local dl = i&lt;br /&gt;
        dl.name = dl[1]&lt;br /&gt;
        dl[1] = nil&lt;br /&gt;
        if type(dl.image) == &amp;#039;table&amp;#039; then&lt;br /&gt;
            dl.image = dl.image[1]&lt;br /&gt;
        end&lt;br /&gt;
        table.insert(data, dl)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- Statistics&lt;br /&gt;
    local smwstats = {&lt;br /&gt;
        offset = query.offset,&lt;br /&gt;
        limit  = query.limit,&lt;br /&gt;
        found  = #smwdata,&lt;br /&gt;
        time   = (t2 - t1) * 1000&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    --[[ mw.log(string.format(&amp;#039;SMW: Found %i, offset %i, limit %i, time elapsed %.3f ms.&amp;#039;, &lt;br /&gt;
        smwstats.found, smwstats.offset, smwstats.limit, smwstats.time))&lt;br /&gt;
        --]]&lt;br /&gt;
&lt;br /&gt;
    return data&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Wilderness&gt;Theslamprogram</name></author>
	</entry>
</feed>