Module:AspectCodesTagCloudDEV

-- DEVELOPMENT!!!

local p = {}

function p.show(frame) if not mw.smw then return "mw.smw module not found" end

local conferenceContributionsQuery = mw.smw.getQueryResult(" \   HasConferenceContributionAspectCode::+ \    |?HasConferenceContributionAspectCode \    |?HasConferenceContributionType \    |?HasConferenceContributionStatus \    |?HasConferenceContributionAuthorName \    |?HasConferenceContributionScheduleDay \    |?HasConferenceContributionStartTime \    |?HasEntityTitle \    |?HasEntityBlurb \    |?HasEntityKeyword \  ") if conferenceContributionsQuery == nil then return "(no values)" end

if type( conferenceContributionsQuery ) == "table" then

local conferenceContributions = {} for k,v in pairs( conferenceContributionsQuery.results ) do     table.insert(conferenceContributions, {        conferenceContribution = v.fulltext,        properties = v.printouts      } ) end

-- Sort by AspectCode conferenceContributionsByAspectCode = {} keywords = {} contributionTypes = {} scheduleDays = {} for k,v in pairs(conferenceContributions) do     page = mw.title.new(v.conferenceContribution) if tableHasKey(conferenceContributionsByAspectCode, v.properties.HasConferenceContributionAspectCode[1].fulltext) then table.insert(conferenceContributionsByAspectCode[v.properties.HasConferenceContributionAspectCode[1].fulltext], {         conferenceContribution = v.conferenceContribution,          properties = v.properties,          content = page:getContent      }) else conferenceContributionsByAspectCode[v.properties.HasConferenceContributionAspectCode[1].fulltext] = end -- KEYWORDS for kwk, kwv in pairs(v.properties.HasEntityKeyword) do       if tableHasKey(keywords, kwv) then keywords[kwv]["vol"] = keywords[kwv]["vol"] + 1 else keywords[kwv] = { vol = 1 } end end -- CONTRIBUTION TYPES if tableHasKey(contributionTypes, v.properties.HasConferenceContributionType[1]) then contributionTypes[v.properties.HasConferenceContributionType[1]]["vol"] = contributionTypes[v.properties.HasConferenceContributionType[1]]["vol"] + 1 else contributionTypes[v.properties.HasConferenceContributionType[1]] = { vol = 1 } end -- SCHEDULE DAYS if v.properties.HasConferenceContributionScheduleDay[1] then if tableHasKey(scheduleDays, v.properties.HasConferenceContributionScheduleDay[1].raw) then scheduleDays[string.sub(v.properties.HasConferenceContributionScheduleDay[1].raw, 3)]["vol"] = scheduleDays[string.sub(v.properties.HasConferenceContributionScheduleDay[1].raw, 3)]["vol"] + 1 else scheduleDays[string.sub(v.properties.HasConferenceContributionScheduleDay[1].raw, 3)] = { vol = 1 } end end

end

aspectCodesData = getAspectCodesData

-- Assemble tag cloud tagCloud = {} maxContributions = getMaxContributions(conferenceContributionsByAspectCode) minContributions = getMinContributions(conferenceContributionsByAspectCode) maxFontSize = 60 minFontSize = 20 for k,v in pairs(conferenceContributionsByAspectCode) do     contributionTitlesList = getContributionTitlesList(v) if aspectCodesData[k] then aspectCodeGroup = aspectCodesData[k][1].properties.HasAspectCodeGroup[1] aspectCodeTitle = aspectCodesData[k][1].properties.HasEntityTitle[1] if aspectCodesData[k][1].properties.HasEntityBlurb[1] then aspectCodeBlurb = aspectCodesData[k][1].properties.HasEntityBlurb[1] else aspectCodeBlurb = "" end else aspectCodeGroup = "" aspectCodeTitle = "" aspectCodeBlurb = "" end tooltip = mw.getCurrentFrame:preprocess( "" ) fontSize = minFontSize + ((table.getn(v) - minContributions) / (maxContributions - minContributions) * (maxFontSize - minFontSize)) table.insert(tagCloud, " \ " .. aspectCodeGroup .. " \ " .. aspectCodeTitle .. "" .. tooltip .. " \ " .. contributionTitlesList .. " \ ") end

