Current Users (by group)

Current Users (by group)

Last modified by Hal Eden on 2009/04/03 15:17

Current Users (by group)

Flash plugin or Javascript are turned off. Activate both and reload to view the mindmap
<% 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?" 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?

for (item in xwiki.searchDocuments(sql)) { def username = xwiki.getUserName(item) def user = xwiki.getUser(item)

//if (user.isUserInGroup("XWiki.DCNM2009")) { usersArray.add(criteria Service.revision Criteria Factory.create Revision Criteria(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(currUser1?) if(revisions.size() > 0) { currUser2?.add(revisions.size()) currUser3? = currUser3? + 1 } else { currUser2?.add(0) } } }

def distanceArray = 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)) { distanceArrayi?prev? = distanceArrayprev?i? }

//calculate distances if(i < (dimension - 1)) { for(next in (i+1)..(dimension - 1)) {

//tanimoto distance //calculate cross product of usersArrayi?2? and usersArraynext?2? def totalShared = 0 for(k in 0..(usersArrayi?2?.size() - 1)) { if(usersArrayi?2?k? != null && usersArraynext?2?k? != null) { if(usersArrayi?2?k? * usersArraynext?2?k? > 0) { totalShared += 1 } } }

def denom = (double)(usersArraynext?3?+ usersArrayi?3? - totalShared) if(denom != 0) { distanceArrayi?next? = totalShared / denom } else { distanceArrayi?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 (distanceArrayi? != null> 0) { def nonzero = distanceArrayi?.inject(0.0) { running, item -> running + item } if (nonzero > 0.0) { def userN = xwiki.getUserName( usersArrayi?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 (distanceArrayi?j? > 0) { def fromUser = xwiki.getUserName(usersArrayi?0?, false); def toUser = xwiki.getUserName(usersArrayj?0?, false); xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor:distanceArrayi?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?" } }

if(request.get("viewtoplsa") != null){ def users = ] def distance Array = [? 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 = .size) { i = 0 while ((this Line = reader.read Line()) != null) { i++ def distance Str = new String Tokenizer(this Line, ",") 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 = rowj?1? def valueN = rowj?0? def k = j-1 while(k >= 0 && rowk?1? < valueC) { rowk + 1?0? = rowk?0? rowk + 1?1? = rowk?1? k = k-1 } rowk+1?0? = valueN rowk+1?1? = valueC }

//prints users' top five connected people if they exist

print usersi-1? + ": " for(j in 0..4) { if(rowj?1? > 0) { if(j > 0) { print ", " } print xwiki.getUserName(rowj?0?) } } println "n"

sortedDistanceMatrix.add(row) } } } else { println "

Show top lsa Relations?" }

if(request.get("genlsa") != null){ def usersArray = ] def distance Array = [? 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 = .size) { i = 0 while ((this Line = reader.read Line()) != null) { i++ def distance Str = new String Tokenizer(this Line, ",") def row = [? j = 0

//for(j in 1..size) { while (distanceStr.hasMoreTokens()) { j++ row.add(users Array[j-1?,Double.parseDouble(distanceStr.nextToken())]) }

//sort the row

for(j in 1..(row.size()-1)) { def valueC = rowj?1? def valueN = rowj?0? def k = j-1 while(k >= 0 && rowk?1? < valueC) { rowk + 1?0? = rowk?0? rowk + 1?1? = rowk?1? k = k-1 } rowk+1?0? = valueN rowk+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 (sortedDistanceMatrixi? != null) { def nonzero = sortedDistanceMatrixi?.inject(0.0) { running, item -> running + item1? } if (nonzero > 0.0) { def userN = xwiki.getUserName( usersArrayi?, false) //userN = user.getProperty("member").value def userdoc = xwiki.getDocument(usersArrayi?) 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 (sortedDistanceMatrixi?j? != null) { if (sortedDistanceMatrixi?j?1? > 0) { def fromUser = xwiki.getUserName(usersArrayi?, false); def toUser = xwiki.getUserName(sortedDistanceMatrixi?j?0?, false); xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor: sortedDistanceMatrixi?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?" }

if(request.get("genlsaxxx") != null){ def usersArray = ] def distance Array = [? 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 = .size) { i = 0 while ((this Line = reader.read Line()) != null) { i++ def distance Str = new String Tokenizer(this Line, ",") 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 (distanceArrayi? != null> 0) { def nonzero = distanceArrayi?.inject(0.0) { running, item -> running + item } if (nonzero > 0.0) { def userN = xwiki.getUserName( usersArrayi?, 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 (distanceArrayi?j? > 0) { def fromUser = xwiki.getUserName(usersArrayi?, false); def toUser = xwiki.getUserName(usersArrayj?, false); xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor:distanceArrayi?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."

}

%>

user relations

Flash plugin or Javascript are turned off. Activate both and reload to view the mindmap
Tags:
Created by Administrator on 2009/03/31 21:16

This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 2.7.1.${buildNumber} - Documentation