User:4madness/Templates/ParamSum/doc

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search
Information icon-grey.svg
This is a documentation subpage for User:4madness/Templates/ParamSum.
It contains usage information, categories, and other content that is not part of the original template page.
User:4madness/Templates/ParamSum invokes Module:Sandbox/User:4madness/ParamSum using Lua.

The ParamSum template accepts a generated list of values, adds them together and returns a table with the requested sums.

Usage

{{User:4madness/Templates/ParamSum
|data            = <!-- raw data (see below) -->
|selected        = <!-- comma-seperated list of keys to sum together from data -->
|html            = <!-- (Optional) "yes" if html output is desired instead of wikitext table syntax -->
|<somekey> class = <!-- (Optional) class(es) to add to cell containing the sum of <somekey> -->
}}

The parameters |data= and |selected= can also be passed as unnamed parameters.

{{User:4madness/Templates/ParamSum|<!-- data -->|<!-- selected -->|…}}

Parameter details

data

Alias: First unnamed parameter

The value for |data= is expected to be a list of rows delimited by ! symbols with each key=value pair within a row separated by | symbols. For example:

key1=row1value|key2=row1value!key1=row2value|key2=row2value!…

key1=4|key2=5!key1=1|key2=10!key1=8|key2=6!key1=10|key2=4!key1=3|key2=10!…

selected

Alias: Second unnamed parameter

A comma-separated list of keys to sum together. Keys not in this list are skipped and are returned in the same order as given here.

A special key, #, is used to return the number of lines processed.

html (optional)

If set to yes, the returned code will use HTML table cells (<td class="someclass">sum1</td><td class="someotherclass">sum2</td>) instead of wikitext table syntax (class="someclass" | sum1|| class="someotherclass" | sum2).

<somekey> class (optional)

This parameter is used to assign a class or classes to the cell containing the sum of <somekey> values. For the cell containing the sum of all key1 values, use |key1 class=<classdef>. This can be repeated for each key in |selected=.

The value of <classdef> can be an ordinary list of classes or it can be any number of conditional classes.

Conditional Classes
<classdef> Condition Class is added… Result when sum of key1 values is 10
someclass none always |key1 class=someclassclass="someclass" | 10
gt<num>:someclass gt<num> when sum is greater than <num> |key1 class=gt0:someclassclass="someclass" | 10
lt<num>:someclass lt<num> when sum is less than <num> |key1 class=lt0:someclass10
eq<num>:someclass eq<num> when sum is equal to <num> |key1 class=eq10:someclassclass="someclass" | 10
neq<num>:someclass neq<num> when sum is not equal to <num> |key1 class=neq10:someclass10
lteq<num>:someclass lteq<num> when sum is less than or equal to <num> |key1 class=lteq0:someclass10
gteq<num>:someclass gteq<num> when sum is greater than or equal to <num> |key1 class=gteq0:someclassclass="someclass" | 10

For <classdef> values, <num> can be substituted with # to compare against the number of lines processed.

Combining definitions
|key1 class=<classdef> Result when sum of key1 values is 10
|key1 class=someclass gt0:someotherclass class="someclass someotherclass" | 10
|key1 class=lt0:failclass gteq0:successclass class="successclass" | 10
|key1 class=gteq0:positiveclass gteq#:enoughclass Count is 9 → class="positiveclass enoughclass" | 10

Count is 10 → class="positiveclass enoughclass" | 10
Count is 11 → class="positiveclass" | 10

|key1 class=lt#:toofewclass eq#:correctclass gt#:toomanyclass Count is 9 → class="toomanyclass" | 10

Count is 10 → class="correctclass" | 10
Count is 11 → class="toofewclass" | 10

Example

This template is best used with DynamicPageList (DPL) queries to reformat the data for ingestion by this template. To count the number of template calls (e.g. DropsLine) on a given page that use a particular parameter (e.g. "nosmw"), a phantom template can be created (e.g. at "/hasnosmw") with the following content:

hasnosmw={{#if:{{{nosmw|}}}|1|0}}!

The phantom template can then be used in a DPL query to generate the data value for use by this template. To display the result correctly, the template must be wrapped in a table.

{| class="wikitable" style="text-align:center"
|+ DropsLine templates on [[{{{title|}}}]]
|-
! Calls !! Calls w/ <code>nosmw</code>
|-
|{{User:4madness/Templates/ParamSum
  |data     = {{#dpl:title={{{title|}}}|uses=Template:DropsLine|include={DropsLine¦/hasnosmw}|noresultsheader=0|namespace=}}
  |selected = #,hasnosmw
  }}
|}
DropsLine templates on Woman (Canifis)
Calls Calls w/ nosmw
27 27
DropsLine templates on Woman (Canifis)
Calls Calls w/ nosmw
27 20
DropsLine templates on Woman (Canifis)
Calls Calls w/ nosmw
27 0

This can be improved by adding cell highlighting as shown below:

{| class="wikitable" style="text-align:center"
|+ DropsLine templates on [[{{{title|}}}]]
|-
! Calls !! Calls w/ <code>nosmw</code>
|-
|{{User:4madness/Templates/ParamSum
  |data     = {{#dpl:title={{{title|}}}|uses=Template:DropsLine|include={DropsLine¦/hasnosmw}|noresultsheader=0|namespace=}}
  |selected = #,hasnosmw
  |hasnosmw class=eq#:table-bg-green gt0:table-bg-orange lteq0:table-bg-red
  }}
|}
Note regarding colors
The table-bg-* color classes overwrite each other depending on the order they appear in MediaWiki:Common.less/wikitables.less.
They do so in the following order:
  1. table-bg-red (lowest priority)
  2. table-bg-orange
  3. table-bg-yellow
  4. table-bg-green
  5. table-bg-blue
  6. table-bg-purple
  7. table-bg-pink
  8. table-bg-gray
  9. table-bg-grey (highest priority)
DropsLine templates on Woman (Canifis)
Calls Calls w/ nosmw
27 27
DropsLine templates on Woman (Canifis)
Calls Calls w/ nosmw
27 20
DropsLine templates on Woman (Canifis)
Calls Calls w/ nosmw
27 0