Mòdul:NumTableOrder
Aparença
Documentació del mòdul [ mostra ] [ modifica el codi ] [ mostra l'historial ] [ refresca ]
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
S'utilitza en el Mòdul:Chart, per veure el funcionament: {{NumTableOrder/Test}}
Ús
[modifica]{{#invoke:NumTableOrder|nom de la funció}}
local p = {}
local SA = require "Module:SimpleArgs"
--- Numeral to abbreviated ordinal ---
function p.numeralToAbbrevOrdinal (num)
if num == 1 then
return '1r'
elseif num == 2 then
return '2n'
elseif num == 3 then
return '3r'
elseif num == 4 then
return '4t'
else
return num..'è'
end
end --numeralToAbbrevOrdinal
function p.numeralToAbbrevOrdinalF (frame)
local args = SA.GetArgs (frame)
num = SA.PosIntFromArgs (args, 1)
return p.numeralToAbbrevOrdinal(num)
end
local TODV = { --TOnDupliValue
Middle = 1,
First = 2,
Continuous = 3,
Range = 4,
}
function p.SortAnSetOrder (Arr, DescOrder, IdemOrder, OnDupliValue)
local J, Sum, Count, First = 0, 0, 0, 0
local Ord = {}
function SetH ()
local I, Middle = 0, 0
local Val = ''
--begin
if OnDupliValue == TODV.Range then
Val = p.numeralToAbbrevOrdinal(First)..'-'..p.numeralToAbbrevOrdinal(First+Count-1)
elseif OnDupliValue == TODV.Middle then
Val = Sum/Count
if Val == math.floor(Val) then
Val = p.numeralToAbbrevOrdinal(Val)
end
else
Val = p.numeralToAbbrevOrdinal(J)
end
for I = 1, Count do
Ord[J-1+I] = Val
end
Count = 1
end --SetH
local I, K, N = 0, 0, 0
local Arr2, Ord2 = {}, {}
local Num = 0
--begin
if IdemOrder then
Arr2 = {}
for I, V in ipairs (Arr) do
table.insert (Arr2, V)
end
end
if DescOrder then
table.sort (Arr, function(a, b) return a>b end)
else
table.sort (Arr)
end
for I, V in ipairs (Arr) do
table.insert (Ord, p.numeralToAbbrevOrdinal(I))
end
N = #Arr
if OnDupliValue == TODV.Continuous then
J = 0
Num = -100000
for I, V in ipairs (Arr) do
if Num ~= V then
J = J + 1
Num = V
end
Ord[I] = p.numeralToAbbrevOrdinal(J)
end
else
J = 1
while J <= N do
Ord[J] = p.numeralToAbbrevOrdinal(J)
Count = 1
Sum = J
First = J
K = J + 1
while K <= N do
if Arr[J] == Arr[K] then
Count = Count + 1
Sum = Sum + K
K = K + 1
else
if Count > 1 then
SetH()
end
J = K-1
First = J
break
end
end
if Count > 1 then
SetH()
break
else
J = J + 1
end
end
end
if IdemOrder then
Ord2 = {}
for I, V in ipairs (Arr2) do
for K, W in ipairs (Arr) do
if V == W then
table.insert (Ord2, Ord[K])
break
end
end
end
return Arr2, Ord2
else
return Arr, Ord
end
end --SortAnSetOrder
function p.SortAnSetOrderF(frame) --used for examples
local args,Nargs = SA.GetArgs (frame)
local NumTab = SA.NumTabFromArgs(args, 1, ',', 2)
local DescOrder = SA.BoolFromArgs(args, 2)
local IdemOrder = SA.BoolFromArgs(args, 3)
local OnDupliValue = SA.PosIntFromArgs (args, 4, 1, 1, 4)
Arr, Ord = p.SortAnSetOrder (NumTab, DescOrder, IdemOrder, OnDupliValue)
local S = ''
for i, val in ipairs (Arr) do
S = S..Arr[i]..': '..Ord[i]
if i < #Arr then
S = S..' -- '
end
end
return S
end --SortAnSetOrderF
return p