require('strict')local p = local Date = require('Module:Date')._Datelocal mm = require('Module:Math')
local list = require('Module:Sandbox/Jts1882/Covid/data')local list2 =
p.main = function(frame) local output = "
" .. (covidDeaths or "n/a") .. ' (' .. (dateCases or "missing date") .. ')' endend if 12 then local statements -- don't want a lot of large local objects if countryQid and mw.wikibase.isValidEntityId(countryQid) then -- valid id--item = mw.wikibase.getEntity(countryQid) --if not item then return "Country Qid not found" end -- get population local i=1 statements = nil statements = mw.wikibase.getBestStatements(countryQid, 'P1082') i = 1 --#statements while statements[i] do --while item:getBestStatements('P1082')[i] do local timeStamp local statement = statements[i] --item:getBestStatements('P1082')[i] population = statement.mainsnak.datavalue.value.amount if statement.qualifiers and statement.qualifiers['P585'] and statement.qualifiers['P585'][1]['datavalue'] then timeStamp = statement.qualifiers['P585'][1]['datavalue']['value']['time'] --point in time end datePopulation = "missing" if timeStamp then datePopulation = Date(timeStamp):text("dmy") or "missing" end i=i+1 end end end -- local output = '\n | -\n | ' .. countryName .. ' | ' .. (covidCases or "n/a") .. ' (' .. (dateCases or "missing date") .. ')' .. ' | ' .. (covidDeaths or "n/a") .. ' (' .. (dateDeaths or "missing date") .. ')' .. ' | ' .. (population or "n/a") if covidCases nil then covidCases = 0.001 end if covidDeathsnil then covidDeaths = 0.001 end local output = output .. ' | ' .. mm._precision_format(covidCases/population*1000000,0) .. ' | ' .. mm._precision_format(covidDeaths/population*1000000,0) return output or "no value found" endp.getWikidataPopulation =function(countryQid) local population local datePopulation local statements -- don't want a lot of large local objects if countryQid and mw.wikibase.isValidEntityId(countryQid) then -- valid id --item = mw.wikibase.getEntity(countryQid) --if not item then return "Country Qid not found" end -- get population local i=1 statements = nil statements = mw.wikibase.getBestStatements(countryQid, 'P1082') i = 1 --#statements while statements[i] do --while item:getBestStatements('P1082')[i] do local timeStamp local statement = statements[i] --item:getBestStatements('P1082')[i] population = statement.mainsnak.datavalue.value.amount if statement.qualifiers and statement.qualifiers['P585'] and statement.qualifiers['P585'][1]['datavalue'] then timeStamp = statement.qualifiers['P585'][1]['datavalue']['value']['time'] --point in time end datePopulation = "missing" if timeStamp then datePopulation = Date(timeStamp):text("dmy") or "missing" end i=i+1 end end return (population or "n/a") end return p |