General Actions:
Log-in
Wiki:
CreativeIT
▼
:
Document Index
»
Space:
Main
▼
:
Document Index
»
Page:
test2
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
test2
Wiki source code of
test2
Last modified by
Holger Dick
on 2010/07/16 12:29
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: #includeInContext('XWiki.Rater') 2: 3: <% 4: ratdoc = xwiki.getDocument("XWiki.RatStats") 5: rat2doc = xwiki.getDocument("XWiki.RatingStats") 6: userList = xwiki.getArrayList() 7: topUsers = xwiki.getHashMap() 8: pageList = xwiki.getArrayList() 9: pageRatings = xwiki.getHashMap() 10: existingUsersIndex = xwiki.getHashMap() 11: existingPagesIndex = xwiki.getHashMap() 12: Comparator comparator = Collections.reverseOrder(); 13: allRatings = ratdoc.getObjects("XWiki.RatingClass") 14: allPerUserRatings = rat2doc.getObjects('XWiki.PerUserRatingsClass') 15: allPerPageRatings = rat2doc.getObjects('XWiki.PerPageRatingsClass') 16: 17: /* Create a hashtable with all users and the count of their ratings */ 18: for(rating in allRatings) 19: { 20: /* --- first the top-rater statistics --- */ 21: user = ratdoc.display("user", rating) 22: page = ratdoc.display("page", rating) 23: stars = ratdoc.display("rating", rating).toInteger() 24: 25: if (userList.contains(user)) 26: { 27: currentCount = topUsers.get(user, rating) 28: currentCount ++ 29: topUsers.put(user, currentCount) 30: } 31: else 32: { 33: userList.add(user) 34: topUsers.put(user, 1) 35: } 36: 37: /* --- And now the ratings per page statistics --- */ 38: if (pageList.contains(page)) 39: { 40: upAndDown = pageRatings.get(page) 41: if(stars > 3) 42: { 43: upAndDown[0]++ 44: }else{ 45: upAndDown[1]++ 46: } 47: pageRatings.put(page, upAndDown) 48: }else{ 49: int[] upAndDown = new int[2] 50: if(stars > 3) 51: { 52: upAndDown[0] = 1 53: upAndDown[1] = 0 54: }else{ 55: upAndDown[0] = 0 56: upAndDown[1] = 1 57: } 58: pageRatings.put(page, upAndDown) 59: pageList.add(page) 60: } 61: 62: } 63: 64: /* now we want to save the results as objects in another page so that they can 65: be easily retrieved. First, we check what users already have entries. */ 66: int i = 0 67: for(user in allPerUserRatings) 68: { 69: username = rat2doc.display("username", user) 70: existingUsersIndex.put(username, i) 71: i++ 72: } 73: 74: /* save the count of ratings given for each user as an object of the class 75: 'XWiki.PerUserRatingsClass'. If the user already has an object, we will change 76: this. Otherwise, a new one gets created. */ 77: for(user in userList) 78: { 79: count = topUsers.get(user).toInteger() 80: if(existingUsersIndex.containsKey(user)) 81: { 82: currentIndex = existingUsersIndex.get(user) 83: perUserObject = rat2doc.getObject('XWiki.PerUserRatingsClass', currentIndex) 84: perUserObject.set('numberOfRatings', count) 85: }else{ 86: perUserObject = rat2doc.newObject('XWiki.PerUserRatingsClass') 87: perUserObject.set('username', user) 88: perUserObject.set('numberOfRatings', count) 89: } 90: } 91: 92: /* Now, let's save the statistics per page - similar to per user*/ 93: i = 0 94: for(page in allPerPageRatings) 95: { 96: pagename = rat2doc.display("pagename", page) 97: existingPagesIndex.put(pagename, i) 98: i++ 99: } 100: for(page in pageList) 101: { 102: upAndDowns = pageRatings.get(page) 103: if(existingPagesIndex.containsKey(page)) 104: { 105: currentIndex = existingPagesIndex.get(page) 106: perPageObject = rat2doc.getObject('XWiki.PerPageRatingsClass', currentIndex) 107: perPageObject.set('upratings', upAndDowns[0].toInteger()) 108: perPageObject.set('downratings', upAndDowns[1].toInteger()) 109: }else{ 110: perPageObject = rat2doc.newObject('XWiki.PerPageRatingsClass') 111: perPageObject.set('pagename', page) 112: perPageObject.set('upratings', upAndDowns[0].toInteger()) 113: perPageObject.set('downratings', upAndDowns[1].toInteger()) 114: } 115: } 116: 117: /* Finally, we save the changes to the objects */ 118: rat2doc.save('Updated Stats', true) 119: 120: /* Print the (up to) 5 users with the most rating 121: !< currently it sorts by users names, not their contributions 122: sortedList = userList.sort(comparator) 123: if(sortedList.size() > 5) 124: { 125: sortedList.removeRange(5, sortedList.size()) 126: } 127: */ 128: 129: %>
Quick Links
Home
Index
What's New
Blog
Calendar
Photo Albums
Sandbox
Tags
Bulletin Board
My Recent Modifications
PamelaJennings
|
rwakkary
|
HaledenSands
|
ByronLahey