General Actions:
Log-in
Wiki:
CreativeIT
▼
:
Document Index
»
Space:
XWiki
▼
:
Document Index
»
Page:
GraphGearTest
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Current Users (by group)
Wiki source code of
Current Users (by group)
Last modified by
Hal Eden
on 2009/04/03 15:17
Content
·
Comments
(0)
·
Attachments
(7)
·
History
·
Information
Show line numbers
#macro(graphgearmap $mapname) <link href=$doc.getAttachmentURL("slider.css") rel="stylesheet" type="text/css" /> <script type="text/javascript" src="$doc.getAttachmentURL('swfobject.js')"> </script> <script type="text/javascript" src="$doc.getAttachmentURL('mootools.js')"> </script> <script type="text/javascript" src="$doc.getAttachmentURL('slider.js')"> </script> <script type="text/javascript" src="$doc.getAttachmentURL('graphgear.js')"> </script> <div id="gearspace_$mapname" style="width:100%; height:750px"> Flash plugin or Javascript are turned off. Activate both and reload to view the mindmap </div> <script language="JavaScript"> var flashMovie; function init() { if (document.getElementById) { flashMovie = document.getElementById("graphgear"); } } function jsLiveXML() { var xml = document.liveXml.liveXmlArea.value; flashMovie.liveXML(xml); } function switchGravity(num) { flashMovie.changeProperty("GRAVITY", num); } function setSegmentLength(num) { flashMovie.changeProperty("idealSegmentLength", num); } function setBounce(num) { flashMovie.changeProperty("SPRINGK", num); } function setRepel(num) { flashMovie.changeProperty("REPELK", num); } function addRandomNode() { flashMovie.addRandomNode(); } window.onload = init; </script> <script type="text/javascript"> var so = new SWFObject("$doc.getAttachmentURL("GraphGear.swf")", "graphgear", "100%", "100%", "8"); so.addVariable("graphXMLFile", "$doc.getAttachmentURL($mapname)"); // rename to your xml file so.addVariable("idealSegmentLength", 100); so.addVariable("REPELK", 50); so.addVariable("SPRINGK", 30); so.addVariable("action", "center"); so.addParam("allowScriptAccess", "always"); so.addParam("scale", "showall"); so.addParam("salign", "tl"); so.write("gearspace_$mapname"); </script> #end $xwiki.jsx.use("XWiki.GraphGearTest") 1 Current Users (by group) #graphgearmap("groupmap.xml") <% import java.io.StringReader import java.util.HashMap import com.xpn.xwiki.doc.XWikiAttachment import groovy.xml.MarkupBuilder if (xwiki.hasAdminRights()) { println "[Update the Group Map>" + doc.fullName + "?updategm=1]" if (request.get("updategm") != null) { print "Start mindmap generation... " def sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='XWiki.XWikiGroups'" def writer = new StringWriter() def xmlBuilder = new MarkupBuilder(writer) def nodes = [] xmlBuilder.graph (title: "User Map", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725") { xmlBuilder.node (id: "root", text:"Groups", color:"ffffff") for (item in xwiki.searchDocuments(sql)) { def groupdoc = xwiki.getDocument(item) xmlBuilder.node(id: groupdoc.getName(), text:groupdoc.getName(), color:"cccccc") xmlBuilder.edge(sourceNode: "root", targetNode: groupdoc.getName(), label:"") def users = groupdoc.getObjects("XWiki.XWikiGroups") for (user in users) { def hgapcount = 0 def totalCount = users.size() def userName = xwiki.getUserName(user.getProperty("member").value) userName = user.getProperty("member").value def userdoc = xwiki.getDocument(userName) if (userdoc != null) { def attachCount = userdoc.attachmentList.size() def attachIndex = attachCount - 1 def nodeURL = userdoc.getURL() def nodeHtml = xwiki.getUserName(userName, false) def userN = nodeHtml def obj = userdoc.getObject("XWiki.XWikiUsers") def attachURL = "" if (obj != null) { def lastname = obj.get("last_name") def firstname = obj.get('first_name') nodeHtml = firstname + ' ' + lastname } if (attachCount >0){ def attach = userdoc.attachmentList.get(0) attachURL = userdoc.getAttachmentURL(attach.filename,"download") + "?width=90" } if (! nodes.contains(userName)) { nodes.add(userName) xmlBuilder.node(id: userN, text: nodeHtml, color:"aaaaaa", image: attachURL, link: nodeURL) } xmlBuilder.edge(sourceNode: groupdoc.getName(), targetNode: userN, label:"") } } } } def attachmentName = "groupmap.xml" def attachment = doc.getDocument().getAttachment(attachmentName) if (!attachment){ attachment = new XWikiAttachment(doc.getDocument(), attachmentName) doc.getDocument().getAttachmentList().add(attachment) } attachment.setContent(writer.toString().getBytes()) doc.getDocument().saveAttachmentContent(attachment, context.getContext()) doc.save() println "done" response.sendRedirect(xwiki.getURL(doc.getName(),"view")) } } %> <% import java.util.StringTokenizer import java.util.HashMap import com.xpn.xwiki.doc.XWikiAttachment import groovy.xml.MarkupBuilder if (xwiki.hasAdminRights()) { if(request.get("updaterelations") != null) { //common edits user relations def sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='XWiki.XWikiUsers'" def usersArray = [] for (item in xwiki.searchDocuments(sql)) { def username = xwiki.getUserName(item) def user = xwiki.getUser(item) //if (user.isUserInGroup("XWiki.DCNM2009")) { usersArray.add([item, xwiki.criteriaService.revisionCriteriaFactory.createRevisionCriteria(item), [], 0]) //} } sql = ", BaseObject as obj" def test = 0 for (item in xwiki.searchDocuments(sql)) { def currDocument = xwiki.getDocument(item) //checks if each user has editing this doc for(currUser in usersArray) { def revisions = currDocument.getRevisions(currUser[1]) if(revisions.size() > 0) { currUser[2].add(revisions.size()) currUser[3] = currUser[3] + 1 } else { currUser[2].add(0) } } } def distanceArray = [] def dimension = usersArray.size() for(i in 0..(dimension - 1)) { def row = new double[dimension] distanceArray.add(row) //fill in previously calculated distances (symmetric matrix) for(prev in 0..(i-1)) { distanceArray[i][prev] = distanceArray[prev][i] } //calculate distances if(i < (dimension - 1)) { for(next in (i+1)..(dimension - 1)) { //tanimoto distance //calculate cross product of usersArray[i][2] and usersArray[next][2] def totalShared = 0 for(k in 0..(usersArray[i][2].size() - 1)) { if(usersArray[i][2][k] != null && usersArray[next][2][k] != null) { if(usersArray[i][2][k] * usersArray[next][2][k] > 0) { totalShared += 1 } } } def denom = (double)(usersArray[next][3]+ usersArray[i][3] - totalShared) if(denom != 0) { distanceArray[i][next] = totalShared / denom } else { distanceArray[i][next] = 0 } } } } //write out connection matrix to an attachment def writer = new StringWriter() def xmlBuilder = new MarkupBuilder(writer) xmlBuilder.graph (title: "User Map", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725"){ for(i in 0..(usersArray.size()-1)) { if (distanceArray[i] != null> 0) { def nonzero = distanceArray[i].inject(0.0) { running, item -> running + item } if (nonzero > 0.0) { def userN = xwiki.getUserName( usersArray[i][0], false) xmlBuilder.node(id: userN, text: userN, color:"aaaaaa", nonzero:nonzero) } } } for(i in 0..(distanceArray.size()-2)) { for(j in (i+1)..(distanceArray.size()-1)) { if (distanceArray[i][j] > 0) { def fromUser = xwiki.getUserName(usersArray[i][0], false); def toUser = xwiki.getUserName(usersArray[j][0], false); xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor:distanceArray[i][j], label:"") } } } } def attachmentName = "userdistances.xml" def attachment = doc.getDocument().getAttachment(attachmentName) if (!attachment){ attachment = new XWikiAttachment(doc.getDocument(), attachmentName) doc.getDocument().getAttachmentList().add(attachment) } attachment.setContent(writer.toString().getBytes()) doc.getDocument().saveAttachmentContent(attachment, context.getContext()) doc.save() println "Finished updating user relations." } else { println "[Update the User Relations>" + doc.fullName + "?updaterelations=1]" } } if(request.get("viewtoplsa") != null){ def users = [] def distanceArray = [] def attachmentName = "lsa-creativeit2.csv" def attachment = doc.getAttachment(attachmentName) if (!attachment){ println "No lsa file found." } else { def content = attachment.getContentAsString() def reader = new BufferedReader(new StringReader(content)) def userListStr = new StringTokenizer(reader.readLine(), ",") // for(i in 1..size) { while (userListStr.hasMoreTokens()) { users.add(userListStr.nextToken()) } def sortedDistanceMatrix = [] //for(i in 1..size) { i = 0 while ((thisLine = reader.readLine()) != null) { i++ def distanceStr = new StringTokenizer(thisLine, ",") def row = [] j = 0 //for(j in 1..size) { while (distanceStr.hasMoreTokens()) { j++ row.add([users[j-1],Double.parseDouble(distanceStr.nextToken())]) } //sort the row for(j in 1..(row.size()-1)) { def valueC = row[j][1] def valueN = row[j][0] def k = j-1 while(k >= 0 && row[k][1] < valueC) { row[k + 1][0] = row[k][0] row[k + 1][1] = row[k][1] k = k-1 } row[k+1][0] = valueN row[k+1][1] = valueC } //prints users' top five connected people if they exist print users[i-1] + ": " for(j in 0..4) { if(row[j][1] > 0) { if(j > 0) { print ", " } print xwiki.getUserName(row[j][0]) } } println "\n" sortedDistanceMatrix.add(row) } } } else { println "\\\\[Show top lsa Relations>" + doc.fullName + "?viewtoplsa=1]" } if(request.get("genlsa") != null){ def usersArray = [] def distanceArray = [] def attachmentName = "lsa-creativeit2.csv" def attachment = doc.getAttachment(attachmentName) if (!attachment){ println "No lsa file found." } else { def content = attachment.getContentAsString() def reader = new BufferedReader(new StringReader(content)) def userListStr = new StringTokenizer(reader.readLine(), ",") // for(i in 1..size) { while (userListStr.hasMoreTokens()) { usersArray.add(userListStr.nextToken()) } def sortedDistanceMatrix = [] //for(i in 1..size) { i = 0 while ((thisLine = reader.readLine()) != null) { i++ def distanceStr = new StringTokenizer(thisLine, ",") def row = [] j = 0 //for(j in 1..size) { while (distanceStr.hasMoreTokens()) { j++ row.add([usersArray[j-1],Double.parseDouble(distanceStr.nextToken())]) } //sort the row for(j in 1..(row.size()-1)) { def valueC = row[j][1] def valueN = row[j][0] def k = j-1 while(k >= 0 && row[k][1] < valueC) { row[k + 1][0] = row[k][0] row[k + 1][1] = row[k][1] k = k-1 } row[k+1][0] = valueN row[k+1][1] = valueC } sortedDistanceMatrix.add(row) } //write out connection matrix to an attachment def writer = new StringWriter() def xmlBuilder = new MarkupBuilder(writer) xmlBuilder.graph (title: "Profile Closeness", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725"){ for(i in 0..(usersArray.size()-1)) { if (sortedDistanceMatrix[i] != null) { def nonzero = sortedDistanceMatrix[i].inject(0.0) { running, item -> running + item[1] } if (nonzero > 0.0) { def userN = xwiki.getUserName( usersArray[i], false) //userN = user.getProperty("member").value def userdoc = xwiki.getDocument(usersArray[i]) if (userdoc != null) { def attachCount = userdoc.attachmentList.size() def attachIndex = attachCount - 1 def nodeURL = userdoc.getURL() def nodeHtml = xwiki.getUserName(userN, false) userN = nodeHtml def obj = userdoc.getObject("XWiki.XWikiUsers") def attachURL = "" if (obj != null) { def lastname = obj.get("last_name") def firstname = obj.get('first_name') nodeHtml = firstname + ' ' + lastname } if (attachCount >0){ def attach = userdoc.attachmentList.get(0) attachURL = userdoc.getAttachmentURL(attach.filename,"download") + "?width=90" } xmlBuilder.node(id: userN, text: nodeHtml, color:"aaaaaa", image: attachURL, link: nodeURL, nonzero: nonzero) } //xmlBuilder.node(id: userN, text: userN, color:"aaaaaa", nonzero:nonzero) } } } for(i in 0..(sortedDistanceMatrix.size()-1)) { for(j in 1..5) { if (sortedDistanceMatrix[i][j] != null) { if (sortedDistanceMatrix[i][j][1] > 0) { def fromUser = xwiki.getUserName(usersArray[i], false); def toUser = xwiki.getUserName(sortedDistanceMatrix[i][j][0], false); xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor: sortedDistanceMatrix[i][j][1], label:"") } } } } } def outAttachmentName = "lsadistances.xml" def outAttachment = doc.getDocument().getAttachment(outAttachmentName) if (!outAttachment){ outAttachment = new XWikiAttachment(doc.getDocument(), outAttachmentName) doc.getDocument().getAttachmentList().add(outAttachment) } outAttachment.setContent(writer.toString().getBytes()) doc.getDocument().saveAttachmentContent(outAttachment, context.getContext()) doc.save() println "Finished updating lsa relations." } } else { println "\\\\[generate graph for lsa Relations>" + doc.fullName + "?genlsa=1]" } if(request.get("genlsaxxx") != null){ def usersArray = [] def distanceArray = [] def attachmentName = "lsa-creativeit2.csv" def attachment = doc.getAttachment(attachmentName) if (!attachment){ println "No lsa file found." } else { def content = attachment.getContentAsString() def reader = new BufferedReader(new StringReader(content)) def userListStr = new StringTokenizer(reader.readLine(), ",") // for(i in 1..size) { while (userListStr.hasMoreTokens()) { usersArray.add(userListStr.nextToken()) } def sortedDistanceMatrix = [] //for(i in 1..size) { i = 0 while ((thisLine = reader.readLine()) != null) { i++ def distanceStr = new StringTokenizer(thisLine, ",") def row = [] j = 0 //for(j in 1..size) { while (distanceStr.hasMoreTokens()) { j++ row.add(Double.parseDouble(distanceStr.nextToken())) } distanceArray.add(row) } } //write out connection matrix to an attachment def writer = new StringWriter() def xmlBuilder = new MarkupBuilder(writer) xmlBuilder.graph (title: "User Map", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725"){ for(i in 0..(usersArray.size()-1)) { if (distanceArray[i] != null> 0) { def nonzero = distanceArray[i].inject(0.0) { running, item -> running + item } if (nonzero > 0.0) { def userN = xwiki.getUserName( usersArray[i], false) xmlBuilder.node(id: userN, text: userN, color:"aaaaaa", nonzero:nonzero) } } } for(i in 0..(distanceArray.size()-2)) { for(j in (i+1)..(distanceArray.size()-1)) { if (distanceArray[i][j] > 0) { def fromUser = xwiki.getUserName(usersArray[i], false); def toUser = xwiki.getUserName(usersArray[j], false); xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor:distanceArray[i][j], label:"") } } } } def outAttachmentName = "lsadistances.xml" def outAttachment = doc.getDocument().getAttachment(outAttachmentName) if (!outAttachment){ outAttachment = new XWikiAttachment(doc.getDocument(), outAttachmentName) doc.getDocument().getAttachmentList().add(outAttachment) } outAttachment.setContent(writer.toString().getBytes()) doc.getDocument().saveAttachmentContent(outAttachment, context.getContext()) doc.save() println "Finished updating lsa relations." } %> 1 user relations #graphgearmap("lsadistances.xml")
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey