Module:SMW: Difference between revisions

From devsummit
No edit summary
No edit summary
Line 16: Line 16:
      
      
     local statements = {};
     local statements = {};
     for k,v in pairs( sessions.results ) do
     for k1,v1 in pairs( sessions.results ) do
         statements[v.fulltext] = mw.smw.getQueryResult( "[[Category:Statements]][[Session::" .. v.fulltext .. "]]" )
         statements[v1.fulltext] = {}
    for k2,v2 in pairs ( mw.smw.getQueryResult( "[[Category:Statements]][[Session::" .. v1.fulltext .. "]]" ) ) do
    statements[v1.fulltext][v2.fulltext] = true
end
     end
     end
      
      
Line 33: Line 36:
     local count = 0
     local count = 0
     for k3,v3 in pairs( statements[v1.fulltext] ) do
     for k3,v3 in pairs( statements[v1.fulltext] ) do
    if ( statements[v2.fulltext][k3] == true ) then
    count = count + 1
end
end
end
result = result .. count
result = result .. count

Revision as of 09:11, 27 November 2017

Documentation for this module may be created at Module:SMW/doc

-- Module:SMW
local p = {}

-- Return results
function p.sessionTable(frame)

    local sessions = mw.smw.getQueryResult( "[[Category:Sessions]]" )

    if sessions == nil then
        return "(no values)"
    end

    if type( sessions ) ~= "table" then
        return "(invalid query result)"
    end
    
    local statements = {};
    for k1,v1 in pairs( sessions.results ) do
        statements[v1.fulltext] = {}
    	for k2,v2 in pairs ( mw.smw.getQueryResult( "[[Category:Statements]][[Session::" .. v1.fulltext .. "]]" ) ) do
    		statements[v1.fulltext][v2.fulltext] = true
		end
    end
    
    local result = "\n{| class='wikitable\n|\n"
    for k1,v1 in pairs( sessions.results ) do
        result = result .. "![[" .. v1.fulltext .. "]]\n"
    end
    for k1,v1 in pairs( sessions.results ) do
        result = result .. "|-\n![[" .. v1.fulltext .. "]]\n"
        for k2,v2 in pairs( sessions.results ) do
        	result = result .. "| style='text-align:center;'|"
        	if v1.fulltext == v2.fulltext then
        		result = result .. "X"
    		else
    			local count = 0
    			for k3,v3 in pairs( statements[v1.fulltext] ) do
    				if ( statements[v2.fulltext][k3] == true ) then
    					count = count + 1
					end
				end
				result = result .. count
    		end
    		result = result .. "\n"
    	end
    end
    result = result .. "|}"

    return result
end

return p