Index: lams_tool_preview/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r4a6c8a497b55005dcd5b6158ebc2051fc5e3b40a -r0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0 --- lams_tool_preview/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 4a6c8a497b55005dcd5b6158ebc2051fc5e3b40a) +++ lams_tool_preview/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0) @@ -223,3 +223,4 @@ label.rating.rubrics.require.ratings = Students must assign evaluation to all rubrics and peers label.rating.rubrics.require.ratings.tooltip = If selected, the student is required to assign an evaluation to all peers. No blank evaluations allowed. message.rating.rubrics.selection.missing = You have not rated one or more peers. Are you sure you want to continue? +output.desc.learner.rating.average = Learner's average rating from peers \ No newline at end of file Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/PeerreviewConstants.java =================================================================== diff -u -r62aaf160878735888d077bf28fac3c1989bb8fbd -r0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0 --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/PeerreviewConstants.java (.../PeerreviewConstants.java) (revision 62aaf160878735888d077bf28fac3c1989bb8fbd) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/PeerreviewConstants.java (.../PeerreviewConstants.java) (revision 0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0) @@ -142,5 +142,5 @@ public static final String ATTR_USER_UID = "userUid"; - public static final String SHARED_ITEMS_DEFINITION_NAME = "shared.items.output.definition.peerreview"; -} + public static final String OUTPUT_NAME_LEARNER_RATING_AVERAGE = "learner.rating.average"; +} \ No newline at end of file Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/peerreviewApplicationContext.xml =================================================================== diff -u -r01c2a55767c613282c319ed8b38a0c78712e3661 -r0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0 --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/peerreviewApplicationContext.xml (.../peerreviewApplicationContext.xml) (revision 01c2a55767c613282c319ed8b38a0c78712e3661) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/peerreviewApplicationContext.xml (.../peerreviewApplicationContext.xml) (revision 0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0) @@ -33,6 +33,11 @@ + + + + + @@ -54,6 +59,9 @@ + + + @@ -108,5 +116,4 @@ - - + \ No newline at end of file Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/IPeerreviewService.java =================================================================== diff -u -r603269d5aab112e1179448fbb5596550ab39f009 -r0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0 --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/IPeerreviewService.java (.../IPeerreviewService.java) (revision 603269d5aab112e1179448fbb5596550ab39f009) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/IPeerreviewService.java (.../IPeerreviewService.java) (revision 0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0) @@ -23,10 +23,7 @@ package org.lamsfoundation.lams.tool.peerreview.service; -import java.util.Collection; -import java.util.List; -import java.util.Map; - +import com.fasterxml.jackson.databind.node.ArrayNode; import org.lamsfoundation.lams.notebook.model.NotebookEntry; import org.lamsfoundation.lams.rating.ToolRatingManager; import org.lamsfoundation.lams.rating.dto.ItemRatingDTO; @@ -42,7 +39,9 @@ import org.lamsfoundation.lams.util.excel.ExcelSheet; import org.lamsfoundation.lams.web.util.SessionMap; -import com.fasterxml.jackson.databind.node.ArrayNode; +import java.util.Collection; +import java.util.List; +import java.util.Map; /** * Interface that defines the contract that all Peerreview service provider must follow. @@ -70,6 +69,7 @@ Peerreview getDefaultContent(Long contentId) throws PeerreviewApplicationException; // ********** for user methods ************* + /** * Create a new user in database. */ @@ -117,6 +117,8 @@ */ PeerreviewSession getPeerreviewSessionBySessionId(Long sessionId); + List getPeerreviewSessionsByConentId(Long toolContentId); + /** * Save or update peerreview session. * @@ -155,7 +157,7 @@ * @param qaSessionId * @param excludeUserId * @param includeHiddenUsers - * whether hidden users should be counted as well or not + * whether hidden users should be counted as well or not * @return */ int getCountUsersBySession(final Long qaSessionId, final Long excludeUserId); @@ -205,10 +207,9 @@ PeerreviewUser getUser(Long uid); /** - * Trigger the user creation, based on the lesson/grouping class, if needed. This - * should be called by the web layer to trigger an update. Could take a while to run so - * should be called from a new thread in the Action classm rather than holding up the Action - * class. + * Trigger the user creation, based on the lesson/grouping class, if needed. This should be called by the web layer + * to trigger an update. Could take a while to run so should be called from a new thread in the Action classm rather + * than holding up the Action class. * * Returns true if a check/update is triggered, returns false if a check is already underway. * @@ -245,22 +246,18 @@ /** * It's a modification of org.lamsfoundation.lams.rating.ToolRatingManager.getRatingCriteriaDtos(Long contentId, * Long toolSessionId, Collection itemIds, boolean isCommentsByOtherUsersRequired, Long userId) method, added - * additional parameter - * isCountUsersRatedEachItem. - * + * additional parameter isCountUsersRatedEachItem. */ List getRatingCriteriaDtos(Long contentId, Long toolSessionId, Collection itemIds, boolean isCommentsByOtherUsersRequired, Long userId, boolean isCountUsersRatedEachItem); /** * Gets all the users in the session and any existing ratings for a given criteria. If you want to use the - * tablesorter - * set skipRatings to true and it will just get the main criteria details, then on the jsp page call a tablesorter - * function that call getUsersRatingsCommentsByCriteriaJSON, with the page and size are included. - * Self rating === getAllUsers - * If you want the ratings done *by* the user XYZ, set getByUser to true and currentUser id to XYZ's user id. - * If you want the ratings done *for* user XYZ, set getByUser to true and currentUser id to XYZ's user id. - * user, set getByUser to false and set currentUserId to the current user id. + * tablesorter set skipRatings to true and it will just get the main criteria details, then on the jsp page call a + * tablesorter function that call getUsersRatingsCommentsByCriteriaJSON, with the page and size are included. Self + * rating === getAllUsers If you want the ratings done *by* the user XYZ, set getByUser to true and currentUser id + * to XYZ's user id. If you want the ratings done *for* user XYZ, set getByUser to true and currentUser id to XYZ's + * user id. user, set getByUser to false and set currentUserId to the current user id. */ StyledCriteriaRatingDTO getUsersRatingsCommentsByCriteriaIdDTO(Long toolContentId, Long toolSessionId, RatingCriteria criteria, Long currentUserId, boolean skipRatings, int sorting, String searchString, @@ -291,9 +288,8 @@ List getStatistics(Long toolContentId); /** - * Get all the notebook entries for a session - * Will return List<[user.user_id, user.first_name, user.first_name + user.last_name, notebook entry, notebook - * date]> + * Get all the notebook entries for a session Will return List<[user.user_id, user.first_name, user.first_name + + * user.last_name, notebook entry, notebook date]> */ List getUserNotebookEntriesForTablesorter(Long toolSessionId, int page, int size, int sorting, String searchString); Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/PeerreviewOutputFactory.java =================================================================== diff -u --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/PeerreviewOutputFactory.java (revision 0) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/PeerreviewOutputFactory.java (revision 0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0) @@ -0,0 +1,130 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.tool.peerreview.service; + +import org.lamsfoundation.lams.tool.OutputFactory; +import org.lamsfoundation.lams.tool.ToolOutput; +import org.lamsfoundation.lams.tool.ToolOutputDefinition; +import org.lamsfoundation.lams.tool.peerreview.PeerreviewConstants; +import org.lamsfoundation.lams.tool.peerreview.model.Peerreview; +import org.lamsfoundation.lams.tool.peerreview.model.PeerreviewSession; +import org.lamsfoundation.lams.tool.peerreview.util.EmailAnalysisBuilder; + +import java.util.*; + +public class PeerreviewOutputFactory extends OutputFactory { + + /** + * @see org.lamsfoundation.lams.tool.OutputDefinitionFactory#getToolOutputDefinitions(Object) + */ + @Override + public SortedMap getToolOutputDefinitions(Object toolContentObject, + int definitionType) { + TreeMap definitionMap = new TreeMap<>(); + if (definitionType == ToolOutputDefinition.DATA_OUTPUT_DEFINITION_TYPE_CONDITION) { + ToolOutputDefinition definition = buildRangeDefinition( + PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE, 0L, 5L); + definitionMap.put(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE, definition); + } + + return definitionMap; + } + + public SortedMap getToolOutput(List names, IPeerreviewService peerreviewService, + Long toolSessionId, Long learnerId) { + TreeMap output = new TreeMap<>(); + Peerreview peerreview = peerreviewService.getPeerreviewBySessionId(toolSessionId); + + if (names == null || names.contains(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE)) { + ToolOutput toolOutput = buildLearnerRatingAverageOutput(peerreviewService, peerreview.getContentId(), + toolSessionId, learnerId); + output.put(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE, toolOutput); + } + + return output; + } + + public ToolOutput getToolOutput(String name, IPeerreviewService peerreviewService, Long toolSessionId, + Long learnerId) { + Peerreview peerreview = peerreviewService.getPeerreviewBySessionId(toolSessionId); + + if (name != null && name.equals(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE)) { + return buildLearnerRatingAverageOutput(peerreviewService, peerreview.getContentId(), toolSessionId, + learnerId); + } + + return null; + } + + public List getToolOutputs(String name, IPeerreviewService peerreviewService, Long toolContentId) { + List outputs = new ArrayList<>(); + + if (name != null && name.equals(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE)) { + List sessions = peerreviewService.getPeerreviewSessionsByConentId(toolContentId); + for (PeerreviewSession session : sessions) { + + double rating = 0d; + Map learnersData = peerreviewService.getLearnerData( + toolContentId, session.getSessionId()); + for (EmailAnalysisBuilder.LearnerData learnerData : learnersData.values()) { + int criteriaCount = 0; + for (EmailAnalysisBuilder.LearnerData.SingleCriteriaData criteriaData : learnerData.criteriaDataMap.values()) { + if (criteriaData.peerRatingExcSelf != null) { + rating += criteriaData.peerRatingExcSelf; + criteriaCount++; + } + } + if (criteriaCount > 0) { + rating = rating / criteriaCount; + } + } + outputs.add(new ToolOutput(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE, + getI18NText(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE, true), rating)); + + } + } + return outputs; + } + + private ToolOutput buildLearnerRatingAverageOutput(IPeerreviewService peerreviewService, Long toolContentId, + Long toolSessionId, Long learnerId) { + double rating = 0d; + Map learnersData = peerreviewService.getLearnerData(toolContentId, + toolSessionId); + EmailAnalysisBuilder.LearnerData learnerData = learnersData.get(learnerId); + if (learnerData != null) { + int criteriaCount = 0; + for (EmailAnalysisBuilder.LearnerData.SingleCriteriaData criteriaData : learnerData.criteriaDataMap.values()) { + if (criteriaData.peerRatingExcSelf != null) { + rating += criteriaData.peerRatingExcSelf; + criteriaCount++; + } + } + if (criteriaCount > 0) { + rating = rating / criteriaCount; + } + } + return new ToolOutput(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE, + getI18NText(PeerreviewConstants.OUTPUT_NAME_LEARNER_RATING_AVERAGE, true), rating); + } +} \ No newline at end of file Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/PeerreviewServiceImpl.java =================================================================== diff -u -r324eb210f0c4a8193d0a0b071a675720ebf9b594 -r0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0 --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/PeerreviewServiceImpl.java (.../PeerreviewServiceImpl.java) (revision 324eb210f0c4a8193d0a0b071a675720ebf9b594) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/service/PeerreviewServiceImpl.java (.../PeerreviewServiceImpl.java) (revision 0d5ed4bdbfb191f7ffefc64a35c31cf48b55f0b0) @@ -95,6 +95,8 @@ private MessageService messageService; + private PeerreviewOutputFactory peerreviewOutputFactory; + // system services private ILamsToolService toolService; @@ -183,6 +185,11 @@ } @Override + public List getPeerreviewSessionsByConentId(Long toolContentId) { + return peerreviewSessionDao.getByContentId(toolContentId); + } + + @Override public void saveOrUpdatePeerreviewSession(PeerreviewSession resSession) { peerreviewSessionDao.insertOrUpdate(resSession); } @@ -797,7 +804,7 @@ @Override public SortedMap getToolOutputDefinitions(Long toolContentId, int definitionType) throws ToolException { - return new TreeMap<>(); + return peerreviewOutputFactory.getToolOutputDefinitions(toolContentId, definitionType); } @Override @@ -1048,17 +1055,17 @@ @Override public SortedMap getToolOutput(List names, Long toolSessionId, Long learnerId) { - return new TreeMap<>(); + return peerreviewOutputFactory.getToolOutput(names, this, toolSessionId, learnerId); } @Override public ToolOutput getToolOutput(String name, Long toolSessionId, Long learnerId) { - return null; + return peerreviewOutputFactory.getToolOutput(name, this, toolSessionId, learnerId); } @Override public List getToolOutputs(String name, Long toolContentId) { - return new ArrayList<>(); + return peerreviewOutputFactory.getToolOutputs(name, this, toolContentId); } @Override @@ -1090,6 +1097,10 @@ this.messageService = messageService; } + public void setPeerreviewOutputFactory(PeerreviewOutputFactory peerreviewOutputFactory) { + this.peerreviewOutputFactory = peerreviewOutputFactory; + } + public void setPeerreviewDao(PeerreviewDAO peerreviewDao) { this.peerreviewDao = peerreviewDao; }