legend = " PROMOTE/USE/MONITOR | CONFIGURE/INTEGRATE | SETUP/DEVELOP/MAINTAIN | COMMUNITY  "

if frame.args[1] == "cloud" then return " " .. legend .. " " .. table.concat(tagCloud, '&#32;') .. " "   else --     return table_print(aspectCodesData) --     return table_print(contributionTypes) --     return table_print(conferenceContributionsByAspectCode) return aspectsMap(conferenceContributionsByAspectCode) end end

return conferenceContributionsQuery end

-- HELPER FUNCTIONS

function aspectsMap(conferenceContributionsByAspectCode) -- KEYWORDS keywordNounList = {} keywordVerbList = {} for kwk, kwv in pairsByKeys(keywords) do   fontSize = 13 + ( kwv["vol"] * 2 ) firstCharIsUppercase = string.match(kwk, '^%u') if firstCharIsUppercase == nil then table.insert(keywordVerbList, " ❏  " .. kwk .. " " .. kwv["vol"] .. "") else table.insert(keywordNounList, " ❏ " .. kwk .. " " .. kwv["vol"] .. "") end end -- CONTRIBUTION TYPES contributionTypeList = {} for ctk, ctv in pairsByKeys(contributionTypes) do   table.insert(contributionTypeList, " ❏ " .. ctk .. " " .. ctv["vol"] .. "") end -- SCHEDULE DAYS scheduleDayList = {} for ctk, ctv in pairsByKeys(scheduleDays) do   table.insert(scheduleDayList, " ❏ " .. ctk .. " " .. ctv["vol"] .. "") end mytable = { " ",       "  ",      "", " Infrastructure: SETUP ", getAspectCodeHTML("SE-0"), getAspectCodeHTML("SE-1"), getAspectCodeHTML("SE-2"), " Infrastructure: MAINTAIN ", getAspectCodeHTML("MA-0"), getAspectCodeHTML("MA-1"), getAspectCodeHTML("MA-2"), " Infrastructure: DEVELOP ", getAspectCodeHTML("DE-0"), getAspectCodeHTML("DE-1"), getAspectCodeHTML("DE-2"), " ",     "  "    }  return table.concat(mytable, '') end

function getAspectCodeHTML(ac) if aspectCodesData[ac] then t = { " ",       "" .. ac .. " ",       aspectCodesData[ac][1].properties.HasEntityTitle[1] .. " " .. getAspectCodeTooltip(ac) .. " ",       getContributionTitlesList(conferenceContributionsByAspectCode[ac]), " "   }  else t = {} end return table.concat(t, '') end

function table_print (tt, indent, done) done = done or {} indent = indent or 0 if type(tt) == "table" then local sb = {} for key, value in pairs (tt) do     table.insert(sb, string.rep (" ", indent)) -- indent it      if type (value) == "table" and not done [value] then done [value] = true table.insert(sb, key .. " = {\n"); table.insert(sb, table_print (value, indent + 2, done)) table.insert(sb, string.rep (" ", indent)) -- indent it       table.insert(sb, "}\n"); elseif "number" == type(key) then table.insert(sb, string.format("\"%s\"\n", tostring(value))) else table.insert(sb, string.format( "%s = \"%s\"\n", tostring (key), tostring(value))) end end return table.concat(sb) else return tt .. "\n" end end

