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
Hide line numbers
1: #macro(graphgearmap $mapname) 2: <link href=$doc.getAttachmentURL("slider.css") rel="stylesheet" type="text/css" /> 3: <script type="text/javascript" 4: src="$doc.getAttachmentURL('swfobject.js')"> 5: </script> 6: <script type="text/javascript" 7: src="$doc.getAttachmentURL('mootools.js')"> 8: </script> 9: <script type="text/javascript" 10: src="$doc.getAttachmentURL('slider.js')"> 11: </script> 12: <script type="text/javascript" 13: src="$doc.getAttachmentURL('graphgear.js')"> 14: </script> 15: <div id="gearspace_$mapname" style="width:100%; height:750px"> 16: Flash plugin or Javascript are turned off. 17: Activate both and reload to view the mindmap 18: </div> 19: <script language="JavaScript"> 20: var flashMovie; 21: function init() { 22: if (document.getElementById) { 23: flashMovie = document.getElementById("graphgear"); 24: } 25: } 26: function jsLiveXML() { 27: var xml = document.liveXml.liveXmlArea.value; 28: flashMovie.liveXML(xml); 29: } 30: function switchGravity(num) { 31: flashMovie.changeProperty("GRAVITY", num); 32: } 33: function setSegmentLength(num) { 34: flashMovie.changeProperty("idealSegmentLength", num); 35: } 36: function setBounce(num) { 37: flashMovie.changeProperty("SPRINGK", num); 38: } 39: function setRepel(num) { 40: flashMovie.changeProperty("REPELK", num); 41: } 42: function addRandomNode() { 43: flashMovie.addRandomNode(); 44: } 45: window.onload = init; 46: </script> 47: <script type="text/javascript"> 48: var so = new SWFObject("$doc.getAttachmentURL("GraphGear.swf")", "graphgear", "100%", "100%", "8"); 49: so.addVariable("graphXMLFile", "$doc.getAttachmentURL($mapname)"); // rename to your xml file 50: so.addVariable("idealSegmentLength", 100); 51: so.addVariable("REPELK", 50); 52: so.addVariable("SPRINGK", 30); 53: so.addVariable("action", "center"); 54: so.addParam("allowScriptAccess", "always"); 55: so.addParam("scale", "showall"); 56: so.addParam("salign", "tl"); 57: so.write("gearspace_$mapname"); 58: </script> 59: #end 60: $xwiki.jsx.use("XWiki.GraphGearTest") 61: 1 Current Users (by group) 62: #graphgearmap("groupmap.xml") 63: <% 64: import java.io.StringReader 65: import java.util.HashMap 66: import com.xpn.xwiki.doc.XWikiAttachment 67: import groovy.xml.MarkupBuilder 68: 69: if (xwiki.hasAdminRights()) 70: { 71: println "[Update the Group Map>" + doc.fullName + "?updategm=1]" 72: if (request.get("updategm") != null) 73: { 74: print "Start mindmap generation... " 75: 76: def sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='XWiki.XWikiGroups'" 77: def writer = new StringWriter() 78: def xmlBuilder = new MarkupBuilder(writer) 79: def nodes = [] 80: 81: xmlBuilder.graph (title: "User Map", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725") { 82: xmlBuilder.node (id: "root", text:"Groups", color:"ffffff") 83: for (item in xwiki.searchDocuments(sql)) { 84: def groupdoc = xwiki.getDocument(item) 85: xmlBuilder.node(id: groupdoc.getName(), text:groupdoc.getName(), color:"cccccc") 86: xmlBuilder.edge(sourceNode: "root", targetNode: groupdoc.getName(), label:"") 87: def users = groupdoc.getObjects("XWiki.XWikiGroups") 88: for (user in users) { 89: def hgapcount = 0 90: def totalCount = users.size() 91: def userName = xwiki.getUserName(user.getProperty("member").value) 92: userName = user.getProperty("member").value 93: def userdoc = xwiki.getDocument(userName) 94: if (userdoc != null) { 95: def attachCount = userdoc.attachmentList.size() 96: def attachIndex = attachCount - 1 97: def nodeURL = userdoc.getURL() 98: def nodeHtml = xwiki.getUserName(userName, false) 99: def userN = nodeHtml 100: def obj = userdoc.getObject("XWiki.XWikiUsers") 101: def attachURL = "" 102: if (obj != null) { 103: def lastname = obj.get("last_name") 104: def firstname = obj.get('first_name') 105: nodeHtml = firstname + ' ' + lastname 106: } 107: 108: if (attachCount >0){ 109: def attach = userdoc.attachmentList.get(0) 110: attachURL = userdoc.getAttachmentURL(attach.filename,"download") + "?width=90" 111: } 112: if (! nodes.contains(userName)) { 113: nodes.add(userName) 114: xmlBuilder.node(id: userN, text: nodeHtml, color:"aaaaaa", image: attachURL, link: nodeURL) 115: } 116: xmlBuilder.edge(sourceNode: groupdoc.getName(), targetNode: userN, label:"") 117: } 118: } 119: } 120: } 121: def attachmentName = "groupmap.xml" 122: def attachment = doc.getDocument().getAttachment(attachmentName) 123: if (!attachment){ 124: attachment = new XWikiAttachment(doc.getDocument(), attachmentName) 125: doc.getDocument().getAttachmentList().add(attachment) 126: } 127: 128: attachment.setContent(writer.toString().getBytes()) 129: doc.getDocument().saveAttachmentContent(attachment, context.getContext()) 130: doc.save() 131: 132: println "done" 133: response.sendRedirect(xwiki.getURL(doc.getName(),"view")) 134: } 135: } 136: 137: %> 138: <% 139: import java.util.StringTokenizer 140: import java.util.HashMap 141: import com.xpn.xwiki.doc.XWikiAttachment 142: import groovy.xml.MarkupBuilder 143: 144: if (xwiki.hasAdminRights()) { 145: if(request.get("updaterelations") != null) { 146: //common edits user relations 147: def sql = ", BaseObject as obj where obj.name=doc.fullName and obj.className='XWiki.XWikiUsers'" 148: def usersArray = [] 149: 150: for (item in xwiki.searchDocuments(sql)) { 151: def username = xwiki.getUserName(item) 152: def user = xwiki.getUser(item) 153: 154: //if (user.isUserInGroup("XWiki.DCNM2009")) { 155: usersArray.add([item, xwiki.criteriaService.revisionCriteriaFactory.createRevisionCriteria(item), [], 0]) 156: //} 157: } 158: 159: sql = ", BaseObject as obj" 160: 161: def test = 0 162: 163: for (item in xwiki.searchDocuments(sql)) { 164: 165: def currDocument = xwiki.getDocument(item) 166: //checks if each user has editing this doc 167: for(currUser in usersArray) { 168: def revisions = currDocument.getRevisions(currUser[1]) 169: if(revisions.size() > 0) { 170: currUser[2].add(revisions.size()) 171: currUser[3] = currUser[3] + 1 172: } 173: else { 174: currUser[2].add(0) 175: } 176: } 177: } 178: 179: def distanceArray = [] 180: def dimension = usersArray.size() 181: for(i in 0..(dimension - 1)) { 182: def row = new double[dimension] 183: distanceArray.add(row) 184: 185: //fill in previously calculated distances (symmetric matrix) 186: for(prev in 0..(i-1)) { 187: distanceArray[i][prev] = distanceArray[prev][i] 188: } 189: 190: //calculate distances 191: if(i < (dimension - 1)) { 192: for(next in (i+1)..(dimension - 1)) { 193: 194: //tanimoto distance 195: //calculate cross product of usersArray[i][2] and usersArray[next][2] 196: def totalShared = 0 197: for(k in 0..(usersArray[i][2].size() - 1)) { 198: if(usersArray[i][2][k] != null && usersArray[next][2][k] != null) { 199: if(usersArray[i][2][k] * usersArray[next][2][k] > 0) { 200: totalShared += 1 201: } 202: } 203: } 204: 205: def denom = (double)(usersArray[next][3]+ usersArray[i][3] - totalShared) 206: if(denom != 0) { 207: distanceArray[i][next] = totalShared / denom 208: } else { 209: distanceArray[i][next] = 0 210: } 211: } 212: } 213: } 214: 215: //write out connection matrix to an attachment 216: def writer = new StringWriter() 217: def xmlBuilder = new MarkupBuilder(writer) 218: 219: xmlBuilder.graph (title: "User Map", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725"){ 220: 221: for(i in 0..(usersArray.size()-1)) { 222: if (distanceArray[i] != null> 0) { 223: def nonzero = distanceArray[i].inject(0.0) { running, item -> running + item } 224: if (nonzero > 0.0) { 225: def userN = xwiki.getUserName( usersArray[i][0], false) 226: xmlBuilder.node(id: userN, text: userN, color:"aaaaaa", nonzero:nonzero) 227: } 228: } 229: } 230: for(i in 0..(distanceArray.size()-2)) { 231: for(j in (i+1)..(distanceArray.size()-1)) { 232: if (distanceArray[i][j] > 0) { 233: def fromUser = xwiki.getUserName(usersArray[i][0], false); 234: def toUser = xwiki.getUserName(usersArray[j][0], false); 235: xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor:distanceArray[i][j], label:"") 236: } 237: } 238: } 239: } 240: def attachmentName = "userdistances.xml" 241: def attachment = doc.getDocument().getAttachment(attachmentName) 242: if (!attachment){ 243: attachment = new XWikiAttachment(doc.getDocument(), attachmentName) 244: doc.getDocument().getAttachmentList().add(attachment) 245: } 246: 247: attachment.setContent(writer.toString().getBytes()) 248: doc.getDocument().saveAttachmentContent(attachment, context.getContext()) 249: doc.save() 250: 251: println "Finished updating user relations." 252: } else { 253: println "[Update the User Relations>" + doc.fullName + "?updaterelations=1]" 254: } 255: } 256: 257: if(request.get("viewtoplsa") != null){ 258: def users = [] 259: def distanceArray = [] 260: def attachmentName = "lsa-creativeit2.csv" 261: def attachment = doc.getAttachment(attachmentName) 262: if (!attachment){ 263: println "No lsa file found." 264: } else { 265: def content = attachment.getContentAsString() 266: def reader = new BufferedReader(new StringReader(content)) 267: def userListStr = new StringTokenizer(reader.readLine(), ",") 268: // for(i in 1..size) { 269: while (userListStr.hasMoreTokens()) { 270: users.add(userListStr.nextToken()) 271: } 272: def sortedDistanceMatrix = [] 273: //for(i in 1..size) { 274: i = 0 275: while ((thisLine = reader.readLine()) != null) { 276: i++ 277: def distanceStr = new StringTokenizer(thisLine, ",") 278: def row = [] 279: j = 0 280: 281: //for(j in 1..size) { 282: while (distanceStr.hasMoreTokens()) { 283: j++ 284: row.add([users[j-1],Double.parseDouble(distanceStr.nextToken())]) 285: } 286: 287: //sort the row 288: for(j in 1..(row.size()-1)) { 289: def valueC = row[j][1] 290: def valueN = row[j][0] 291: def k = j-1 292: while(k >= 0 && row[k][1] < valueC) { 293: row[k + 1][0] = row[k][0] 294: row[k + 1][1] = row[k][1] 295: k = k-1 296: } 297: row[k+1][0] = valueN 298: row[k+1][1] = valueC 299: } 300: 301: //prints users' top five connected people if they exist 302: 303: print users[i-1] + ": " 304: for(j in 0..4) { 305: if(row[j][1] > 0) { 306: if(j > 0) { 307: print ", " 308: } 309: print xwiki.getUserName(row[j][0]) 310: } 311: } 312: println "\n" 313: 314: sortedDistanceMatrix.add(row) 315: } 316: } 317: } else { 318: println "\\\\[Show top lsa Relations>" + doc.fullName + "?viewtoplsa=1]" 319: } 320: 321: if(request.get("genlsa") != null){ 322: def usersArray = [] 323: def distanceArray = [] 324: def attachmentName = "lsa-creativeit2.csv" 325: def attachment = doc.getAttachment(attachmentName) 326: if (!attachment){ 327: println "No lsa file found." 328: } else { 329: def content = attachment.getContentAsString() 330: def reader = new BufferedReader(new StringReader(content)) 331: def userListStr = new StringTokenizer(reader.readLine(), ",") 332: // for(i in 1..size) { 333: while (userListStr.hasMoreTokens()) { 334: usersArray.add(userListStr.nextToken()) 335: } 336: def sortedDistanceMatrix = [] 337: //for(i in 1..size) { 338: i = 0 339: while ((thisLine = reader.readLine()) != null) { 340: i++ 341: def distanceStr = new StringTokenizer(thisLine, ",") 342: def row = [] 343: j = 0 344: 345: //for(j in 1..size) { 346: while (distanceStr.hasMoreTokens()) { 347: j++ 348: row.add([usersArray[j-1],Double.parseDouble(distanceStr.nextToken())]) 349: } 350: 351: //sort the row 352: 353: for(j in 1..(row.size()-1)) { 354: def valueC = row[j][1] 355: def valueN = row[j][0] 356: def k = j-1 357: while(k >= 0 && row[k][1] < valueC) { 358: row[k + 1][0] = row[k][0] 359: row[k + 1][1] = row[k][1] 360: k = k-1 361: } 362: row[k+1][0] = valueN 363: row[k+1][1] = valueC 364: } 365: sortedDistanceMatrix.add(row) 366: } 367: 368: //write out connection matrix to an attachment 369: def writer = new StringWriter() 370: def xmlBuilder = new MarkupBuilder(writer) 371: 372: xmlBuilder.graph (title: "Profile Closeness", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725"){ 373: 374: for(i in 0..(usersArray.size()-1)) { 375: if (sortedDistanceMatrix[i] != null) { 376: def nonzero = sortedDistanceMatrix[i].inject(0.0) { running, item -> running + item[1] } 377: if (nonzero > 0.0) { 378: def userN = xwiki.getUserName( usersArray[i], false) 379: //userN = user.getProperty("member").value 380: def userdoc = xwiki.getDocument(usersArray[i]) 381: if (userdoc != null) { 382: def attachCount = userdoc.attachmentList.size() 383: def attachIndex = attachCount - 1 384: def nodeURL = userdoc.getURL() 385: def nodeHtml = xwiki.getUserName(userN, false) 386: userN = nodeHtml 387: def obj = userdoc.getObject("XWiki.XWikiUsers") 388: def attachURL = "" 389: if (obj != null) { 390: def lastname = obj.get("last_name") 391: def firstname = obj.get('first_name') 392: nodeHtml = firstname + ' ' + lastname 393: } 394: 395: if (attachCount >0){ 396: def attach = userdoc.attachmentList.get(0) 397: attachURL = userdoc.getAttachmentURL(attach.filename,"download") + "?width=90" 398: } 399: xmlBuilder.node(id: userN, text: nodeHtml, color:"aaaaaa", image: attachURL, link: nodeURL, nonzero: nonzero) 400: } 401: 402: //xmlBuilder.node(id: userN, text: userN, color:"aaaaaa", nonzero:nonzero) 403: } 404: } 405: } 406: 407: for(i in 0..(sortedDistanceMatrix.size()-1)) { 408: for(j in 1..5) { 409: if (sortedDistanceMatrix[i][j] != null) { 410: if (sortedDistanceMatrix[i][j][1] > 0) { 411: def fromUser = xwiki.getUserName(usersArray[i], false); 412: def toUser = xwiki.getUserName(sortedDistanceMatrix[i][j][0], false); 413: xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor: sortedDistanceMatrix[i][j][1], label:"") 414: } 415: } 416: } 417: } 418: } 419: def outAttachmentName = "lsadistances.xml" 420: def outAttachment = doc.getDocument().getAttachment(outAttachmentName) 421: if (!outAttachment){ 422: outAttachment = new XWikiAttachment(doc.getDocument(), outAttachmentName) 423: doc.getDocument().getAttachmentList().add(outAttachment) 424: } 425: 426: outAttachment.setContent(writer.toString().getBytes()) 427: doc.getDocument().saveAttachmentContent(outAttachment, context.getContext()) 428: doc.save() 429: 430: println "Finished updating lsa relations." 431: } 432: } else { 433: println "\\\\[generate graph for lsa Relations>" + doc.fullName + "?genlsa=1]" 434: } 435: 436: if(request.get("genlsaxxx") != null){ 437: def usersArray = [] 438: def distanceArray = [] 439: def attachmentName = "lsa-creativeit2.csv" 440: def attachment = doc.getAttachment(attachmentName) 441: if (!attachment){ 442: println "No lsa file found." 443: } else { 444: def content = attachment.getContentAsString() 445: def reader = new BufferedReader(new StringReader(content)) 446: def userListStr = new StringTokenizer(reader.readLine(), ",") 447: // for(i in 1..size) { 448: while (userListStr.hasMoreTokens()) { 449: usersArray.add(userListStr.nextToken()) 450: } 451: def sortedDistanceMatrix = [] 452: //for(i in 1..size) { 453: i = 0 454: while ((thisLine = reader.readLine()) != null) { 455: i++ 456: def distanceStr = new StringTokenizer(thisLine, ",") 457: def row = [] 458: j = 0 459: 460: //for(j in 1..size) { 461: while (distanceStr.hasMoreTokens()) { 462: j++ 463: row.add(Double.parseDouble(distanceStr.nextToken())) 464: } 465: 466: distanceArray.add(row) 467: } 468: 469: } 470: //write out connection matrix to an attachment 471: def writer = new StringWriter() 472: def xmlBuilder = new MarkupBuilder(writer) 473: 474: xmlBuilder.graph (title: "User Map", bgcolor:"ffffff", linecolor:"cccccc", viewmode:"explore", width:"725", height:"725"){ 475: 476: for(i in 0..(usersArray.size()-1)) { 477: if (distanceArray[i] != null> 0) { 478: def nonzero = distanceArray[i].inject(0.0) { running, item -> running + item } 479: if (nonzero > 0.0) { 480: def userN = xwiki.getUserName( usersArray[i], false) 481: xmlBuilder.node(id: userN, text: userN, color:"aaaaaa", nonzero:nonzero) 482: } 483: } 484: } 485: 486: for(i in 0..(distanceArray.size()-2)) { 487: for(j in (i+1)..(distanceArray.size()-1)) { 488: if (distanceArray[i][j] > 0) { 489: def fromUser = xwiki.getUserName(usersArray[i], false); 490: def toUser = xwiki.getUserName(usersArray[j], false); 491: xmlBuilder.edge(sourceNode: fromUser, targetNode: toUser, distFactor:distanceArray[i][j], label:"") 492: } 493: } 494: } 495: 496: } 497: def outAttachmentName = "lsadistances.xml" 498: def outAttachment = doc.getDocument().getAttachment(outAttachmentName) 499: if (!outAttachment){ 500: outAttachment = new XWikiAttachment(doc.getDocument(), outAttachmentName) 501: doc.getDocument().getAttachmentList().add(outAttachment) 502: } 503: 504: outAttachment.setContent(writer.toString().getBytes()) 505: doc.getDocument().saveAttachmentContent(outAttachment, context.getContext()) 506: doc.save() 507: 508: println "Finished updating lsa relations." 509: 510: } 511: 512: %> 513: 1 user relations 514: #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