Module:BiologicalAgeBiomarkers: Difference between revisions

    From Longevity Wiki
    No edit summary
    No edit summary
    Line 13: Line 13:
    function p.createCrossTable(frame)
    function p.createCrossTable(frame)
         -- Start of the wiki table
         -- Start of the wiki table
         local wikitable = '{| class="wikitable sortable"\n!'
         local wikitable = '{| class="wikitable sortable"\n'


         -- Column headers: Biomarker and System
         -- Column headers: Biomarker and System
         wikitable = wikitable .. ' System !! Biomarker !! Count '
         wikitable = wikitable .. '! System !! Biomarker !! Count '
         for _, study in pairs(studies) do
         for _, study in pairs(studies) do
             wikitable = wikitable .. ' !! ' .. p.template(frame, "pmid", study.pmid)
             wikitable = wikitable .. ' !! ' .. p.template(frame, "pmid", study.pmid)
    Line 24: Line 24:
         for i, row in ipairs(rows) do
         for i, row in ipairs(rows) do
             wikitable = wikitable .. '|-\n'
             wikitable = wikitable .. '|-\n'
             wikitable = wikitable .. '! ' .. row.name .. '\n'
             wikitable = wikitable .. '! rowspan="2" | ' .. row.name .. '\n'
    wikitable = wikitable .. '!\n'
             for _, study in ipairs(studies) do
             for _, study in ipairs(studies) do
                 local cellValue = study[row.key] or ""
                 local cellValue = study[row.key] or ""

    Revision as of 01:45, 21 February 2024

    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.template(frame, name, arg)
    	return frame:expandTemplate({title = name, args = { arg }})
    end
    
    function p.createCrossTable(frame)
        -- Start of the wiki table
        local wikitable = '{| class="wikitable sortable"\n'
    
        -- Column headers: Biomarker and System
        wikitable = wikitable .. '! System !! Biomarker !! Count '
        for _, study in pairs(studies) do
            wikitable = wikitable .. ' !! ' .. p.template(frame, "pmid", study.pmid)
    	end
    	wikitable = wikitable .. '\n'
    
        for i, row in ipairs(rows) do
            wikitable = wikitable .. '|-\n'
            wikitable = wikitable .. '! rowspan="2" | ' .. row.name .. '\n'
            for _, study in ipairs(studies) do
                local cellValue = study[row.key] or ""
    			wikitable = wikitable .. '! ' .. p.template(frame, "VerticalText", cellValue) .. '\n'
            end
    	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
    	        
    	        local count = 0
    	        for _, study in ipairs(studies) do
    	        	if study.biomarkers[bm.key] ~= nil then
        				count = count + 1
    	        	end
    			end
    	        wikitable = wikitable .. string.format(' || %d', count)
    	        
    	        for _, study in ipairs(studies) do
    	            -- Retrieve data value for the current cell, using the nested structure
    	            local cellValue = study.biomarkers[bm.key] or ""
    	        	if cellValue == "x" then
    	        		cellValue = 'style="background-color:gray; color: transparent;" | ' .. cellValue
    	        	elseif cellValue ~= "" then
    	        		cellValue = 'style="background-color:gray;" | ' .. cellValue
        	        end
     	            wikitable = wikitable .. ' || ' .. cellValue
    	        end
    			wikitable = wikitable .. '\n'
    	    end
        end
    
        -- End of the table
        wikitable = wikitable .. '\n|}'
    
        return wikitable
    end
    
    return p