Moodul:Mall:Provints
Ilme
Selle mooduli dokumentatsiooni saab kirjutada asukohta Moodul:Mall:Provints/doc.
local wdLoadSuccess, mdlWikidata = pcall(require, "Moodul:Wikidata")
assert (wdLoadSuccess, "Wikidata mooduli laadimine ebaõnnestus.")
local p = {}
local function round(val,decimal)
if (decimal) then
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal)
else
return math.floor(val + 0.5)
end
end
local function population(frame)
local wdParameters = {}
numPop = ""
wdParameters["args"] = nil
wdParameters["args"] = {}
wdParameters["args"][1] = "P1082"
numPop = mdlWikidata.claim(wdParameters) or ""
return numPop
end
function p.area(frame)
local header = frame.args["header"]
local getfullstr = frame.args["getfullstr"]
local wdParameters = {}
strOutput = ""
numArea = ""
strDate = ""
strRefs = ""
areaPID = "P2046"
wdParameters["args"] = nil
wdParameters["args"] = {}
wdParameters["args"][1] = areaPID
numArea = mdlWikidata.claim(wdParameters) or ""
-- kehtivusosa
wdParameters["args"]["qualifier"] = "P518"
wdParameters["args"]["parameter"] = "numeric-id"
strAppliesTo = mdlWikidata.claim(wdParameters) or nil
wdParameters["args"]["qualifier"] = nil
wdParameters["args"]["parameter"] = nil
if strAppliesTo and tonumber(strAppliesTo) ~= 16868672 then
wdParameters["args"][2] = "P518"
wdParameters["args"][3] = "Q16868672"
numArea = mdlWikidata.claim(wdParameters) or ""
end
-- unit km2
wdParameters["args"]["parameter"] = "unit"
strUnit = mdlWikidata.claim(wdParameters) or ""
wdParameters["args"]["parameter"] = nil
if strUnit ~= "Q712226" then
return ""
end
if header or getfullstr then
if header then header = header .. " " else header = "" end
if numArea > 100 then numArea = round(numArea, 0)
else numArea = round(numArea, 1)
end
-- date
wdParameters["args"]["qualifier"] = "P585"
wdParameters["args"]["parameter"] = "time:Y"
strDate = mdlWikidata.claim(wdParameters) or nil
wdParameters["args"]["qualifier"] = nil
wdParameters["args"]["parameter"] = nil
if strDate then
strDate = " <span style=\"font-size:88%\">(" .. strDate .. ")</span>"
else
strDate = ""
end
-- refs
wdParameters["args"]["references"] = "only"
strRefs = mdlWikidata.claim(wdParameters) or ""
local showIcon = require("Moodul:EditAtWikidata").showMessage
local iconParameters = {}
iconParameters["args"] = nil
iconParameters["args"] = {}
iconParameters["args"]["pid"] = areaPID
strOutput = header .. mw.language.getContentLanguage():formatNum( numArea ) .. " km²" .. strDate .. strRefs .. showIcon(iconParameters)
else
strOutput = numArea
end
return strOutput
end
function p.popDensity( frame )
local pop = tonumber(frame.args["pop"])
local area = mw.language.getContentLanguage():parseFormattedNumber( frame.args["area"] )
local header = frame.args["header"]
popDensity = ""
if ( (string.len(frame.args["pop"]) > 0 and not pop)
or (string.len(frame.args["area"]) > 0 and not area) ) then
errorStr = "<span style=\"color:red\">Kontrolli pindala ja rahvaarvu väärtust ([[Mall:Provints#cite note-tihedus-2|?]])</span>[[Kategooria:Parameetrite vead]]"
return errorStr
end
frame.args = {}
if not pop then
pop = tonumber( population(frame) )
end
if not area then
area = tonumber( p.area(frame) )
end
if pop and area then
popDensity = round(pop / area, 1)
if header then
popDensity = header .. " " .. mw.language.getContentLanguage():formatNum( popDensity ) .. " in/km²"
end
end
return popDensity
end
return p