Module:SMW: Difference between revisions

From devsummit
(=p.sessionTable())
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Module:SMW
local p = {}
local p = {}


-- Return results
function p.sessionTable(frame)
function p.sessionTable(frame)


Line 8: Line 6:


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


     if type( sessions ) ~= "table" then
     local statements = {};
         return "(invalid query result)"
    for k1,v1 in pairs( sessions.results ) do
        statements[v1.fulltext] = {}
        local queryResult = mw.smw.getQueryResult( "[[Category:Statements]][[Session::" .. v1.fulltext .. "]]" )
         local count = 0
    for k2,v2 in pairs ( queryResult.results ) do
    statements[v1.fulltext][v2.fulltext] = true
    count = count + 1
end
statements[v1.fulltext]['count'] = count
     end
     end
      
      
     local statements = {};
     local result = "\n{| class='wikitable\n|\n"
     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 .. "]]" )
         result = result .. "![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\n"
     end
     end
      
     for k1,v1 in pairs( sessions.results ) do
    local myResult = ""
        result = result .. "|-\n![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\n"
    for k,v in pairs( sessions.results ) do
        for k2,v2 in pairs( sessions.results ) do
        myResult = myResult .. "[[" .. v.fulltext .. "]]" .. "<br/>"
        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
     end
    result = result .. "|}"


     return myResult
     return result
end
end


return p
return p

Latest revision as of 11:54, 27 November 2017

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

local p = {}

function p.sessionTable(frame)

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

    if sessions == nil then
        return "no sessions found"
    end

    local statements = {};
    for k1,v1 in pairs( sessions.results ) do
        statements[v1.fulltext] = {}
        local queryResult = mw.smw.getQueryResult( "[[Category:Statements]][[Session::" .. v1.fulltext .. "]]" )
        local count = 0
    	for k2,v2 in pairs ( queryResult.results ) do
    		statements[v1.fulltext][v2.fulltext] = true
    		count = count + 1
		end
		statements[v1.fulltext]['count'] = count
    end
    
    local result = "\n{| class='wikitable\n|\n"
    for k1,v1 in pairs( sessions.results ) do
        result = result .. "![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\n"
    end
    for k1,v1 in pairs( sessions.results ) do
        result = result .. "|-\n![[" .. v1.fulltext .. "]] (" .. statements[v1.fulltext]['count'] .. ")\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