Module:Sandbox/Frietjes
local p = {}
local math_module = require("Module:Math")
local function rnd(num, digits)
-- This function implements {{rnd}}
return math_module._precision_format(tostring(num), digits)
end
function p.ifexists(frame)
page = frame.args[1]
if not page then return (frame.args['no'] or '') end
if mw.title.new(page).exists then return (frame.args['yes'] or 'yes') end
return (frame.args['no'] or '')
end
function p.lists(frame)
local s = '\n' .. (frame.args[1] or '') .. '\n'
s = mw.ustring.gsub(s, '([\r\n])%*([^\r\n]*)', '%1<ul><li>%2</li></ul>')
s = mw.ustring.gsub(s, '([\r\n])#([^\r\n]*)', '%1<ol><li>%2</li></ol>')
s = mw.ustring.gsub(s, '</ol>%s*([\r\n]*)<ol>', '%1')
s = mw.ustring.gsub(s, '</ul>%s*([\r\n]*)<ul>', '%1')
s = mw.ustring.gsub(s, '^[\r\n](.*)[\r\n]$', '%1')
return s
end
function p.precision(frame)
return math_module._precision(frame.args[1])
end
function p.wpct(frame)
local w = tonumber(frame.args[1]) or 0
local l = tonumber(frame.args[2]) or 0
local pct = '–'
if (w + l) > 0 then
pct = rnd(w / (w + l), 3):gsub('^0', '')
end
return pct
end
function p.extractcolor(frame)
local str = frame.args[1] or ''
local color = mw.ustring.match(';' .. str .. ';', '.*;%s*([Cc][Oo][Ll][Oo][Rr]%s*:%s*.-)%s*;')
return color or 'NO MATCH'
end
local function trim(s)
return s:match('^%s*(.-)%s*$')
end
function p.timeline(frame)
local args = frame.args
local width = 600
local height = 340
local scaleminor = 50
local scalemajor = 100
local rawoutput = false
local data = {}
for k, v in pairs(args) do
if type(k) == 'number' then
data[k] = trim(v)
elseif k:find('^width$') then
width = tonumber(v)
elseif k:find('^height$') then
height = tonumber(v)
elseif k:find('^rawoutput$') then
if trim(v) ~= '' then
rawoutput = true
end
end
end
-- find some data limits
local minyear, maxyear, maxpop = 999999, 0, 0
for i = 1, #data, 2 do
local year = tonumber(data[i] or '0')
local pop = tonumber(data[i+1] or '0')
minyear = (year < minyear) and year or minyear
maxyear = (year > maxyear) and year or maxyear
maxpop = (pop > maxpop) and pop or maxpop
end
local logbound = 10^(math.floor(math.log(maxpop)/math.log(10)+1))
local scalemajor = logbound/10
local scaleminor = scalemajor/2
maxpop = scalemajor*(math.floor(maxpop/scalemajor + 1))
local timeline = {
'Colors=',
' id:lightgrey value:gray(0.9)',
' id:darkgrey value:gray(0.3)',
' id:sfondo value:rgb(1,1,1)',
' id:barra value:rgb(0.664, 0.664, 0.930)', -- dark lavender
'',
'ImageSize = width:' .. tostring(width) .. ' height:' .. tostring(height),
'PlotArea = left:44 bottom:40 top:10 right:10',
'DateFormat = x.y',
'Period = from:0 till:' .. tostring(maxpop),
'TimeAxis = orientation:vertical',
'AlignBars = justify',
'ScaleMajor = gridcolor:darkgrey increment:' .. tostring(scalemajor) .. ' start:0',
'ScaleMinor = gridcolor:lightgrey increment:' .. tostring(scaleminor) .. ' start:0',
'BackgroundColors = canvas:sfondo',
'BarData='
}
local yearscale = math.max(math.floor((maxyear - minyear)/10),1)
yearscale = 5*(math.floor(yearscale / 5))
minyear = yearscale*math.floor(minyear/yearscale)
maxyear = yearscale*math.ceil(maxyear/yearscale)
for year = minyear,maxyear do
local text = ( (year % yearscale) == 0) and ' text:' .. year or ''
table.insert(timeline, ' bar:' .. year .. text)
end
table.insert(timeline,'\nPlotData=\n color:barra width:7 align:left\n')
for i = 1, #data, 2 do
local year = data[i] or ''
local pop = data[i+1] or ''
table.insert(timeline, ' bar:' .. year .. ' from: 0 till:' .. pop)
end
-- table.insert(timeline,'\nPlotData=\n')
--for i = 1, #data, 2 do
-- local year = data[i] or ''
-- local pop = data[i+1] or ''
-- table.insert(timeline, ' bar:' .. year .. ' at:' .. pop .. ' fontsize:XS text: ' .. pop .. ' shift:(-8.5)')
-- end
if rawoutput then
return frame:extensionTag{ name = 'pre', content = '\n' .. table.concat(timeline,'\n') .. '\n' }
end
return frame:extensionTag{ name = 'timeline', content = '\n' .. table.concat(timeline,'\n') .. '\n' }
end
local function getBestStatement(item_id, property_id)
if not(item_id) or not(mw.wikibase.isValidEntityId(item_id)) or not(mw.wikibase.entityExists(item_id)) then
return false
end
local statements = mw.wikibase.getBestStatements(item_id, property_id)
if not statements or #statements == 0 then
return false
end
local hasNoValue = ( statements[1].mainsnak and statements[1].mainsnak.snaktype == 'novalue' )
if hasNoValue then
return false
end
return statements[1]
end
function p.hasOSM(frame)
return getBestStatement(mw.wikibase.getEntityIdForCurrentPage(), 'P402') and 'yes' or 'no'
end
function p.chart(frame)
local chart = require('Module:Chart')['bar-chart']
return chart(frame)
end
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame, {parentFirst = true,
valueFunc = function (key, val)
if key == 'text_IPS' then
return nil
end
if type(val) == 'string' then
val = val:match('^%s*(.-)%s*$')
if val == '' then
return nil
else
return val
end
else
return val
end
end
})
local team_list = {}
local ii = 1
while args['team'..ii] ~= nil do
team_list[args['team'..ii]] = ii
ii = ii + 1
end
local max_team = ii - 1
local first_team, last_team = 1, max_team
if args['showteam'] and team_list[args['showteam']] then
first_team = team_list[args['showteam']] - 2
last_team = first_team + 4
if first_team < 1 then
first_team = 1
last_team = first_team + 4
end
if last_team > max_team then
last_team = max_team
first_team = max_team - 4
end
if first_team < 1 then first_team = 1 end
end
local hasnotes = false
local ii = first_team
local res = '{| class="wikitable"\n'
res = res .. '! Pos. !! Team !! Result\n'
while args['team'..ii] ~= nil and (ii <= last_team) do
res = res .. '|-\n'
res = res .. '| ' .. ii .. '\n'
res = res .. '| ' .. (args['name_'..args['team' .. ii]] or '') .. '\n'
local text_result = args['result'..ii] and args['text_'..args['result'..ii]] or ''
local style_text = ''
if text_result:match('fbmulticompefn') then
hasnotes = true
style_text = style_text .. 'padding:0;'
end
style_text = style_text .. (args['result'..ii] and ('background:' .. args['col_'..args['result'..ii]]) or '')
res = res .. '| style="' .. style_text .. '" | ' .. text_result .. '\n'
ii = ii + 1
end
res = res .. '|}'
if hasnotes == true then
res = res .. '<b>Table notes:</b>' .. frame:expandTemplate{ title = 'notelist'}
end
-- Generate tracking
if not args['notracking'] then
-- Step 1: Generate a team and result list
for k,v in pairs(args) do
-- nothing
end
end
return res
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.