Moodul:Mall:Provints: erinevus redaktsioonide vahel
Ilme
Eemaldatud sisu Lisatud sisu
eelisjärk |
jätta ümardamisel koma järel null alles |
||
(ei näidata ühe teise kasutaja 3 vahepealset redaktsiooni) | |||
4. rida: | 4. rida: | ||
local p = {} |
local p = {} |
||
local function |
local function precision_format(num) |
||
local prFormat = require("Moodul:Math")._precision_format |
|||
if (decimal) then |
|||
precision = num > 100 and 0 or num < 1 and 2 or 1 |
|||
return math.floor( (val * 10^decimal) + 0.5) / (10^decimal) |
|||
return prFormat(num, precision) |
|||
else |
|||
return math.floor(val + 0.5) |
|||
end |
|||
end |
end |
||
51. rida: | 49. rida: | ||
end |
end |
||
-- unit km2 |
-- unit ha or km2 |
||
wdParameters["args"]["parameter"] = "unit" |
wdParameters["args"]["parameter"] = "unit" |
||
strUnit = mdlWikidata.claim(wdParameters) or "" |
strUnit = mdlWikidata.claim(wdParameters) or "" |
||
wdParameters["args"]["parameter"] = nil |
wdParameters["args"]["parameter"] = nil |
||
if strUnit |
if numArea and strUnit == "Q35852" then |
||
numArea = numArea / 100 |
|||
elseif strUnit ~= "Q712226" then |
|||
return "" |
|||
end |
end |
||
if header or getfullstr then |
if header or getfullstr then |
||
if header then header = header .. " " else header = "" end |
if header then header = header .. " " else header = "" end |
||
if numArea > 100 then numArea = round(numArea, 0) |
|||
else numArea = round(numArea, 1) |
|||
end |
|||
-- date |
-- date |
||
wdParameters["args"]["qualifier"] = "P585" |
wdParameters["args"]["qualifier"] = "P585" |
||
85. rida: | 82. rida: | ||
iconParameters["args"] = {} |
iconParameters["args"] = {} |
||
iconParameters["args"]["pid"] = areaPID |
iconParameters["args"]["pid"] = areaPID |
||
strOutput = header .. |
strOutput = header .. precision_format(numArea) .. " km²" .. strDate .. strRefs .. showIcon(iconParameters) |
||
else |
else |
||
strOutput = numArea |
strOutput = numArea |
||
114. rida: | 111. rida: | ||
end |
end |
||
if pop and area then |
if pop and area then |
||
popDensity = |
popDensity = pop / area > 0.01 and precision_format(pop / area) or '< 1' |
||
if header then |
if header then |
||
popDensity = header .. " " .. |
popDensity = header .. " " .. popDensity .. " in/km²" |
||
end |
end |
||
end |
end |
Viimane redaktsioon: 19. märts 2024, kell 18:37
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 precision_format(num)
local prFormat = require("Moodul:Math")._precision_format
precision = num > 100 and 0 or num < 1 and 2 or 1
return prFormat(num, precision)
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 ha or km2
wdParameters["args"]["parameter"] = "unit"
strUnit = mdlWikidata.claim(wdParameters) or ""
wdParameters["args"]["parameter"] = nil
if numArea and strUnit == "Q35852" then
numArea = numArea / 100
elseif strUnit ~= "Q712226" then
return ""
end
if header or getfullstr then
if header then header = header .. " " else header = "" 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 .. precision_format(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 = pop / area > 0.01 and precision_format(pop / area) or '< 1'
if header then
popDensity = header .. " " .. popDensity .. " in/km²"
end
end
return popDensity
end
return p