Module:BiologicalAgeBiomarkers

Revision as of 00:55, 21 February 2024 by Strimo (talk | contribs) (Replaced content with "local p = {} local data = require('Module:BiologicalAgeBiomarkers/Data') local biomarkers = data.biomarkers local rows = data.rows local studies = data.studies function p.createCrossTable(frame) -- Start of the wiki table local wikitable = '{| class="wikitable"\n!' -- Column headers: Biomarker and System wikitable = wikitable .. ' System !! Biomarker' for _, study in pairs(studies) do wikitable = wikitable .. ' !! ' .. frame:expandTemp...")

Output the biological age biomarkers table.

Data is stored in Module:BiologicalAgeBiomarkers/Data


local p = {}

local data = require('Module:BiologicalAgeBiomarkers/Data')

local biomarkers = data.biomarkers
local rows = data.rows
local studies = data.studies

function p.createCrossTable(frame)
    -- Start of the wiki table
    local wikitable = '{| class="wikitable"\n!'

    -- Column headers: Biomarker and System
    wikitable = wikitable .. ' System !! Biomarker'
    for _, study in pairs(studies) do
        wikitable = wikitable .. ' !! ' .. frame:expandTemplate({title = "pmid", args = { study.pmid }})
	end
	wikitable = wikitable .. '\n'

    for i, row in ipairs(rows) do
        wikitable = wikitable .. '|-\n'
        wikitable = wikitable .. '| ' .. row.name .. ' || ' .. ''
        for _, study in ipairs(studies) do
            local cellValue = study[row.key] or ""
			wikitable = wikitable .. ' || ' .. cellValue
        end
		wikitable = wikitable .. '\n'
	end

    -- Generate rows for each biomarker
    for _, system in ipairs(biomarkers) do
	    for _, bm in ipairs(system.data) do
	        wikitable = wikitable .. '|-\n'
	        wikitable = wikitable .. '| '  .. system.system .. ' || ' .. bm.name
	        for _, study in ipairs(studies) do
	            -- Retrieve data value for the current cell, using the nested structure
	            local cellValue = study.biomarkers[bm.key] or ""
	            wikitable = wikitable .. ' || ' .. cellValue
	        end
			wikitable = wikitable .. '\n'
	    end
    end

    -- End of the table
    wikitable = wikitable .. '\n|}'

    return wikitable
end

return p