Module:Medical cases chart/data: Difference between revisions

Content deleted Content added
Make more easily callable from other modules
rename "page name" to page to make calling it simpler, prepend arguments with "data" to avoid collisions with arguments for Module:Medical cases chart
Line 1:
--- Example usage:
--- {{#invoke:Module:Medical cases chart/data|externalData|page name=COVID-19 Cases in Santa Clara County, California.tab|recoveries=hospitalized|cases=totalConfirmedCases}}
--- =p._externalData({["page name"]datapage="COVID-19 Cases in Santa Clara County, California.tab",recoveriesdatarecoveries="hospitalized",casesdatacases="totalConfirmedCases"})
 
local p = {}
Line 25:
 
function p._externalData(args)
local data = mw.ext.data.get(args["page name"].datapage)
local dateIndex
Line 34:
local class5Index
for i, field in ipairs(data.schema.fields) do
if field.name == "date" or field.name == args.datedatadate then
dateIndex = i
elseif field.name == "deaths" or field.name == args.deathsdatadeaths then
deathsIndex = i
elseif field.name == "recoveries" or field.name == args.recoveriesdatarecoveries then
recoveriesIndex = i
elseif field.name == "cases" or field.name == args.casesdatacases then
casesIndex = i
elseif field.name == "class4" or field.name == args.class4dataclass4 then
class4Index = i
elseif field.name == "class5" or field.name == args.class5dataclass5 then
class5Index = i
end
end
assert(dateIndex, "Date field not found.")
assert(deathsIndex or not args.deathsdatadeaths, "Deaths field not found.")
assert(recoveriesIndex or not args.recoveriesdatarecoveries, "Recoveries field not found.")
assert(casesIndex or not args.casesdatacases, "Cases field not found.")
assert(class4Index or not args.class4dataclass4, "Class 4 field not found.")
assert(class5Index or not args.class5dataclass5, "Class 5 field not found.")
-- Restructure the data as tables with keys.
Line 131:
 
function p.externalData(frame)
local args = {}
return p._externalData(frame.args)
for k,v in pairs(frame.args) do
if (v or '') ~= '' then
args['data'..k] = v
end
end
return p._externalData(frame.args)
end
return p