Fandom

Wikia Developers Wiki

Global Lua Modules/Autocalctable

< Global Lua Modules

888pages on
this wiki
Add New Page
Talk0 Share
Adds summation/average/min/max values of a column of a table imported from page containing json/module/csv .


Install

Installing modules

To get a brief introduction to lua read the basics page first. On Wikia, one can use modules by either accessing a module remotely or copying all its contents to a Wiki. Modules accessed remotely from dev.wikia are subject to change while 'correctly' copied modules are controlled by a particular wiki.

Using a module "remotely" using Module:Devmodule

Create Module:Devmodule and copy the following code to remotely access modules in dev's repository. See more details in Global Lua Modules/Devmodule.
--[[This imports modules from dev.wikia]]
return require("Dev:Devmodule")

Loading modules remotely from dev.wikia

Create Module:Autocalctable in your wiki and add the following code:
--This loads modules directly from dev.wikia.com
return require("Dev:Autocalctable")

Using Module:Autocalctable in another wiki

To use modules without depending on dev see this page. Create Template:Autocalctable in your wiki and add the following code:
{{#invoke:Autocalctable|main}}

Using template in a page

You can use this module in a page using syntax such as:
{{Autocalctable|main|arg1|arg2}}

Module information

Functions

p.main

Entry point - Creates a table with automatically calculated columns..
Parameters
NameTypepurpose
frametableA scribunto frame.
Return typeReturn purpose
stringA table containing calculated columns.

getTable

Extracts table columns containing numbers..
Parameters
NameTypepurpose
sPagestringA page containing the table e.g Module:Scores.json.
sTypestringThe type of data contained in the page (csv, json, lua) -lua table.
Return typeReturn purpose
stringA table containing calculated columns.

p.createHtmlTable

Creates an html table..
Parameters
NameTypepurpose
arrColumnsstringA column containing numbers.
calculationsstringThe types of calculations to perform (avg, min, max, sum).
Return typeReturn purpose
stringAn html table containing calculated columns.

Syntax

{{#invoke:Autotablecalc|page = pagename|type = datatype|calc = calculationtype}}

Where calc = sum/avg/min/max - can be more than one separated by commas ,e.g.:

  • calc=sum,avg
  • pagename =name of page/module
  • datatype = json or lua or cvs

Example

CodeOutput
{{#invoke:Autocalctable|main|page=Module:Autocalctable/testdata|type=lua|calc=sum}}
toysprice
12310
154
13814
CodeOutput
{{#invoke:Autocalctable|main|page=Module:Autocalctable/testdata|type=lua|calc=sum,avg}}
toysprice
12310
154
13814
697

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.