function pairsByKeys(t, f) local a = {} for n in pairs(t) do a[#a + 1] = n end table.sort(a, f) local i = 0 return function i = i + 1 return a[i], t[a[i]] end end

function to_string( tbl ) if "nil"       == type( tbl ) then return tostring(nil) elseif "table" == type( tbl ) then return table_print(tbl) elseif "string" == type( tbl ) then return tbl else return tostring(tbl) end end

function tableHasKey(table,key) return table[key] ~= nil end

function getMaxContributions(conferenceContributionsByAspectCode) -- Get max amount of contributions per aspect code max = 0 for k,v in pairs(conferenceContributionsByAspectCode) do   if table.getn(v) > max then max = table.getn(v) end end return max end

function getMinContributions(aspectCodes) -- Get min amount of contributions per aspect code min = 0 for k,v in pairs(aspectCodes) do   if table.getn(v) < min then min = table.getn(v) elseif min == 0 then min = table.getn(v) end end return min end

function getAspectCodesData local aspectCodesDataQuery = mw.smw.getQueryResult(" \   HasAspectCodeGroup::+ \    |?HasAspectCodeGroup \    |?HasEntityTitle \    |?HasEntityBlurb \    |limit=50 \  ") if aspectCodesDataQuery == nil then return "(no values)" end

if type( aspectCodesDataQuery ) == "table" then aspectCodesData = {} for k,v in pairs( aspectCodesDataQuery.results ) do     table.insert(aspectCodesData, {        aspectCode = v.fulltext,        properties = v.printouts      } ) end end

-- Sort by AspectCode aspectCodes = {} for k,v in pairs(aspectCodesData) do   if tableHasKey(aspectCodesData, v.aspectCode) then table.insert(aspectCodes[v.aspectCode], {       properties = v.properties    }) else aspectCodes[v.aspectCode] = end end

return aspectCodes end

function getBackgroundColorForAspectCodeGroup(aspectCode) green = { PROMOTE=true, USE=true, MONITOR=true } blue = { CONFIGURE=true, INTEGRATE=true } red = { SETUP=true, DEVELOP=true, MAINTAIN=true } if green[aspectCode] then return "#BDE4A7" elseif blue[aspectCode] then return "#B5C8F6" elseif red[aspectCode] then return "#FFD57C" else return "#E3EBEB" end end

function getContributionTitlesList(conferenceContributions) if conferenceContributions == nil then return "" end ctl = {} for k,v in pairs(conferenceContributions) do   if v.properties.HasEntityBlurb[1] then hasEntityBlurb = v.properties.HasEntityBlurb[1] else hasEntityBlurb = "" end if v.content[1] then volOfUpvotes = getVolOfUpvotes(v.content) else volOfUpvotes = 0 end -- KEYWORDS theKeywords = {} if v.properties.HasEntityKeyword[1] then for kwk, kwv in pairs(v.properties.HasEntityKeyword) do       table.insert(theKeywords, " " .. kwv .. " ") end end -- AUTHORS theAuthors = {} if v.properties.HasConferenceContributionAuthorName[1] then for ak, av in pairs(v.properties.HasConferenceContributionAuthorName) do       table.insert(theAuthors, " " .. av.fulltext .. " ") end end -- DAYS if v.properties.HasConferenceContributionScheduleDay[1] then scheduleDay = string.sub(v.properties.HasConferenceContributionScheduleDay[1].raw, 3) else scheduleDay = "" end -- START TIME if v.properties.HasConferenceContributionStartTime[1] then startTime = v.properties.HasConferenceContributionStartTime[1] else startTime = "" end tooltip = mw.getCurrentFrame:preprocess( "" ) table.insert(ctl, " " .. v.properties.HasEntityTitle[1] .. " " .. tooltip .. " ( " .. v.properties.HasConferenceContributionType[1] .. ", " .. volOfUpvotes .. " upvotes) by " .. table.concat(theAuthors, "/") .. " " .. table.concat(theKeywords, " - ") .. " " .. scheduleDay .. " at " .. startTime) end return "" .. table.concat(ctl, "") .. "" end

function split(s, delimiter) result = {}; for match in (s..delimiter):gmatch("(.-)"..delimiter) do       table.insert(result, match); end return result; end

function getVolOfUpvotes(content) allUpvotes = split(content, "Upvotes")[2] if allUpvotes then volUpvotes = #split(allUpvotes, "*") else volUpvotes = 1 end return volUpvotes - 1 end

function getAspectCodeTooltip(k) if aspectCodesData[k][1].properties.HasEntityBlurb[1] then aspectCodeBlurb = aspectCodesData[k][1].properties.HasEntityBlurb[1] else aspectCodeBlurb = "" end return mw.getCurrentFrame:preprocess( "" ) end

return p