Module:Medical cases chart/data: Difference between revisions

Content deleted Content added
No edit summary
Fixed off-by-one error
 
(5 intermediate revisions by 2 users not shown)
Line 1:
--- Example usage:
--- {{#invoke:Medical cases chart/data|externalData|page=COVID-19 Casescases in Santa Clara County, California.tab|recoveries=hospitalized|cases=totalConfirmedCases}}
--- =p._externalData({datapage="COVID-19 Casescases in Santa Clara County, California.tab",datarecoveries="hospitalized",datacases="totalConfirmedCases"})
 
local p = {}
Line 21:
local change = current / previous * 100 - 100
local sign = change < 0 and "−" or "+"
return mw.ustring.format("%s%s%%", sign, lang:formatNum(round(math.abs(change))))
if (math.abs(change)) >= 10 then
return mw.ustring.format("%s%.0f%%", sign, (math.abs(change)))
end
if (math.abs(change)) < 1 then
return mw.ustring.format("%s%.3f%%", sign, (math.abs(change)))
end
return mw.ustring.format("%s%s.2f%%", sign, lang:formatNum(round(math.abs(change))))
end
 
Line 69 ⟶ 76:
}
local prevRecord = records[#records] or {}
if casesIndex and not prevRecord.cases and record.cases and record.cases > 0 then
record.options.firstright1 = "y"
end
if deathsIndex and prevRecord.deaths == 0 and record.deaths and record.deaths > 0 then
record.options.firstright2 = "y"
end
Line 94 ⟶ 101:
for i = #records, 1, -1 do
local record = records[i]
if i < #records and record.streak > 3 then
for j = i, i - record.streak + 3, -1 do
table.remove(records, j)