Module:Medical cases chart/data: Difference between revisions

Content deleted Content added
An experiment
 
No edit summary
Line 52:
assert(class4Index or not frame.args.class4, "Class 4 field not found.")
assert(class5Index or not frame.args.class5, "Class 5 field not found.")
local records = {}
for i, record in ipairs(data.data) do
table.insert(records, {
prevCasesdate = record[casesIndexdateIndex],
prevDeathsdeaths = deathsIndex and record[deathsIndex],
recoveries = recoveriesIndex and record[recoveriesIndex],
cases = casesIndex and record[casesIndex],
class4 = class4Index and record[class4Index],
class5 = class5Index and record[class5Index],
})
end
local rows = {}
local prevCasesprevRecord = {}
for i, record in ipairs(records) do
local prevDeaths
for i, record in ipairs(data.data) do
local row = {
tostring(record[dateIndex]).date,
deathsIndex and tostring(record[deathsIndex]).deaths or ""),
recoveriesIndex and tostring(record[recoveriesIndex]).recoveries or ""),
casesIndex and tostring(record[casesIndex]).cases or ""),
class4Index and tostring(record[class4Index]).class4 or ""),
class5Index and tostring(record[class5Index]).class5 or ""),
casesIndexrecord.cases and lang:formatNum(record[casesIndex].cases) or "",
casesIndexrecord.cases and formatChange(prevCasesprevRecord.cases, record[casesIndex].cases) or "",
deathsIndexrecord.deaths and lang:formatNum(record[deathsIndex].deaths) or "",
deathsIndexrecord.deaths and formatChange(prevDeathsprevRecord.deaths, record[deathsIndex].deaths) or "",
}
if casesIndex and not prevCasesprevRecord.cases and record[casesIndex].cases > 0 then
table.insert(row, "firstright1=y")
end
if deathsIndex and prevDeathsprevRecord.deaths == 0 and record[deathsIndex].deaths > 0 then
table.insert(row, "firstright2=y")
end
Line 78 ⟶ 89:
table.insert(rows, table.concat(row, ";"))
prevRecord = record
if casesIndex then
prevCases = record[casesIndex]
end
if deathsIndex then
prevDeaths = record[deathsIndex]
end
end
return table.concat(rows, "\n")