Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java,v diff -u -r1.99 -r1.100 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java 17 Dec 2006 18:10:26 -0000 1.99 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McAppConstants.java 15 Aug 2007 03:54:49 -0000 1.100 @@ -192,8 +192,6 @@ public static final String DEFAULT_FEEDBACK_INCORRECT ="Your answer is incorrect"; public static final String DEFAULT_FEEDBACK_CORRECT ="Correct"; - public static final String PASSMARK_APPLICABLE ="passMarkApplicable"; - public static final String USER_OVER_PASSMARK ="userOverPassMark"; public static final String TITLE ="title"; public static final String INSTRUCTIONS ="instructions"; @@ -270,9 +268,6 @@ public static final String TOTAL_QUESTION_COUNT ="totalQuestionCount"; public static final String HR_COLUMN_COUNT ="hrColumnCount"; public static final String LEARNER_MARK ="learnerMark"; - public static final String LEARNER_BEST_MARK ="learnerBestMark"; - public static final String LEARNER_LAST_ATTEMPT_ORDER ="learnerLastAttemptOrder"; - public static final String LEARNER_MARK_ATLEAST ="learnerMarkAtLeast"; public static final String MAP_ANSWERS ="mapAnswers"; public static final String CURRENT_ANSWER ="currentAnswer"; public static final String USER_FEEDBACK ="userFeedback"; Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralLearnerFlowDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralLearnerFlowDTO.java,v diff -u -r1.15 -r1.16 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralLearnerFlowDTO.java 3 Dec 2006 21:23:35 -0000 1.15 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McGeneralLearnerFlowDTO.java 15 Aug 2007 03:54:49 -0000 1.16 @@ -38,16 +38,14 @@ { protected String retries; - protected String learnerMark; + protected Integer learnerMark; protected String userName; - protected String learnerMarkAtLeast; + protected Integer totalQuestionCount; - protected String totalQuestionCount; + protected Integer passMark; - protected String passMark; - protected String passMarkApplicable; protected String userPassed; @@ -60,13 +58,13 @@ protected String activityTitle; - protected String learnerBestMark; + protected Integer latestAttemptMark; - protected String currentQuestionIndex; + protected Integer currentQuestionIndex; protected String countSessionComplete; - protected String topMark; + protected Integer topMark; protected String reflection; @@ -76,9 +74,9 @@ protected String notebookEntriesVisible; - protected String lowestMark; + protected Integer lowestMark; - protected String averageMark; + protected Integer averageMark; protected String reportViewOnly; @@ -102,14 +100,12 @@ protected String totalCountReached; - protected String questionIndex; + protected Integer questionIndex; protected String questionListingMode; - protected String totalUserMark; + protected Integer totalMarksPossible; - protected String totalMarksPossible; - protected Map mapFeedbackContent; protected Map mapFinalAnswersIsContent; @@ -130,18 +126,6 @@ this.mapFeedbackContent = mapFeedbackContent; } /** - * @return Returns the totalUserMark. - */ - public String getTotalUserMark() { - return totalUserMark; - } - /** - * @param totalUserMark The totalUserMark to set. - */ - public void setTotalUserMark(String totalUserMark) { - this.totalUserMark = totalUserMark; - } - /** * @return Returns the questionListingMode. */ public String getQuestionListingMode() { @@ -156,13 +140,13 @@ /** * @return Returns the questionIndex. */ - public String getQuestionIndex() { + public Integer getQuestionIndex() { return questionIndex; } /** * @param questionIndex The questionIndex to set. */ - public void setQuestionIndex(String questionIndex) { + public void setQuestionIndex(Integer questionIndex) { this.questionIndex = questionIndex; } /** @@ -204,13 +188,13 @@ /** * @return Returns the averageMark. */ - public String getAverageMark() { + public Integer getAverageMark() { return averageMark; } /** * @param averageMark The averageMark to set. */ - public void setAverageMark(String averageMark) { + public void setAverageMark(Integer averageMark) { this.averageMark = averageMark; } /** @@ -228,38 +212,38 @@ /** * @return Returns the lowestMark. */ - public String getLowestMark() { + public Integer getLowestMark() { return lowestMark; } /** * @param lowestMark The lowestMark to set. */ - public void setLowestMark(String lowestMark) { + public void setLowestMark(Integer lowestMark) { this.lowestMark = lowestMark; } /** * @return Returns the topMark. */ - public String getTopMark() { + public Integer getTopMark() { return topMark; } /** * @param topMark The topMark to set. */ - public void setTopMark(String topMark) { + public void setTopMark(Integer topMark) { this.topMark = topMark; } /** - * @return Returns the learnerBestMark. + * @return Returns the LatestAttemptMark. */ - public String getLearnerBestMark() { - return learnerBestMark; + public Integer getLatestAttemptMark() { + return latestAttemptMark; } /** * @param learnerBestMark The learnerBestMark to set. */ - public void setLearnerBestMark(String learnerBestMark) { - this.learnerBestMark = learnerBestMark; + public void setLatestAttemptMark(Integer latestAttemptMark) { + this.latestAttemptMark = latestAttemptMark; } /** * @return Returns the activityInstructions. @@ -277,37 +261,25 @@ /** * @return Returns the learnerMark. */ - public String getLearnerMark() { + public Integer getLearnerMark() { return learnerMark; } /** * @param learnerMark The learnerMark to set. */ - public void setLearnerMark(String learnerMark) { + public void setLearnerMark(Integer learnerMark) { this.learnerMark = learnerMark; } /** - * @return Returns the learnerMarkAtLeast. - */ - public String getLearnerMarkAtLeast() { - return learnerMarkAtLeast; - } - /** - * @param learnerMarkAtLeast The learnerMarkAtLeast to set. - */ - public void setLearnerMarkAtLeast(String learnerMarkAtLeast) { - this.learnerMarkAtLeast = learnerMarkAtLeast; - } - /** * @return Returns the passMark. */ - public String getPassMark() { + public Integer getPassMark() { return passMark; } /** * @param passMark The passMark to set. */ - public void setPassMark(String passMark) { + public void setPassMark(Integer passMark) { this.passMark = passMark; } /** @@ -337,13 +309,13 @@ /** * @return Returns the totalQuestionCount. */ - public String getTotalQuestionCount() { + public Integer getTotalQuestionCount() { return totalQuestionCount; } /** * @param totalQuestionCount The totalQuestionCount to set. */ - public void setTotalQuestionCount(String totalQuestionCount) { + public void setTotalQuestionCount(Integer totalQuestionCount) { this.totalQuestionCount = totalQuestionCount; } /** @@ -375,7 +347,6 @@ .append("mapQueAttempts: ", mapQueAttempts) .append("mapGeneralOptionsContent: ", mapGeneralOptionsContent) .append("learnerMark : ", learnerMark) - .append("learnerMarkAtLeast: ", learnerMarkAtLeast) .append("totalQuestionCount: ", totalQuestionCount) .append("passMark: ", passMark) .append("passMarkApplicable: ", passMarkApplicable) @@ -435,13 +406,13 @@ /** * @return Returns the currentQuestionIndex. */ - public String getCurrentQuestionIndex() { + public Integer getCurrentQuestionIndex() { return currentQuestionIndex; } /** * @param currentQuestionIndex The currentQuestionIndex to set. */ - public void setCurrentQuestionIndex(String currentQuestionIndex) { + public void setCurrentQuestionIndex(Integer currentQuestionIndex) { this.currentQuestionIndex = currentQuestionIndex; } /** @@ -594,22 +565,27 @@ /** * @return Returns the totalMarksPossible. */ - public String getTotalMarksPossible() { + public Integer getTotalMarksPossible() { return totalMarksPossible; } /** * @param totalMarksPossible The totalMarksPossible to set. */ - public void setTotalMarksPossible(String totalMarksPossible) { + public void setTotalMarksPossible(Integer totalMarksPossible) { this.totalMarksPossible = totalMarksPossible; } /** + * If using for a display screen then showMarks controls whether or not + * to show the average and top marks for the session. If using for the "get answers" + * screens, then this controls whether or not to show the marks for each question - + * this allows us to NOT show the marks if ALL of the questions have a mark of 1. * @return Returns the showMarks. */ public String getShowMarks() { return showMarks; } /** + * See getShowMarks() for the meaning of "showMarks". * @param showMarks The showMarks to set. */ public void setShowMarks(String showMarks) { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McLearnerAnswersDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/Attic/McLearnerAnswersDTO.java,v diff -u -r1.4 -r1.5 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McLearnerAnswersDTO.java 15 Oct 2006 11:08:52 -0000 1.4 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McLearnerAnswersDTO.java 15 Aug 2007 03:54:49 -0000 1.5 @@ -39,9 +39,9 @@ protected String displayOrder; - protected String questionUid; + protected Long questionUid; - protected String mark; + protected Integer mark; protected Map candidateAnswers; @@ -114,13 +114,13 @@ /** * @return Returns the questionUid. */ - public String getQuestionUid() { + public Long getQuestionUid() { return questionUid; } /** * @param questionUid The questionUid to set. */ - public void setQuestionUid(String questionUid) { + public void setQuestionUid(Long questionUid) { this.questionUid = questionUid; } /** @@ -174,13 +174,13 @@ /** * @return Returns the mark. */ - public String getMark() { + public Integer getMark() { return mark; } /** * @param mark The mark to set. */ - public void setMark(String mark) { + public void setMark(Integer mark) { this.mark = mark; } /** Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java,v diff -u -r1.9 -r1.10 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java 15 Oct 2006 11:08:52 -0000 1.9 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredAnswersDTO.java 15 Aug 2007 03:54:49 -0000 1.10 @@ -46,26 +46,11 @@ private String sessionName; - private List candidateAnswers; - private List candidateAnswersCorrect; private Map questionAttempts; - /** - * @return Returns the candidateAnswers. - */ - public List getCandidateAnswers() { - return candidateAnswers; - } - /** - * @param candidateAnswers The candidateAnswers to set. - */ - public void setCandidateAnswers(List candidateAnswers) { - this.candidateAnswers = candidateAnswers; - } - /** * @return Returns the question. */ public String getQuestion() { @@ -108,7 +93,6 @@ return new ToStringBuilder(this) .append("questionUid: ", questionUid) .append("question: ", question) - .append("candidateAnswers: ", candidateAnswers) .append("questionAttempts: ", questionAttempts) .append("candidateAnswersCorrect:", candidateAnswersCorrect) .toString(); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredUserDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredUserDTO.java,v diff -u -r1.7 -r1.8 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredUserDTO.java 17 Sep 2006 06:23:44 -0000 1.7 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McMonitoredUserDTO.java 15 Aug 2007 03:54:49 -0000 1.8 @@ -22,6 +22,7 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc; +import java.util.List; import java.util.Map; import org.apache.commons.lang.builder.ToStringBuilder; @@ -47,15 +48,15 @@ private String isCorrect; - private String mark; + private Integer mark; private String response; private String sessionId; private String questionUid; - private Map usersAttempts; + private Map usersAttempts; /** * @return Returns the queUsrId. @@ -72,19 +73,28 @@ public String toString() { return new ToStringBuilder(this) - .append("queUsrId and username", getQueUsrId() + " and " + getUserName()) + .append("queUsrId", queUsrId) + .append("username", userName) + .append("isCorrect", isCorrect) + .append("mark", mark) + .append("sessionId", sessionId) + .append("questionUid", questionUid) + .append("usersAttempts", usersAttempts) .toString(); } /** + * UserAttempts is a map, where the key is the attemptOrder and the value is String array with the text of the attempt. + * At present, the string array will be of length one, but if we ever support more than one answer to a question then this + * will need to be changed to a list of strings. * @return Returns the usersAttempts. */ - public Map getUsersAttempts() { + public Map getUsersAttempts() { return usersAttempts; } /** * @param usersAttempts The usersAttempts to set. */ - public void setUsersAttempts(Map usersAttempts) { + public void setUsersAttempts(Map usersAttempts) { this.usersAttempts = usersAttempts; } @@ -196,13 +206,13 @@ /** * @return Returns the mark. */ - public String getMark() { + public Integer getMark() { return mark; } /** * @param mark The mark to set. */ - public void setMark(String mark) { + public void setMark(Integer mark) { this.mark = mark; } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McTempDataHolderDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/Attic/McTempDataHolderDTO.java,v diff -u -r1.5 -r1.6 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McTempDataHolderDTO.java 10 Dec 2006 23:18:08 -0000 1.5 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McTempDataHolderDTO.java 15 Aug 2007 03:54:49 -0000 1.6 @@ -34,12 +34,9 @@ */ public class McTempDataHolderDTO implements Comparable { - protected String learnerMark; - protected String totalUserWeight; - protected String totalUserMark; - protected String totalReportableUserMark; - protected String totalMarksPossible; - protected String displayOrder; + protected Integer learnerMark; + protected Integer totalMarksPossible; + protected Integer displayOrder; public int compareTo(Object o) @@ -55,9 +52,6 @@ public String toString() { return new ToStringBuilder(this) .append("learnerMark: ", learnerMark) - .append("totalUserWeight : ", totalUserWeight) - .append("totalUserMark : ", totalUserMark) - .append("totalReportableUserMark : ", totalReportableUserMark) .append("totalMarksPossible : ", totalMarksPossible) .append("displayOrder : ", displayOrder) .toString(); @@ -66,74 +60,37 @@ /** * @return Returns the learnerMark. */ - public String getLearnerMark() { + public Integer getLearnerMark() { return learnerMark; } /** * @param learnerMark The learnerMark to set. */ - public void setLearnerMark(String learnerMark) { + public void setLearnerMark(Integer learnerMark) { this.learnerMark = learnerMark; } /** - * @return Returns the totalUserWeight. - */ - public String getTotalUserWeight() { - return totalUserWeight; - } - /** - * @param totalUserWeight The totalUserWeight to set. - */ - public void setTotalUserWeight(String totalUserWeight) { - this.totalUserWeight = totalUserWeight; - } - /** - * @return Returns the totalUserMark. - */ - public String getTotalUserMark() { - return totalUserMark; - } - /** - * @param totalUserMark The totalUserMark to set. - */ - public void setTotalUserMark(String totalUserMark) { - this.totalUserMark = totalUserMark; - } - - /** - * @return Returns the totalReportableUserMark. - */ - public String getTotalReportableUserMark() { - return totalReportableUserMark; - } - /** - * @param totalReportableUserMark The totalReportableUserMark to set. - */ - public void setTotalReportableUserMark(String totalReportableUserMark) { - this.totalReportableUserMark = totalReportableUserMark; - } - /** * @return Returns the totalMarksPossible. */ - public String getTotalMarksPossible() { + public Integer getTotalMarksPossible() { return totalMarksPossible; } /** * @param totalMarksPossible The totalMarksPossible to set. */ - public void setTotalMarksPossible(String totalMarksPossible) { + public void setTotalMarksPossible(Integer totalMarksPossible) { this.totalMarksPossible = totalMarksPossible; } /** * @return Returns the displayOrder. */ - public String getDisplayOrder() { + public Integer getDisplayOrder() { return displayOrder; } /** * @param displayOrder The displayOrder to set. */ - public void setDisplayOrder(String displayOrder) { + public void setDisplayOrder(Integer displayOrder) { this.displayOrder = displayOrder; } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java,v diff -u -r1.3 -r1.4 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java 17 Sep 2006 06:23:44 -0000 1.3 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUserMarkDTO.java 15 Aug 2007 03:54:49 -0000 1.4 @@ -22,6 +22,7 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc; +import java.util.Collection; import java.util.LinkedList; import org.apache.commons.lang.builder.ToStringBuilder; @@ -39,8 +40,8 @@ private String sessionName; private String queUsrId; private String userName; - private LinkedList marks; - private String totalMark; + private Integer[] marks; + private Long totalMark; public String toString() { return new ToStringBuilder(this) @@ -57,13 +58,13 @@ /** * @return Returns the marks. */ - public LinkedList getMarks() { + public Integer[] getMarks() { return marks; } /** * @param marks The marks to set. */ - public void setMarks(LinkedList marks) { + public void setMarks(Integer[] marks) { this.marks = marks; } /** @@ -117,13 +118,13 @@ /** * @return Returns the totalMark. */ - public String getTotalMark() { + public Long getTotalMark() { return totalMark; } /** * @param totalMark The totalMark to set. */ - public void setTotalMark(String totalMark) { + public void setTotalMark(Long totalMark) { this.totalMark = totalMark; } /** Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java,v diff -u -r1.52 -r1.53 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java 3 Dec 2006 21:23:35 -0000 1.52 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/McUtils.java 15 Aug 2007 03:54:49 -0000 1.53 @@ -484,9 +484,6 @@ request.getSession().removeAttribute(CURRENT_QUESTION_INDEX); request.getSession().removeAttribute(TOTAL_QUESTION_COUNT); request.getSession().removeAttribute(LEARNER_MARK); - request.getSession().removeAttribute(LEARNER_BEST_MARK); - request.getSession().removeAttribute(LEARNER_LAST_ATTEMPT_ORDER); - request.getSession().removeAttribute(LEARNER_MARK_ATLEAST); request.getSession().removeAttribute(MAP_ANSWERS); request.getSession().removeAttribute(CURRENT_ANSWER); request.getSession().removeAttribute(USER_FEEDBACK); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java,v diff -u -r1.19 -r1.20 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java 17 Dec 2006 22:47:44 -0000 1.19 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcOptionsContentDAO.java 15 Aug 2007 03:54:50 -0000 1.20 @@ -44,8 +44,6 @@ public List findMcOptionUidsByQueId(Long mcQueContentId); - public McOptsContent findMcOptionsContentByUid(Long uid); - /** *

Return a list of a McOptsContents * with the given identifier mcQueContentId, returns null if not found.

Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUserDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUserDAO.java,v diff -u -r1.13 -r1.14 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUserDAO.java 17 Sep 2006 06:23:44 -0000 1.13 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUserDAO.java 15 Aug 2007 03:54:50 -0000 1.14 @@ -79,15 +79,6 @@ */ public void removeMcUserById(Long userId); - /** - * Returns the number of users that are in this particular - * session. - * - * @param nbSession - * @return the number of users that are in this session - */ - public int getNumberOfUsers(McSession mcSession); - public List getMcUserBySessionOnly(final McSession mcSession); public int getTotalNumberOfUsers(McContent mcContent); @@ -96,4 +87,6 @@ public int countUserComplete(McContent mcContent); + /** Get the max, min and average mark (in that order) for a session */ + public Integer[] getMarkStatisticsForSession(Long sessionUid); } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java,v diff -u -r1.17 -r1.18 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java 3 Dec 2006 21:23:36 -0000 1.17 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/IMcUsrAttemptDAO.java 15 Aug 2007 03:54:50 -0000 1.18 @@ -25,6 +25,7 @@ import java.util.List; import org.lamsfoundation.lams.tool.mc.pojos.McContent; +import org.lamsfoundation.lams.tool.mc.pojos.McSession; import org.lamsfoundation.lams.tool.mc.pojos.McUsrAttempt; @@ -83,33 +84,35 @@ public void removeMcUsrAttempt(McUsrAttempt mcUsrAttempt); /** - * *

returns the highest mark of a learner - * with the given identifier queUsrId

+ *

gets all the attempts (for all questions) for one user in one tool session

* * @param queUsrId * @return */ - public List getHighestMark(Long queUsrId); + public List getUserAttemptsForSession(Long queUsrId); /** - * *

returns the highest mark of a learner - * with the given identifier queUsrId

- * - * @param queUsrId - * @return - */ - public List getHighestAttemptOrder(Long queUsrId); + * Get the most recent attempts (for all questions) for one user in one tool session + * @param queUserUid + * @return + */ + public List getLatestAttemptsForAUser(Long queUserUid); /** - * *

returns a list of attempts - * with the given identifiers queUsrId and mcQueContentId

+ *

gets all the attempts for one questions for one user in one tool session queUsrId, + * ordered by the attempt id. If there is more than one option selected for a question, the attempts + * are "batched".

* * @param queUsrId - * @param mcQueContentId * @return */ - public List getAttemptForQueContent(final Long queUsrId, final Long mcQueContentId); + public List getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(Long queUsrUid, Long mcQueContentId); + /** + * Get the highest attempt order for a user for a particular question + */ + public List getLatestAttemptsForAUserForOneQuestionContent(Long queUsrUid, Long mcQueContentId); + /** * *

returns a list of attempts * with the given identifiers queUsrId and mcQueContentId and attemptOrder

@@ -119,35 +122,8 @@ * @param attemptOrder * @return */ - public List getAttemptByAttemptOrder(final Long queUsrId, final Long mcQueContentId, final Integer attemptOrder); - - /** - * *

returns a list of marks - * - * @return - */ - - public List getAttemptsForUser(final Long queUsrId); - - public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long mcQueContentId); - - public List getUserAttemptsForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid); - - public McUsrAttempt getAttemptWithLastAttemptOrderForUserInSession(Long queUsrUid, final Long mcSessionUid); - - public List getAttemptsForUserInSession(final Long queUsrUid, final Long mcSessionUid); - - public List getAttemptsForUserOnHighestAttemptOrderInSession(final Long queUsrUid, final Long mcSessionUid, final Integer attemptOrder); - - public List getAttemptsOnHighestAttemptOrder(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder); - - public boolean getUserAttemptCorrectForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder); - - public List getMarks(); - - public List getMarksForContent(McContent mcContent); - - public McUsrAttempt getUserAttemptForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder); + public List getAttemptByAttemptOrder(final Long queUsrUid, final Long mcQueContentId, final Integer attemptOrder); + } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java,v diff -u -r1.22 -r1.23 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java 17 Dec 2006 22:47:44 -0000 1.22 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McOptionsContentDAO.java 15 Aug 2007 03:54:50 -0000 1.23 @@ -44,8 +44,6 @@ //private static final String FIND_MC_OPTIONS_CONTENT = "from " + McOptsContent.class.getName() + " as mco where mc_que_content_id=?"; private static final String FIND_MC_OPTIONS_CONTENT = "from mcOptsContent in class McOptsContent where mcOptsContent.mcQueContentId=:mcQueContentUid order by mcOptsContent.displayOrder"; - private static final String FIND_MC_OPTIONS_CONTENT_BY_UID = "from mcOptsContent in class McOptsContent where mcOptsContent.uid=:uid"; - private static final String LOAD_OPTION_CONTENT_BY_OPTION_TEXT = "from mcOptsContent in class McOptsContent where mcOptsContent.mcQueOptionText=:option and mcOptsContent.mcQueContentId=:mcQueContentUid"; private static final String LOAD_PERSISTED_SELECTED_OPTIONS = "from mcOptsContent in class McOptsContent where mcOptsContent.mcQueContentId=:mcQueContentUid and mcOptsContent.correctOption = 1"; @@ -75,23 +73,6 @@ } - public McOptsContent findMcOptionsContentByUid(Long uid) - { - HibernateTemplate templ = this.getHibernateTemplate(); - if ( uid != null) { - List list = getSession().createQuery(FIND_MC_OPTIONS_CONTENT_BY_UID) - .setLong("uid",uid.longValue()) - .list(); - - if(list != null && list.size() > 0){ - McOptsContent mco = (McOptsContent) list.get(0); - return mco; - } - } - return null; - } - - public List findMcOptionUidsByQueId(Long mcQueContentId) { Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUserDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUserDAO.java,v diff -u -r1.18 -r1.19 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUserDAO.java 17 Sep 2006 06:23:45 -0000 1.18 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUserDAO.java 15 Aug 2007 03:54:50 -0000 1.19 @@ -43,11 +43,11 @@ private static final String COUNT_USERS_IN_SESSION = "select mu.queUsrId from McQueUsr mu where mu.mcSession= :mcSession"; - private static final String COUNT_USERS = "select mu.queUsrId from McQueUsr"; - private static final String LOAD_USER_FOR_SESSION = "from mcQueUsr in class McQueUsr where mcQueUsr.mcSessionId= :mcSessionId"; - + private static final String CALC_MARK_STATS_FOR_SESSION = "select max(mu.lastAttemptTotalMark), min(mu.lastAttemptTotalMark), avg(mu.lastAttemptTotalMark)" + +" from McQueUsr mu where mu.mcSessionId = :mcSessionUid"; + public McQueUsr getMcUserByUID(Long uid) { return (McQueUsr) this.getHibernateTemplate() @@ -137,14 +137,6 @@ } - public int getNumberOfUsers(McSession mcSession) - { - return (getHibernateTemplate().findByNamedParam(COUNT_USERS_IN_SESSION, - "mcSession", - mcSession)).size(); - } - - public int getTotalNumberOfUsers() { String query="from obj in class McQueUsr"; return this.getHibernateTemplate().find(query).size(); @@ -222,4 +214,16 @@ return totalUserCount; } + /** Get the max, min and average mark (in that order) for a session */ + public Integer[] getMarkStatisticsForSession(Long sessionUid) + { + Object[] stats = (Object[]) getSession().createQuery(CALC_MARK_STATS_FOR_SESSION) + .setLong("mcSessionUid",sessionUid.longValue()) + .uniqueResult(); + + return new Integer[]{(Integer)stats[0], (Integer)stats[1], new Integer(((Float)stats[2]).intValue())}; + } + + + } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java,v diff -u -r1.20 -r1.21 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java 3 Dec 2006 21:23:36 -0000 1.20 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/dao/hibernate/McUsrAttemptDAO.java 15 Aug 2007 03:54:50 -0000 1.21 @@ -22,45 +22,45 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.dao.hibernate; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.FlushMode; import org.lamsfoundation.lams.tool.mc.dao.IMcUsrAttemptDAO; -import org.lamsfoundation.lams.tool.mc.pojos.McContent; import org.lamsfoundation.lams.tool.mc.pojos.McUsrAttempt; import org.springframework.orm.hibernate3.HibernateTemplate; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** * @author Ozgur Demirtas *

Hibernate implementation for database access to McUsrAttempt for the mc tool.

+ *

Be very careful about the queUserId and the McQueUser.uid fields. McQueUser.queUsrId is the core's user id for this user and McQueUser.uid + * is the primary key for McQueUser. McUsrAttempt.queUsrId = McQueUser.uid, not McUsrAttempt.queUsrId = McQueUser.queUsrId + * as you would expect. A new McQueUser object is created for each new tool session, so if the McQueUser.uid is supplied, then this + * denotes one user in a particular tool session, but if McQueUser.queUsrId is supplied, then this is just the user, not the session and the session + * must also be checked. */ public class McUsrAttemptDAO extends HibernateDaoSupport implements IMcUsrAttemptDAO { static Logger logger = Logger.getLogger(McUsrAttemptDAO.class.getName()); - private static final String LOAD_HIGHEST_MARK_BY_USER_ID = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrId"; + private static final String LOAD_ATTEMPT_BY_USER_SESSION = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrUid"; + + private static final String LOAD_ATTEMPT_BY_ATTEMPT_ORDER = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrUid" + +" and mcUsrAttempt.mcQueContentId=:mcQueContentId and mcUsrAttempt.attemptOrder=:attemptOrder" + +" order by mcUsrAttempt.attemptOrder, mcUsrAttempt.mcOptionsContent.uid"; - private static final String LOAD_HIGHEST_ATTEMPT_ORDER_BY_USER_ID = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrId"; + private static final String LOAD_LAST_ATTEMPT_BY_ATTEMPT_ORDER = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.mcQueUsr.uid=:queUsrUid" + +" and mcUsrAttempt.mcQueContentId=:mcQueContentId and mcUsrAttempt.attemptOrder=mcUsrAttempt.mcQueUsr.lastAttemptOrder" + +" order by mcUsrAttempt.mcOptionsContent.uid"; + + private static final String LOAD_ATTEMPT_FOR_QUESTION_CONTENT = "from mcUsrAttempt in class McUsrAttempt " + +" where mcUsrAttempt.mcQueContentId=:mcQueContentId and mcUsrAttempt.queUsrId=:queUsrUid" + +" order by mcUsrAttempt.attemptOrder"; + + private static final String LOAD_LAST_ATTEMPTS = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.mcQueUsr.uid=:queUsrUid" + +" and mcUsrAttempt.attemptOrder=mcUsrAttempt.mcQueUsr.lastAttemptOrder" + +" order by mcUsrAttempt.mcQueContentId, mcUsrAttempt.mcOptionsContent.uid"; - private static final String LOAD_ATTEMPT_FOR_QUE_CONTENT = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrId and mcUsrAttempt.mcQueContentId=:mcQueContentId"; - - private static final String LOAD_ATTEMPT_FOR_USER = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrId"; - - private static final String LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrId and mcUsrAttempt.mcQueContentId=:mcQueContentId"; - - private static final String LOAD_ATTEMPT_BY_ATTEMPT_ORDER = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.queUsrId=:queUsrId and mcUsrAttempt.mcQueContentId=:mcQueContentId and attemptOrder=:attemptOrder"; - - private static final String LOAD_ATTEMPT_FOR_QUESTION_CONTENT = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.mcQueContentId=:mcQueContentId"; - - private static final String LOAD_MARK = "from mcUsrAttempt in class McUsrAttempt"; - - private static final String LOAD_ATTEMPTS_ON_HIGHEST_ATTEMPT_ORDER = "from mcUsrAttempt in class McUsrAttempt where mcUsrAttempt.attemptOrder=:attemptOrder"; - - private static final String LOAD_HIGHEST_MARK = "from mcUsrAttempt in class McUsrAttempt"; - public McUsrAttempt getMcUserAttemptByUID(Long uid) { return (McUsrAttempt) this.getHibernateTemplate() @@ -72,388 +72,43 @@ this.getHibernateTemplate().save(mcUsrAttempt); } - public List getHighestMark(Long queUsrId) + public List getUserAttemptsForSession(Long queUsrUid) { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_HIGHEST_MARK_BY_USER_ID) - .setLong("queUsrId", queUsrId.longValue()) + List list = getSession().createQuery(LOAD_ATTEMPT_BY_USER_SESSION) + .setLong("queUsrUid", queUsrUid.longValue()) .list(); return list; } - public List getMarks() - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_MARK) + public List getLatestAttemptsForAUser(final Long queUserUid) { + return (List) getSession().createQuery(LOAD_LAST_ATTEMPTS) + .setLong("queUsrUid", queUserUid.longValue()) .list(); - - return list; - } + } - public List getMarksForContent(McContent mcContent) - { - logger.debug("running getMarksForContent for mcContent:" + mcContent); - logger.debug("running getMarksForContent for mcContent uid :" + mcContent.getUid()); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_MARK) + // should be able to get rid of this one by rewriting export portfolio + @SuppressWarnings("unchecked") + public List getLatestAttemptsForAUserForOneQuestionContent(final Long queUsrUid, final Long mcQueContentId) { + return (List) getSession().createQuery(LOAD_LAST_ATTEMPT_BY_ATTEMPT_ORDER) + .setLong("queUsrUid", queUsrUid.longValue()) + .setLong("mcQueContentId", mcQueContentId.longValue()) .list(); + } - List userEntries= new ArrayList(); - - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - logger.debug("attempt content uid:" + attempt.getMcQueContent().getMcContent().getUid()); - - if (attempt.getMcQueContent().getMcContent().getUid() == mcContent.getUid()) - { - logger.debug("same content found:" + mcContent); - userEntries.add(attempt); - } - } - } - - logger.debug("returning userEntries:" + userEntries); - return userEntries; - } - - - - public List getHighestAttemptOrder(Long queUsrId) + @SuppressWarnings("unchecked") + public List getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(final Long queUsrUid, final Long mcQueContentId) { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_HIGHEST_ATTEMPT_ORDER_BY_USER_ID) - .setLong("queUsrId", queUsrId.longValue()) - .list(); - return list; - } - - - public List getAttemptsForUser(final Long queUsrId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER) - .setLong("queUsrId", queUsrId.longValue()) - .list(); - return list; - } - - public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long mcQueContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT) - .setLong("queUsrId", queUsrId.longValue()) + return (List)getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) .setLong("mcQueContentId", mcQueContentId.longValue()) + .setLong("queUsrUid", queUsrUid.longValue()) .list(); - - return list; } - - public List getUserAttemptsForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid) - { - logger.debug("starting getUserAttemptsForQuestionContentAndSessionUid:"); - logger.debug("queUsrUid:" + queUsrUid); - logger.debug("mcQueContentId:" + mcQueContentId); - logger.debug("mcSessionUid:" + mcSessionUid); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("mcQueContentId", mcQueContentId.longValue()) - .list(); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - - if (attempt.getMcQueUsr().getUid().toString().equals(queUsrUid.toString())) - { - logger.debug("queUsrUid equal:" + queUsrUid); - if (attempt.getMcQueUsr().getMcSession().getUid().toString().equals(mcSessionUid.toString())) - { - logger.debug("user belong to this session:" + mcSessionUid); - userEntries.add(attempt); - } - - } - } - } - logger.debug("userEntries:" + userEntries); - return userEntries; - } - - public List getAttemptsOnHighestAttemptOrder(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) + public List getAttemptByAttemptOrder(final Long queUsrUid, final Long mcQueContentId, final Integer attemptOrder) { - logger.debug("starting getUserAttemptsForQuestionContentAndSessionUid:"); - logger.debug("queUsrUid:" + queUsrUid); - logger.debug("mcQueContentId:" + mcQueContentId); - logger.debug("mcSessionUid:" + mcSessionUid); - logger.debug("attemptOrder:" + attemptOrder); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("mcQueContentId", mcQueContentId.longValue()) - .list(); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - - if (attempt.getMcQueUsr().getUid().toString().equals(queUsrUid.toString())) - { - logger.debug("queUsrUid equal:" + queUsrUid); - if (attempt.getMcQueUsr().getMcSession().getUid().toString().equals(mcSessionUid.toString())) - { - logger.debug("user belongs to this session:" + mcSessionUid); - - if (attempt.getAttemptOrder().intValue() == attemptOrder.intValue()) - userEntries.add(attempt); - } - - } - } - } - logger.debug("userEntries:" + userEntries); - return userEntries; - } - - - public List getAttemptsForUserInSession(final Long queUsrUid, final Long mcSessionUid) - { - logger.debug("starting getAttemptsForUserInSession:"); - logger.debug("queUsrUid:" + queUsrUid); - logger.debug("mcSessionUid:" + mcSessionUid); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_MARK) - .list(); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - - if (attempt.getMcQueUsr().getUid().toString().equals(queUsrUid.toString())) - { - logger.debug("queUsrUid equal:" + queUsrUid); - if (attempt.getMcQueUsr().getMcSession().getUid().toString().equals(mcSessionUid.toString())) - { - logger.debug("user belong to this session:" + mcSessionUid); - userEntries.add(attempt); - } - - } - } - } - logger.debug("userEntries:" + userEntries); - return userEntries; - } - - - public List getAttemptsForUserOnHighestAttemptOrderInSession(final Long queUsrUid, final Long mcSessionUid, final Integer attemptOrder) - { - logger.debug("starting getAttemptsForUserOnHighestAttemptOrderInSession:"); - logger.debug("queUsrUid:" + queUsrUid); - logger.debug("mcSessionUid:" + mcSessionUid); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPTS_ON_HIGHEST_ATTEMPT_ORDER) - .setInteger("attemptOrder", attemptOrder.intValue()) - .list(); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - - if (attempt.getMcQueUsr().getUid().toString().equals(queUsrUid.toString())) - { - logger.debug("queUsrUid equal:" + queUsrUid); - if (attempt.getMcQueUsr().getMcSession().getUid().toString().equals(mcSessionUid.toString())) - { - logger.debug("user belong to this session:" + mcSessionUid); - userEntries.add(attempt); - } - - } - } - } - logger.debug("userEntries:" + userEntries); - return userEntries; - } - - - public boolean getUserAttemptCorrectForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) - { - logger.debug("starting getUserAttemptsForQuestionContentAndSessionUid:"); - logger.debug("queUsrUid:" + queUsrUid); - logger.debug("mcQueContentId:" + mcQueContentId); - logger.debug("mcSessionUid:" + mcSessionUid); - logger.debug("attemptOrder:" + attemptOrder); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("mcQueContentId", mcQueContentId.longValue()) - .list(); - - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - - if (attempt.getMcQueUsr().getUid().toString().equals(queUsrUid.toString())) - { - logger.debug("queUsrUid equal:" + queUsrUid); - if (attempt.getMcQueUsr().getMcSession().getUid().toString().equals(mcSessionUid.toString())) - { - logger.debug("user belong to this session:" + mcSessionUid); - logger.debug("isAttemptCorrect:" + attempt.isAttemptCorrect()); - if (attempt.getAttemptOrder().intValue() == attemptOrder.intValue()) - return attempt.isAttemptCorrect(); - } - } - } - } - return false; - } - - - public McUsrAttempt getUserAttemptForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) - { - logger.debug("starting getUserAttemptsForQuestionContentAndSessionUid:"); - logger.debug("queUsrUid:" + queUsrUid); - logger.debug("mcQueContentId:" + mcQueContentId); - logger.debug("mcSessionUid:" + mcSessionUid); - logger.debug("attemptOrder:" + attemptOrder); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) - .setLong("mcQueContentId", mcQueContentId.longValue()) - .list(); - - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - - if (attempt.getMcQueUsr().getUid().toString().equals(queUsrUid.toString())) - { - logger.debug("queUsrUid equal:" + queUsrUid); - if (attempt.getMcQueUsr().getMcSession().getUid().toString().equals(mcSessionUid.toString())) - { - logger.debug("user belong to this session:" + mcSessionUid); - logger.debug("isAttemptCorrect:" + attempt.isAttemptCorrect()); - if (attempt.getAttemptOrder().intValue() == attemptOrder.intValue()) - return attempt; - } - } - } - } - return null; - } - - - - - public McUsrAttempt getAttemptWithLastAttemptOrderForUserInSession(Long queUsrUid, final Long mcSessionUid) - { - logger.debug("starting getLastAttemptOrderForUserInSession:"); - logger.debug("queUsrUid:" + queUsrUid); - logger.debug("mcSessionUid:" + mcSessionUid); - - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_MARK) - .list(); - - logger.debug("list:" + list); - - List userEntries= new ArrayList(); - if(list != null && list.size() > 0){ - Iterator listIterator=list.iterator(); - while (listIterator.hasNext()) - { - McUsrAttempt attempt=(McUsrAttempt)listIterator.next(); - logger.debug("attempt:" + attempt); - - if (attempt.getMcQueUsr().getUid().toString().equals(queUsrUid.toString())) - { - logger.debug("queUsrUid equal:" + queUsrUid); - if (attempt.getMcQueUsr().getMcSession().getUid().toString().equals(mcSessionUid.toString())) - { - logger.debug("user belong to this session:" + mcSessionUid); - userEntries.add(attempt); - } - - } - } - } - logger.debug("userEntries:" + userEntries); - - Iterator itAttempts=userEntries.iterator(); - int highestOrder=0; - McUsrAttempt mcHighestUsrAttempt=null; - - while (itAttempts.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - int currentOrder=mcUsrAttempt.getAttemptOrder().intValue(); - logger.debug("currentOrder: " + currentOrder); - - if (currentOrder > highestOrder) - { - mcHighestUsrAttempt=mcUsrAttempt; - highestOrder=currentOrder; - logger.debug("highestOrder is updated to: " + highestOrder); - } - } - - logger.debug("returning mcHighestUsrAttempt: " + mcHighestUsrAttempt); - logger.debug("highestOrder has become: " + highestOrder); - logger.debug("returning mcHighestUsrAttempt: " + mcHighestUsrAttempt); - return mcHighestUsrAttempt; - } - - - public List getAttemptForQueContent(final Long queUsrId, final Long mcQueContentId) - { - HibernateTemplate templ = this.getHibernateTemplate(); - List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUE_CONTENT) - .setLong("queUsrId", queUsrId.longValue()) - .setLong("mcQueContentId", mcQueContentId.longValue()) - .list(); - return list; - } - - - public List getAttemptByAttemptOrder(final Long queUsrId, final Long mcQueContentId, final Integer attemptOrder) - { - HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(LOAD_ATTEMPT_BY_ATTEMPT_ORDER) - .setLong("queUsrId", queUsrId.longValue()) + .setLong("queUsrUid", queUsrUid.longValue()) .setLong("mcQueContentId", mcQueContentId.longValue()) .setInteger("attemptOrder", attemptOrder.intValue()) .list(); @@ -479,5 +134,5 @@ this.getSession().setFlushMode(FlushMode.AUTO); this.getHibernateTemplate().delete(mcUsrAttempt); } - + } \ No newline at end of file Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McContent.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McContent.java,v diff -u -r1.15 -r1.16 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McContent.java 17 Nov 2006 11:13:03 -0000 1.15 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McContent.java 15 Aug 2007 03:54:49 -0000 1.16 @@ -27,6 +27,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; import java.util.TreeSet; import org.apache.commons.lang.builder.ToStringBuilder; @@ -503,4 +505,26 @@ public void setRandomize(boolean randomize) { this.randomize = randomize; } + + /** + * Get total possible marks for this content. Iterates over the McQueContents set + */ + public Integer getTotalMarksPossible() { + + int totalMarksPossible=0; + Iterator itQuestions=getMcQueContents().iterator() ; + while (itQuestions.hasNext()) + { + McQueContent mcQueContent = (McQueContent)itQuestions.next(); + Integer mark=mcQueContent.getMark(); + totalMarksPossible += (mark!=null ? mark.intValue() : 0); + } + logger.debug("totalMarksPossible: " + totalMarksPossible); + + return new Integer(totalMarksPossible); + } + + public boolean isPassMarkApplicable() { + return passMark != null; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueContent.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueContent.java,v diff -u -r1.7 -r1.8 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueContent.java 15 Oct 2006 11:08:51 -0000 1.7 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueContent.java 15 Aug 2007 03:54:49 -0000 1.8 @@ -267,6 +267,18 @@ this.mcOptionsContents = mcOptionsContents; } + /** Get an options content record by its uid. Iterates + * over the set from getMcOptionsContents(). */ + public McOptsContent getOptionsContentByUID(Long uid) { + Iterator iter = getMcOptionsContents().iterator(); + while (iter.hasNext()) { + McOptsContent elem = (McOptsContent) iter.next(); + if ( elem.getUid().equals(uid)) + return elem; + } + return null; + } + public String toString() { return new ToStringBuilder(this) .append("uid", getUid()) Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueUsr.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueUsr.java,v diff -u -r1.5 -r1.6 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueUsr.java 17 Sep 2006 06:23:45 -0000 1.5 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McQueUsr.java 15 Aug 2007 03:54:49 -0000 1.6 @@ -63,6 +63,10 @@ /** persistent field */ private Set mcUsrAttempts; + private Integer lastAttemptOrder; + + private Integer lastAttemptTotalMark; + /** full constructor */ public McQueUsr(Long queUsrId, String username, String fullname, org.lamsfoundation.lams.tool.mc.pojos.McSession mcSession, Set mcUsrAttempts) { this.queUsrId = queUsrId; @@ -149,6 +153,14 @@ public String toString() { return new ToStringBuilder(this) .append("uid", getUid()) + .append("queUsrId", getQueUsrId()) + .append("username", getUsername()) + .append("fullname", getFullname()) + .append("responseFinalised", isResponseFinalised()) + .append("viewSummaryRequested", isViewSummaryRequested()) + .append("mcSessionId", getMcSessionId()) + .append("lastAttemptOrder", getLastAttemptOrder()) + .append("lastAttemptTotalMark", getLastAttemptTotalMark()) .toString(); } @@ -176,4 +188,40 @@ public void setViewSummaryRequested(boolean viewSummaryRequested) { this.viewSummaryRequested = viewSummaryRequested; } + + public Integer getLastAttemptOrder() { + return lastAttemptOrder; + } + + public void setLastAttemptOrder(Integer lastAttemptOrder) { + this.lastAttemptOrder = lastAttemptOrder; + } + + public Integer getLastAttemptTotalMark() { + return lastAttemptTotalMark; + } + + public void setLastAttemptTotalMark(Integer lastAttemptTotalMark) { + this.lastAttemptTotalMark = lastAttemptTotalMark; + } + + /** Is the latest attempt a pass? True if and only if passmark is applicable for + * the related content and the user's lastAttemptTotalMark >= passmark. + */ + public boolean isLastAttemptMarkPassed() { + return isMarkPassed(lastAttemptTotalMark); + } + + /** Does this mark count as a pass? True if and only if passmark is applicable for + * the related content and the given mark >= passmark. Used to calculate + * if the user has passed before setting up the learner's attempts. + */ + public boolean isMarkPassed(Integer mark) { + McContent content = mcSession.getMcContent(); + if ( mark != null && content.isPassMarkApplicable() ) { + Integer passMark = content.getPassMark(); + return passMark!=null && (mark.compareTo(passMark) >= 0); + } + return false; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McUsrAttempt.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McUsrAttempt.java,v diff -u -r1.6 -r1.7 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McUsrAttempt.java 15 Oct 2006 11:08:51 -0000 1.6 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/pojos/McUsrAttempt.java 15 Aug 2007 03:54:49 -0000 1.7 @@ -275,4 +275,18 @@ public void setFinished(boolean finished) { this.finished = finished; } + + /** Get the mark for displaying to the user. + * If retries or passmark is off, then just check whether or not answer is correct + * If retries and passmark is on, then we only want the marks if the user has passed! + */ + public Integer getMarkForShow( boolean allowRetries ) { + if ( isAttemptCorrect() && + ( !allowRetries || (allowRetries && isPassed()) ) ) { + return getMark(); + } else { + return new Integer(0); + } + } + } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java,v diff -u -r1.63 -r1.64 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 9 May 2007 00:57:12 -0000 1.63 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/IMcService.java 15 Aug 2007 03:54:49 -0000 1.64 @@ -25,6 +25,8 @@ import java.io.InputStream; import java.util.List; +import javax.servlet.http.HttpServletRequest; + import org.lamsfoundation.lams.contentrepository.ITicket; import org.lamsfoundation.lams.contentrepository.NodeKey; import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; @@ -78,9 +80,7 @@ public void createMcUsrAttempt(McUsrAttempt mcUsrAttempt) throws McApplicationException; public void updateMcUsrAttempt(McUsrAttempt mcUsrAttempt) throws McApplicationException; - - public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long mcQueContentId) throws McApplicationException; - + public McQueContent retrieveMcQueContentByUID(Long uid) throws McApplicationException; public void removeMcQueContent(McQueContent mcQueContent) throws McApplicationException; @@ -105,8 +105,6 @@ public List findMcOptionUidsByQueId(Long mcQueContentId) throws McApplicationException; - public McOptsContent findMcOptionsContentByUid(Long uid) throws McApplicationException; - public McQueContent findMcQuestionContentByUid(Long uid) throws McApplicationException; public void removeMcOptionsContentByQueId(Long mcQueContentId) throws McApplicationException; @@ -123,7 +121,7 @@ public List getCorrectOption(Long mcQueContentId); - public List getAllQuestionEntries(final Long mcContentId) throws McApplicationException; + public List getAllQuestionEntries(final Long mcContentId) throws McApplicationException; public McSession retrieveMcSession(Long mcSessionId) throws McApplicationException; @@ -141,6 +139,8 @@ public McSession getMcSessionByUID(Long uid) throws McApplicationException; + public List getLatestAttemptsForAUser(final Long queUserUid) throws McApplicationException; + public void deleteMc(McContent mc) throws McApplicationException; public void deleteMcById(Long mcId) throws McApplicationException; @@ -179,18 +179,18 @@ public boolean studentActivityOccurredGlobal(McContent mcContent) throws McApplicationException; - public List getUserAttemptsForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid) throws McApplicationException; - - public boolean getUserAttemptCorrectForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException; - - public List getAttemptsForUserInSession(final Long queUsrUid, final Long mcSessionUid) throws McApplicationException; - - public List getAttemptsForUserOnHighestAttemptOrderInSession(final Long queUsrUid, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException; - - public List getAttemptsOnHighestAttemptOrder(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException; - - public McUsrAttempt getAttemptWithLastAttemptOrderForUserInSession(Long queUsrUid, final Long mcSessionUid) throws McApplicationException; - + /** + *

gets all the attempts for one questions for one user in one tool session queUsrId, + * ordered by the attempt id. If there is more than one option selected for a question, the attempts + * are "batched".

+ * + * @param queUsrId + * @return + */ + public List getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(Long queUsrUid, Long mcQueContentId) throws McApplicationException; + + public List getLatestAttemptsForAUserForOneQuestionContent(Long queUsrUid, Long mcQueContentId) throws McApplicationException; + public int countIncompleteSession(McContent mc) throws McApplicationException; public boolean studentActivityOccurred(McContent mc) throws McApplicationException; @@ -239,18 +239,8 @@ public void persistFile(String uuid, boolean isOnlineFile, String fileName, McContent mcContent) throws McApplicationException; - public List getHighestMark(Long queUsrId) throws McApplicationException; - - public List getHighestAttemptOrder(Long queUsrId) throws McApplicationException; - - public List getAttemptForQueContent(final Long queUsrId, final Long mcQueContentId) throws McApplicationException; - public List getAttemptByAttemptOrder(final Long queUsrId, final Long mcQueContentId, final Integer attemptOrder) throws McApplicationException; - public List getAttemptsForUser(final Long queUsrId) throws McApplicationException; - - public List getMarks() throws McApplicationException; - public int countSessionComplete() throws McApplicationException; public int countSessionComplete(McContent mcContent) throws McApplicationException; @@ -286,9 +276,12 @@ public List retrieveMcUploadedFiles(McContent mcContent) throws McApplicationException; - public List getMarksForContent(McContent mcContent) throws McApplicationException; - - public McUsrAttempt getUserAttemptForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException; - + /** + * Return the top, lowest and average mark for all learners for one particular tool session. + * @param request + * @return top mark, lowest mark, average mark in that order + */ + public Integer[] getMarkStatistics(McSession mcSession); + } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java,v diff -u -r1.94 -r1.95 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 9 May 2007 00:57:11 -0000 1.94 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/service/McServicePOJO.java 15 Aug 2007 03:54:49 -0000 1.95 @@ -30,6 +30,8 @@ import java.util.TreeSet; import java.util.Vector; +import javax.servlet.http.HttpServletRequest; + import org.apache.log4j.Logger; import org.lamsfoundation.lams.contentrepository.AccessDeniedException; import org.lamsfoundation.lams.contentrepository.FileException; @@ -483,21 +485,6 @@ } - public List getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long mcQueContentId) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getAttemptsForUserAndQuestionContent(queUsrId, mcQueContentId); - } - catch (DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is getting mc UsrAttempt by user id and que content id: " - + e.getMessage(), - e); - } - } - - public void updateMcUsrAttempt(McUsrAttempt mcUsrAttempt) throws McApplicationException { try @@ -512,83 +499,70 @@ } } - - public List getHighestMark(Long queUsrId) throws McApplicationException + public List getAttemptByAttemptOrder(final Long queUsrId, final Long mcQueContentId, final Integer attemptOrder) throws McApplicationException { try { - return mcUsrAttemptDAO.getHighestMark(queUsrId); + return mcUsrAttemptDAO.getAttemptByAttemptOrder(queUsrId, mcQueContentId, attemptOrder); } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is getting the learner's highest mark: " + throw new McApplicationException("Exception occured when lams is getting the learner's attempts by user id and que content id and attempt order: " + e.getMessage(), e); } } - - public List getHighestAttemptOrder(Long queUsrId) throws McApplicationException + public List getLatestAttemptsForAUser(final Long queUserUid) throws McApplicationException { try { - return mcUsrAttemptDAO.getHighestAttemptOrder(queUsrId); + return mcUsrAttemptDAO.getLatestAttemptsForAUser(queUserUid); } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is getting the learner's highest attempt order: " + throw new McApplicationException("Exception occured when lams is getting the learner's attempts by user id and que content id and attempt order: " + e.getMessage(), e); } } - - - public List getAttemptsForUser(final Long queUsrId) throws McApplicationException - { - try + + /** + *

gets all the attempts for one questions for one user in one tool session queUsrId, + * ordered by the attempt id. If there is more than one option selected for a question, the attempts + * are "batched".

+ * + * @param queUsrId + * @return + */ + public List getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(final Long queUsrUid, final Long mcQueContentId) throws McApplicationException + { + try { - return mcUsrAttemptDAO.getAttemptsForUser(queUsrId); + return mcUsrAttemptDAO.getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(queUsrUid, mcQueContentId); } - catch (DataAccessException e) + catch(DataAccessException e) { - throw new McApplicationException("Exception occured when lams is getting the attempts by user id: " - + e.getMessage(), - e); - } - - } - - - public List getAttemptForQueContent(final Long queUsrId, final Long mcQueContentId) throws McApplicationException + throw new McApplicationException("Exception occured when lams is getting attempts. " + + e.getMessage(),e); + } + } + + + public List getLatestAttemptsForAUserForOneQuestionContent(Long queUsrUid, Long mcQueContentId) throws McApplicationException { try { - return mcUsrAttemptDAO.getAttemptForQueContent(queUsrId, mcQueContentId); + return mcUsrAttemptDAO.getLatestAttemptsForAUserForOneQuestionContent(queUsrUid, mcQueContentId); } catch (DataAccessException e) { - throw new McApplicationException("Exception occured when lams is getting the learner's attempts by user id and que content id: " - + e.getMessage(), - e); - } - } - - - public List getAttemptByAttemptOrder(final Long queUsrId, final Long mcQueContentId, final Integer attemptOrder) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getAttemptByAttemptOrder(queUsrId, mcQueContentId, attemptOrder); - } - catch (DataAccessException e) - { throw new McApplicationException("Exception occured when lams is getting the learner's attempts by user id and que content id and attempt order: " + e.getMessage(), e); } } - - + public McQueContent retrieveMcQueContentByUID(Long uid) throws McApplicationException { try @@ -618,11 +592,11 @@ } } - public List getAllQuestionEntries(final Long uid) throws McApplicationException + public List getAllQuestionEntries(final Long uid) throws McApplicationException { try { - return mcQueContentDAO.getAllQuestionEntries(uid.longValue()); + return (List) mcQueContentDAO.getAllQuestionEntries(uid.longValue()); } catch (DataAccessException e) { @@ -940,132 +914,18 @@ } - public List getMarksForContent(McContent mcContent) throws McApplicationException + /** + * Return the top, lowest and average mark for all learners for one particular tool session. + * + * @param request + * @return top mark, lowest mark, average mark in that order + */ + public Integer[] getMarkStatistics(McSession mcSession) { - try - { - return mcUsrAttemptDAO.getMarksForContent(mcContent); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is getting marks " - + e.getMessage(),e); - } + logger.debug("getting mark statistics on mcSession: " + mcSession.getUid()); + return mcUserDAO.getMarkStatisticsForSession(mcSession.getUid()); } - public List getMarks() throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getMarks(); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is getting marks " - + e.getMessage(),e); - } - } - - - public McUsrAttempt getAttemptWithLastAttemptOrderForUserInSession(Long queUsrUid, final Long mcSessionUid) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getAttemptWithLastAttemptOrderForUserInSession(queUsrUid, mcSessionUid); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is getting last attempt order for user in session" - + e.getMessage(),e); - } - } - - - public List getUserAttemptsForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid) - { - try - { - return mcUsrAttemptDAO.getUserAttemptsForQuestionContentAndSessionUid(queUsrUid, mcQueContentId, mcSessionUid); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is getting marks based on userid, sessionid and que content id " - + e.getMessage(),e); - } - } - - - public List getAttemptsForUserOnHighestAttemptOrderInSession(final Long queUsrUid, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getAttemptsForUserOnHighestAttemptOrderInSession(queUsrUid, mcSessionUid, attemptOrder); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is finding whether attempt is correct based on userid, sessionid" - + e.getMessage(),e); - } - } - - public List getAttemptsOnHighestAttemptOrder(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getAttemptsOnHighestAttemptOrder(queUsrUid, mcQueContentId, mcSessionUid, attemptOrder); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is getting attempts on hightest attempt order" - + e.getMessage(),e); - } - } - - public List getAttemptsForUserInSession(final Long queUsrUid, final Long mcSessionUid) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getAttemptsForUserInSession(queUsrUid, mcSessionUid); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is finding whether attempt is correct based on userid, sessionid" - + e.getMessage(),e); - } - } - - - public boolean getUserAttemptCorrectForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getUserAttemptCorrectForQuestionContentAndSessionUid(queUsrUid, mcQueContentId, mcSessionUid, attemptOrder); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is finding whether attempt is correct based on userid, sessionid and que content id " - + e.getMessage(),e); - } - } - - - - public McUsrAttempt getUserAttemptForQuestionContentAndSessionUid(final Long queUsrUid, final Long mcQueContentId, final Long mcSessionUid, final Integer attemptOrder) throws McApplicationException - { - try - { - return mcUsrAttemptDAO.getUserAttemptForQuestionContentAndSessionUid(queUsrUid, mcQueContentId, mcSessionUid, attemptOrder); - } - catch(DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is running getUserAttemptForQuestionContentAndSessionUid:" - + e.getMessage(),e); - } - } - - - - public void deleteMcQueUsr(McQueUsr mcQueUsr) throws McApplicationException { try @@ -1151,19 +1011,6 @@ } } - public McOptsContent findMcOptionsContentByUid(Long uid) throws McApplicationException - { - try - { - return mcOptionsContentDAO.findMcOptionsContentByUid(uid); - } - catch (DataAccessException e) - { - throw new McApplicationException("Exception occured when lams is getting opts by uid" - + e.getMessage(),e); - } - } - public void saveMcOptionsContent(McOptsContent mcOptsContent) throws McApplicationException { try Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java,v diff -u -r1.14 -r1.15 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java 23 May 2007 04:20:00 -0000 1.14 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/ExportServlet.java 15 Aug 2007 03:54:50 -0000 1.15 @@ -129,9 +129,7 @@ request.getSession().setAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO, listMonitoredAnswersContainerDTO); logger.debug("LIST_MONITORED_ANSWERS_CONTAINER_DTO: " + request.getSession().getAttribute(LIST_MONITORED_ANSWERS_CONTAINER_DTO)); - String intTotalMark=viewAnswers(request, content, learner, mcSession, mcService); - logger.debug("intTotalMark: " + intTotalMark); - request.getSession().setAttribute(LEARNER_MARK,intTotalMark); + request.getSession().setAttribute(LEARNER_MARK,learner.getLastAttemptTotalMark()); request.getSession().setAttribute(LEARNER_NAME,learner.getFullname() ); request.getSession().setAttribute(PASSMARK,content.getPassMark().toString()); @@ -142,213 +140,6 @@ } - /** - * viewAnswers(HttpServletRequest request, McContent content, McQueUsr mcQueUsr, McSession mcSession, IMcService mcService) - * - * @param request - * @param content - * @param mcQueUsr - * @param mcSession - * @param mcService - * @return - */ - public String viewAnswers(HttpServletRequest request, McContent content, McQueUsr mcQueUsr, McSession mcSession, IMcService mcService) - { - logger.debug("starting viewAnswers..."); - int intTotalMark=0; - - McUsrAttempt mcUsrAttempt = mcService.getAttemptWithLastAttemptOrderForUserInSession(mcQueUsr.getUid(), mcSession.getUid()); - logger.debug("mcUsrAttempt with highest attempt order: " + mcUsrAttempt); - - int totalQuestionCount=content.getMcQueContents().size(); - logger.debug("totalQuestionCount: " + totalQuestionCount); - - Long toolContentUID=content.getUid(); - logger.debug("toolContentUID: " + toolContentUID); - logger.debug("mcQueUsr: " + mcQueUsr); - - Long queUsrId=mcQueUsr.getUid(); - logger.debug("queUsrId: " + queUsrId); - - Map mapResponses= new TreeMap(new McComparator()); - Map mapQueAttempts= new TreeMap(new McComparator()); - Map mapQueCorrectAttempts= new TreeMap(new McComparator()); - Map mapQueIncorrectAttempts= new TreeMap(new McComparator()); - - for (int i=1; i<= new Integer(totalQuestionCount).intValue(); i++) - { - logger.debug("doing question with display order: " + i); - McQueContent mcQueContent=mcService.getQuestionContentByDisplayOrder(new Long(i), toolContentUID); - logger.debug("mcQueContent uid: " + mcQueContent.getUid()); - - int intCurrentMark=0; - - - /**calculating learner's mark*/ - if (mcUsrAttempt != null) - { - String highestAttemptOrder=mcUsrAttempt.getAttemptOrder().toString(); - logger.debug("highestAttemptOrder: " + highestAttemptOrder); - - List listUserAttempts=mcService.getAttemptsOnHighestAttemptOrder(mcQueUsr.getUid(), mcQueContent.getUid(), mcSession.getUid(), new Integer(highestAttemptOrder)); - logger.debug("listUserAttempts: " + listUserAttempts); - - Iterator itAttempts=listUserAttempts.iterator(); - - if (!mcSession.getMcContent().isRetries()) - { - logger.debug("retries is OFF."); - boolean isAttemptCorrect=false; - McUsrAttempt mcUsrAttemptUser=null; - - while (itAttempts.hasNext()) - { - mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - mcUsrAttemptUser=mcUsrAttempt; - - if (mcUsrAttempt != null) - { - if (mcUsrAttempt.isAttemptCorrect()) - { - isAttemptCorrect=true; - } - } - } - logger.debug("final isAttemptCorrect: " + isAttemptCorrect); - logger.debug("mcUsrAttemptUser: " + mcUsrAttemptUser); - - String currentMark=""; - if (isAttemptCorrect) - { - currentMark= mcUsrAttemptUser.getMcQueContent().getMark().toString(); - } - else - { - currentMark= "0"; - } - mapResponses.put(new Integer(i).toString(), currentMark); - intCurrentMark=new Integer(currentMark).intValue(); - logger.debug("intCurrentMark: " + intCurrentMark); - - } - else - { - logger.debug("retries is ON. User had to PASS. Print the final attempt's data"); - boolean isAttemptCorrect=false; - McUsrAttempt mcUsrAttemptGeneral=null; - while (itAttempts.hasNext()) - { - mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - mcUsrAttemptGeneral=mcUsrAttempt; - - if (mcUsrAttempt != null) - { - if (mcUsrAttempt.isFinished() && mcUsrAttempt.isPassed()) - { - logger.debug("this is a individual question attempt that is finished and passed: " + mcUsrAttempt); - isAttemptCorrect=mcService.getUserAttemptCorrectForQuestionContentAndSessionUid(mcQueUsr.getUid(), - mcQueContent.getUid(), mcSession.getUid(), new Integer(highestAttemptOrder)); - logger.debug("isAttemptCorrect: " + isAttemptCorrect); - break; - } - } - } - - logger.debug("final isAttemptCorrect: " + isAttemptCorrect); - - String currentMark=""; - if (isAttemptCorrect) - { - currentMark= mcUsrAttempt.getMcQueContent().getMark().toString(); - } - else - { - currentMark= "0"; - } - mapResponses.put(new Integer(i).toString(), currentMark); - intCurrentMark=new Integer(currentMark).intValue(); - logger.debug("intCurrentMark: " + intCurrentMark); - } - } - else - { - intCurrentMark=0; - mapResponses.put(new Integer(i).toString(), "0"); - } - - intTotalMark=intTotalMark + intCurrentMark; - logger.debug("intTotalMark: " + intTotalMark); - - Map mapAttemptOrderCorrectAttempts= new TreeMap(new McComparator()); - Map mapAttemptOrderIncorrectAttempts= new TreeMap(new McComparator()); - Map mapAttemptOrderAttempts= new TreeMap(new McComparator()); - for (int j=1; j <= MAX_ATTEMPT_HISTORY ; j++ ) - { - logger.debug("getting list for queUsrId: " + queUsrId); - List attemptsByAttemptOrder=mcService.getAttemptByAttemptOrder(queUsrId, mcQueContent.getUid(), new Integer(j)); - logger.debug("attemptsByAttemptOrder: " + j + " is: " + attemptsByAttemptOrder); - - Map mapAttempts= new TreeMap(new McComparator()); - Map mapAttemptsIncorrect= new TreeMap(new McComparator()); - Map mapAttemptsCorrect= new TreeMap(new McComparator()); - - Iterator attemptIterator=attemptsByAttemptOrder.iterator(); - Long mapIndex=new Long(1); - while (attemptIterator.hasNext()) - { - McUsrAttempt localMcUsrAttempt=(McUsrAttempt)attemptIterator.next(); - logger.debug("localMcUsrAttempt: " + localMcUsrAttempt); - - mapAttempts.put(mapIndex.toString(), localMcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - logger.debug("added attempt with order: " + localMcUsrAttempt.getAttemptOrder() + " , option text is: " + localMcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - mapIndex=new Long(mapIndex.longValue()+1); - } - - logger.debug("final mapAttempts is: " + mapAttempts); - if (mapAttempts.size() > 0) - { - mapAttemptOrderAttempts.put(new Integer(j).toString(), mapAttempts); - } - if (mapAttemptsCorrect.size() > 0) - { - mapAttemptOrderCorrectAttempts.put(new Integer(j).toString(), mapAttemptsCorrect); - } - if (mapAttemptsIncorrect.size() > 0) - { - mapAttemptOrderIncorrectAttempts.put(new Integer(j).toString(), mapAttemptsIncorrect); - } - - } - - logger.debug("final mapAttemptOrderAttempts is: " + mapAttemptOrderAttempts); - if (mapAttemptOrderAttempts.size() > 0) - { - mapQueAttempts.put(new Integer(i).toString(), mapAttemptOrderAttempts); - } - if (mapAttemptOrderCorrectAttempts.size() > 0) - { - mapQueCorrectAttempts.put(new Integer(i).toString(), mapAttemptOrderCorrectAttempts); - } - if (mapAttemptOrderIncorrectAttempts.size() > 0) - { - mapQueIncorrectAttempts.put(new Integer(i).toString(), mapAttemptOrderIncorrectAttempts); - } - - } - request.getSession().setAttribute(MAP_QUE_ATTEMPTS, mapQueAttempts); - logger.debug("final mapQueAttempts is: " + mapQueAttempts); - request.getSession().setAttribute(MAP_QUE_CORRECT_ATTEMPTS, mapQueCorrectAttempts); - request.getSession().setAttribute(MAP_QUE_INCORRECT_ATTEMPTS, mapQueIncorrectAttempts); - request.getSession().setAttribute(MAP_RESPONSES, mapResponses); - - logger.debug("final MAP_RESPONSES is: " + mapResponses); - logger.debug("final intTotalMark is: " + intTotalMark); - return new Integer(intTotalMark).toString(); - } - - /** * teacher(HttpServletRequest request, HttpServletResponse response, String directoryName, Cookie[] cookies) * Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java,v diff -u -r1.47 -r1.48 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java 6 Feb 2007 05:24:52 -0000 1.47 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/LearningUtil.java 15 Aug 2007 03:54:49 -0000 1.48 @@ -150,205 +150,8 @@ logger.debug("totalUserWeight: " + totalUserWeight); return totalUserWeight; } - - - public static String getTotalMarksPossible(McContent mcContent) - { - logger.debug("starting getTotalMarksPossible: " + mcContent); - - int totalMarksPossible=0; - Iterator itQuestions=mcContent.getMcQueContents().iterator() ; - while (itQuestions.hasNext()) - { - McQueContent mcQueContent = (McQueContent)itQuestions.next(); - logger.debug("mcQueContent: " + mcQueContent); - - Integer mark=mcQueContent.getMark(); - logger.debug("mark: " + mark); - - int intMark=0; - if (mark != null) - intMark=mark.intValue(); - - logger.debug("intMark: " + intMark); - - totalMarksPossible+=intMark; - } - logger.debug("totalMarksPossible: " + totalMarksPossible); - - String strTotalMarksPossible= new Integer(totalMarksPossible).toString(); - return strTotalMarksPossible; - } - - - + /** - * calculates the mark of a learner - * getMark(Map mapLeanerAssessmentResults) - * - * @param mapLeanerAssessmentResults - * @return int - */ - public static int getMark(Map mapLeanerAssessmentResults) - { - int totalUserWeight=0; - Iterator itLearnerAssessmentMap = mapLeanerAssessmentResults.entrySet().iterator(); - int correctAnswerCount=0; - while (itLearnerAssessmentMap.hasNext()) - { - Map.Entry pairs = (Map.Entry)itLearnerAssessmentMap.next(); - if (pairs.getValue().toString().equalsIgnoreCase("true")) - { - ++correctAnswerCount; - } - } - return correctAnswerCount; - } - - /** - * calculates the max attempt count of a learner - * getHighestAttemptOrder(HttpServletRequest request, Long queUsrId) - * - * @param request - * @param queUsrId - * @return - */ - public static int getHighestAttemptOrder(HttpServletRequest request, Long queUsrId, IMcService mcService) - { - logger.debug("mcService: " + mcService); - List listMarks=mcService.getHighestAttemptOrder(queUsrId); - - Iterator itMarks=listMarks.iterator(); - int highestAO=0; - while (itMarks.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)itMarks.next(); - int currentAO=mcUsrAttempt.getAttemptOrder().intValue(); - if (currentAO > highestAO) - highestAO= currentAO; - } - return highestAO; - } - - - /** - * returns the highest mark a learner has achieved - * getHighestMark(HttpServletRequest request, Long queUsrId) - * - * @param request - * @param queUsrId - * @return - */ - public static int getHighestMark(HttpServletRequest request, Long queUsrId, IMcService mcService) - { - List listMarks=mcService.getHighestMark(queUsrId); - - Iterator itMarks=listMarks.iterator(); - int highestMark=0; - while (itMarks.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)itMarks.next(); - int currentMark=mcUsrAttempt.getMark().intValue(); - if (currentMark > highestMark) - highestMark= currentMark; - } - return highestMark; - } - - /** - * return the top mark for all learners - * getTopMark(HttpServletRequest request) - * - * @param request - * @return - */ - public static int getTopMark(HttpServletRequest request, IMcService mcService, McContent mcContent) - { - logger.debug("performing getTopMark on mcContent: " + mcContent); - List listMarks=mcService.getMarksForContent(mcContent); - logger.debug("listMarks: " + listMarks); - - Iterator itMarks=listMarks.iterator(); - int highestMark=0; - while (itMarks.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)itMarks.next(); - int currentMark=mcUsrAttempt.getMark().intValue(); - if (currentMark > highestMark) - highestMark= currentMark; - } - return highestMark; - } - - - /** - * return the lowest mark for all learners - * getTopMark(HttpServletRequest request) - * - * @param request - * @return - */ - public static int getLowestMark(HttpServletRequest request, IMcService mcService, McContent mcContent) - { - logger.debug("performing getLowestMark on mcContent: " + mcContent); - List listMarks=mcService.getMarksForContent(mcContent); - logger.debug("listMarks: " + listMarks); - - Iterator itMarks=listMarks.iterator(); - int lowestMark=100; - while (itMarks.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)itMarks.next(); - int currentMark=mcUsrAttempt.getMark().intValue(); - if (currentMark < lowestMark) - lowestMark= currentMark; - } - - //in case there was no attempts - if (lowestMark == 100) - lowestMark=0; - - return lowestMark; - } - - /** - * return the average mark for all learners - * getTopMark(HttpServletRequest request) - * - * @param request - * @return - */ - public static int getAverageMark(HttpServletRequest request, IMcService mcService, McContent mcContent) - { - logger.debug("performing getAverageMark on mcContent: " + mcContent); - List listMarks=mcService.getMarksForContent(mcContent); - logger.debug("listMarks: " + listMarks); - - Iterator itMarks=listMarks.iterator(); - int marksTotal=0; - int count=0; - while (itMarks.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)itMarks.next(); - int currentMark=mcUsrAttempt.getMark().intValue(); - marksTotal=marksTotal + currentMark; - count++; - } - logger.debug("marksTotal: " + marksTotal); - logger.debug("count: " + count); - - int averageMark=0; - if (count > 0) - { - averageMark= (marksTotal / count); - } - - logger.debug("averageMark: " + averageMark); - return averageMark; - } - - - /** * conversts correct options list to correct options map * buildMapCorrectOptions(List correctOptions) * @@ -579,7 +382,7 @@ /** * createLearnerAttempt(HttpServletRequest request, McQueUsr mcQueUsr, List selectedQuestionAndCandidateAnswersDTO, - int mark, boolean passed, int highestAttemptOrder, Map mapLeanerAssessmentResults, IMcService mcService) + Integer totalMark, boolean passed, int highestAttemptOrder, Map mapLeanerAssessmentResults, IMcService mcService) * @param request * @param mcQueUsr @@ -591,33 +394,33 @@ * @param mcService */ public static void createLearnerAttempt(HttpServletRequest request, McQueUsr mcQueUsr, List selectedQuestionAndCandidateAnswersDTO, - int mark, boolean passed, int highestAttemptOrder, Map mapLeanerAssessmentResults, IMcService mcService) + boolean passed, Integer highestAttemptOrder, Map mapLeanerAssessmentResults, IMcService mcService) { logger.debug("starting createLearnerAttempt: "); - Date attempTime=McUtils.getGMTDateTime(); + Date attemptTime=McUtils.getGMTDateTime(); Iterator itSelectedMap = selectedQuestionAndCandidateAnswersDTO.iterator(); while (itSelectedMap.hasNext()) { McLearnerAnswersDTO mcLearnerAnswersDTO=(McLearnerAnswersDTO)itSelectedMap.next(); - logger.debug("mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); - String questionUid=mcLearnerAnswersDTO.getQuestionUid(); - logger.debug("questionUid: " + questionUid); + + if ( logger.isDebugEnabled() ) { + logger.debug("mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); + } + + McQueContent mcQueContent=mcService.findMcQuestionContentByUid(mcLearnerAnswersDTO.getQuestionUid()); - McQueContent mcQueContent=mcService.findMcQuestionContentByUid(new Long(questionUid)); - logger.debug("mcQueContent: " + mcQueContent); - - Map candidateAnswers=mcLearnerAnswersDTO.getCandidateAnswers(); - logger.debug("candidateAnswers: " + candidateAnswers); - - String isAttemptCorrect=mcLearnerAnswersDTO.getAttemptCorrect(); - logger.debug("isAttemptCorrect: " + isAttemptCorrect); - - logger.debug("requesting createIndividualOptions"); - createIndividualOptions(request, candidateAnswers, mcQueContent, mcQueUsr, attempTime, mark, passed, - new Integer(highestAttemptOrder), isAttemptCorrect,mcService); + createIndividualOptions(request, + mcLearnerAnswersDTO.getCandidateAnswers(), + mcQueContent, mcQueUsr, + attemptTime, + mcLearnerAnswersDTO.getMark(), + passed, + highestAttemptOrder, + mcLearnerAnswersDTO.getAttemptCorrect(), + mcService); } - + } @@ -631,15 +434,15 @@ * @param candidateAnswers * @param mcQueContent * @param mcQueUsr - * @param attempTime + * @param attemptTime * @param mark * @param passed * @param highestAttemptOrder * @param isAttemptCorrect * @param mcService */ public static void createIndividualOptions(HttpServletRequest request, Map candidateAnswers, McQueContent mcQueContent, - McQueUsr mcQueUsr, Date attempTime, int mark, boolean passed, Integer highestAttemptOrder, String isAttemptCorrect, + McQueUsr mcQueUsr, Date attemptTime, int mark, boolean passed, Integer highestAttemptOrder, String isAttemptCorrect, IMcService mcService) { logger.debug("starting createIndividualOptions"); @@ -663,7 +466,7 @@ logger.debug("mcOptsContent: " + mcOptsContent); if (mcOptsContent != null) { - McUsrAttempt mcUsrAttempt=new McUsrAttempt(attempTime, mcQueContent, mcQueUsr, mcOptsContent, IntegerMark, passed, highestAttemptOrder, new Boolean(isAttemptCorrect).booleanValue()); + McUsrAttempt mcUsrAttempt=new McUsrAttempt(attemptTime, mcQueContent, mcQueUsr, mcOptsContent, IntegerMark, passed, highestAttemptOrder, new Boolean(isAttemptCorrect).booleanValue()); mcService.createMcUsrAttempt(mcUsrAttempt); logger.debug("created mcUsrAttempt in the db :" + mcUsrAttempt); } @@ -718,7 +521,7 @@ mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); mcGeneralLearnerFlowDTO.setActivityTitle(mcContent.getTitle()); mcGeneralLearnerFlowDTO.setActivityInstructions(mcContent.getInstructions()); - mcGeneralLearnerFlowDTO.setPassMark(mcContent.getPassMark().toString()); + mcGeneralLearnerFlowDTO.setPassMark(mcContent.getPassMark()); mcGeneralLearnerFlowDTO.setReportTitleLearner("Report"); mcGeneralLearnerFlowDTO.setLearnerProgress(new Boolean(false).toString()); @@ -729,7 +532,7 @@ logger.debug("continue buildMcGeneralLearnerFlowDTO: " + mcContent); - mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(mcContent.getMcQueContents().size()).toString()); + mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(mcContent.getMcQueContents().size())); logger.debug("final mcGeneralLearnerFlowDTO: " + mcGeneralLearnerFlowDTO); return mcGeneralLearnerFlowDTO; } @@ -820,80 +623,47 @@ * @param mcService * @return */ - public static List buildQuestionAndCandidateAnswersDTO(HttpServletRequest request, McContent mcContent, boolean randomize, + public static List buildQuestionAndCandidateAnswersDTO(HttpServletRequest request, McContent mcContent, boolean randomize, IMcService mcService) { - logger.debug("starting buildQuestionAndCandidateAnswersDTO, randomize: " + randomize); - - List questionAndCandidateAnswersList= new LinkedList(); - logger.debug("mcContent uid : " + mcContent.getUid()); + List questionAndCandidateAnswersList= new LinkedList(); + List listQuestionEntries=mcService.getAllQuestionEntries(mcContent.getUid()); - List listQuestionEntries=mcService.getAllQuestionEntries(mcContent.getUid()); - logger.debug("listQuestionEntries : " + listQuestionEntries); - - - Iterator listQuestionEntriesIterator=listQuestionEntries.iterator(); while (listQuestionEntriesIterator.hasNext()) { McQueContent mcQueContent=(McQueContent)listQuestionEntriesIterator.next(); - logger.debug("mcQueContent : " + mcQueContent); - McLearnerAnswersDTO mcLearnerAnswersDTO= new McLearnerAnswersDTO(); - logger.debug("mcQueContent uid: " + mcQueContent.getUid()); - List listCandidateAnswers=mcService.findMcOptionNamesByQueId(mcQueContent.getUid()); - logger.debug("pre randomize check, listCandidateAnswers: " + listCandidateAnswers); - List listCandidateAnswerUids=mcService.findMcOptionUidsByQueId(mcQueContent.getUid()); - logger.debug("listCandidateAnswerUids: " + listCandidateAnswerUids); - - logger.debug("randomize check: " + randomize); - if (randomize) { - logger.debug("since randomize is on randomizing the list"); //listCandidateAnswers=randomizeList(listCandidateAnswers, listCandidateAnswerUids); McRandomizedListsDTO mcRandomizedListsDTO=randomizeList(listCandidateAnswers, listCandidateAnswerUids); - logger.debug("mcRandomizedListsDTO: " + mcRandomizedListsDTO); - listCandidateAnswers=mcRandomizedListsDTO.getListCandidateAnswers(); listCandidateAnswerUids=mcRandomizedListsDTO.getListCandidateAnswerUids(); } - - - logger.debug("post randomize check, listCandidateAnswers: " + listCandidateAnswers); - logger.debug("post randomize check, listCandidateAnswerUids: " + listCandidateAnswerUids); - - - logger.debug("listCandidateAnswers: " + listCandidateAnswers); Map mapCandidateAnswers=convertToStringMap(listCandidateAnswers); - logger.debug("mapCandidateAnswers: " + mapCandidateAnswers); - - Map mapCandidateAnswerUids=convertToStringMap(listCandidateAnswerUids); - logger.debug("mapCandidateAnswerUids: " + mapCandidateAnswerUids); - String question=mcQueContent.getQuestion(); - logger.debug("question: " + question); mcLearnerAnswersDTO.setQuestion(question); mcLearnerAnswersDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); - mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid().toString()); + mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid()); - mcLearnerAnswersDTO.setMark(mcQueContent.getMark().toString()); + mcLearnerAnswersDTO.setMark(mcQueContent.getMark()); mcLearnerAnswersDTO.setCandidateAnswerUids(mapCandidateAnswerUids); - mcLearnerAnswersDTO.setCandidateAnswers(mapCandidateAnswers); - logger.debug("current mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); - logger.debug("current mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); - questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); } - logger.debug("final questionAndCandidateAnswersList: " + questionAndCandidateAnswersList); + if ( logger.isDebugEnabled() ) { + logger.debug("buildQuestionAndCandidateAnswersDTO: mcContent uid "+mcContent.getUid()+" randomize "+randomize + + "final questionAndCandidateAnswersList: " + questionAndCandidateAnswersList); + } + return questionAndCandidateAnswersList; } @@ -922,139 +692,7 @@ } - /** - * int getLearnerMarkAtLeast(Integer passMark, Map mapQuestionWeights) - * - * @param passMark - * @param mapQuestionWeights - * @return - */ - public static int getLearnerMarkAtLeast(Integer passMark, Map mapQuestionWeights) - { - logger.debug("doing getLearnerMarkAtLeast"); - logger.debug("passMark:" + passMark); - logger.debug("mapQuestionWeights:" + mapQuestionWeights); - - if ((passMark == null) || (passMark.intValue() == 0)) - { - logger.debug("no passMark.."); - return 0; - } - else if ((passMark != null) && (passMark.intValue() != 0)) - { - int minimumQuestionCountToPass=calculateMinimumQuestionCountToPass(passMark, mapQuestionWeights); - logger.debug("minimumQuestionCountToPass: " + minimumQuestionCountToPass); - return minimumQuestionCountToPass; - } - return 0; - } - - /** - * int getMarksBasedLearnerMarkAtLeast(Integer passMark, Map mapQuestionMarks) - * - * @param passMark - * @param mapQuestionMarks - * @return - */ - public static int getMarksBasedLearnerMarkAtLeast(Integer passMark, Map mapQuestionMarks) - { - logger.debug("doing getMarksBasedLearnerMarkAtLeast: " + mapQuestionMarks); - logger.debug("passMark:" + passMark); - logger.debug("mapQuestionMarks:" + mapQuestionMarks); - - if ((passMark == null) || (passMark.intValue() == 0)) - { - logger.debug("no passMark.."); - return 0; - } - else if ((passMark != null) && (passMark.intValue() != 0)) - { - int minimumQuestionCountToPass=calculateMarksBasedMinimumQuestionCountToPass(passMark, mapQuestionMarks); - logger.debug("minimumQuestionCountToPass: " + minimumQuestionCountToPass); - return minimumQuestionCountToPass; - } - return 0; - } - - - /** - * int calculateMinimumQuestionCountToPass(Integer passMark, Map mapQuestionWeights) - * - * @param passMark - * @param mapQuestionWeights - * @return - */ - public static int calculateMinimumQuestionCountToPass(Integer passMark, Map mapQuestionWeights) - { - logger.debug("calculating minimumQuestionCountToPass: mapQuestionWeights: " + mapQuestionWeights + " passmark: " + passMark); - logger.debug("passMark: " + passMark); - logger.debug("original mapQuestionWeights: " + mapQuestionWeights); - - boolean mapExcluded=false; - int minimumQuestionCount=0; - int totalHighestWeights=0; - while (totalHighestWeights <= passMark.intValue()) - { - logger.debug("totalHighestWeights versus passMark: " + totalHighestWeights + " versus" + passMark); - int highestWeight=getHighestWeight(mapQuestionWeights, mapExcluded); - logger.debug("highestWeight: " + highestWeight); - totalHighestWeights=totalHighestWeights + highestWeight; - logger.debug("totalHighestWeights: " + totalHighestWeights); - mapQuestionWeights=rebuildWeightsMapExcludeHighestWeight(mapQuestionWeights, highestWeight); - mapExcluded=true; - logger.debug("mapQuestionWeights: " + mapQuestionWeights); - ++minimumQuestionCount; - if (mapQuestionWeights.size() == 0) - { - logger.debug("no more weights: "); - break; - } - } - logger.debug("returning minimumQuestionCount: " + minimumQuestionCount); - return minimumQuestionCount; - } - - - /** - * int calculateMarksBasedMinimumQuestionCountToPass(Integer passMark, Map mapQuestionMarks) - * - * @param passMark - * @param mapQuestionMarks - * @return - */ - public static int calculateMarksBasedMinimumQuestionCountToPass(Integer passMark, Map mapQuestionMarks) - { - logger.debug("calculating minimumQuestionCountToPass: mapQuestionMarks: " + mapQuestionMarks + " passmark: " + passMark); - logger.debug("passMark: " + passMark); - logger.debug("original mapQuestionMarks: " + mapQuestionMarks); - - boolean mapExcluded=false; - int minimumQuestionCount=0; - int totalHighestMarks=0; - while (totalHighestMarks <= passMark.intValue()) - { - logger.debug("totalHighestMarks versus passMark: " + totalHighestMarks + " versus" + passMark); - int highestWeight=getHighestMark(mapQuestionMarks, mapExcluded); - logger.debug("highestWeight: " + highestWeight); - totalHighestMarks=totalHighestMarks + highestWeight; - logger.debug("totalHighestMarks: " + totalHighestMarks); - mapQuestionMarks=rebuildWeightsMapExcludeHighestWeight(mapQuestionMarks, highestWeight); - mapExcluded=true; - logger.debug("mapQuestionMarks: " + mapQuestionMarks); - ++minimumQuestionCount; - if (mapQuestionMarks.size() == 0) - { - logger.debug("no more marks: "); - break; - } - } - logger.debug("returning minimumQuestionCount: " + minimumQuestionCount); - return minimumQuestionCount; - } - - - /** * int getHighestMark(Map mapQuestionMarks, boolean mapExcluded) * * @param mapQuestionMarks @@ -1088,79 +726,8 @@ } - /** - * int getHighestWeight(Map mapQuestionWeights, boolean mapExcluded) - * - * @param mapQuestionWeights - * @param mapExcluded - * @return - */ - public static int getHighestWeight(Map mapQuestionWeights, boolean mapExcluded) - { - logger.debug("mapExcluded: " + mapExcluded); - - if ((mapQuestionWeights.size() == 1) && (!mapExcluded)) - { - logger.debug("using map with 1 question only"); - /*the only alternative is 100*/ - return 100; - } - - logger.debug("continue excluding map"); - Iterator itMap = mapQuestionWeights.entrySet().iterator(); - int highestWeight=0; - while (itMap.hasNext()) - { - Map.Entry pair = (Map.Entry)itMap.next(); - String weight=pair.getValue().toString(); - int intWeight=new Integer(weight).intValue(); - - if (intWeight > highestWeight) - highestWeight= intWeight; - } - return highestWeight; - } - - + /** - * Map rebuildWeightsMapExcludeHighestWeight(Map mapQuestionWeights, int highestWeight) - * - * @param mapQuestionWeights - * @param highestWeight - * @return - */ - public static Map rebuildWeightsMapExcludeHighestWeight(Map mapQuestionWeights, int highestWeight) - { - logger.debug("doing rebuildWeightsMapExcludeHighestWeight: " + mapQuestionWeights); - logger.debug("doing highestWeight: " + highestWeight); - - Map mapWeightsExcludeHighestWeight= new TreeMap(new McComparator()); - - Iterator itMap = mapQuestionWeights.entrySet().iterator(); - Long mapIndex=new Long(1); - while (itMap.hasNext()) - { - Map.Entry pair = (Map.Entry)itMap.next(); - String weight=pair.getValue().toString(); - int intWeight=new Integer(weight).intValue(); - logger.debug("intWeight: " + intWeight); - logger.debug("intWeight versus highestWeight:" + intWeight + " versus" + highestWeight); - if (intWeight != highestWeight) - { - mapWeightsExcludeHighestWeight.put(mapIndex.toString(),weight); - mapIndex=new Long(mapIndex.longValue()+1); - } - else - { - logger.debug("excluding highest weight from the reconstructed map: " + intWeight); - } - } - logger.debug("returning mapWeightsExcludeHighestWeight: " + mapWeightsExcludeHighestWeight); - return mapWeightsExcludeHighestWeight; - } - - - /** * Map rebuildMarksMapExcludeHighestMark(Map mapQuestionMarks, int highestMark) * * @param mapQuestionMarks @@ -1261,5 +828,115 @@ } */ + /** Gets the various maps used by jsps to display a learner's attempts. + * @return Map[mapFinalAnswersIsContent, mapFinalAnswersContent, mapQueAttempts, mapQueCorrectAttempts, mapQueIncorrectAttempts, mapMarks] */ + public static Map[] getAttemptMapsForUser(int intTotalQuestionCount, Long toolContentUID, boolean allowRetries, IMcService mcService, McQueUsr mcQueUsr) { + + Map mapFinalAnswersIsContent= new TreeMap(new McComparator()); + Map mapFinalAnswersContent= new TreeMap(new McComparator()); + + // mapQueAttempts: key is the question display order, the value is the mapAttempOrderAttempts map. + // mapAttemptOrderAttempts: key is the attempt order, the value is the mapAttempt map. + // mapAttemptMap: key is an artificial ordering, the value is the actual value for the question + // at the moment, there will only be one attempt for each question of each learner in a tool session + // so mapAttemptMap will only have one value. + // The mapQueCorrectAttempts and mapQueIncorrectAttempts work in a similar way + Map mapQueAttempts= new TreeMap(new McComparator()); + Map mapQueCorrectAttempts= new TreeMap(new McComparator()); + Map mapQueIncorrectAttempts= new TreeMap(new McComparator()); + + for (int i=1; i<= intTotalQuestionCount; i++) + { + logger.debug("doing question with display order: " + i); + McQueContent mcQueContent=mcService.getQuestionContentByDisplayOrder(new Long(i), toolContentUID); + logger.debug("mcQueContent uid: " + mcQueContent.getUid()); + + McUsrAttempt mcUsrAttemptFinal = null; + + List userAttempts = mcService.getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(mcQueUsr.getUid(), mcQueContent.getUid()); + Iterator userAttemptsIter = userAttempts.iterator(); + + Map mapAttemptOrderAttempts= new TreeMap(new McComparator()); + Map mapAttemptOrderCorrectAttempts= new TreeMap(new McComparator()); + Map mapAttemptOrderIncorrectAttempts= new TreeMap(new McComparator()); + + while ( userAttemptsIter.hasNext() ) { + McUsrAttempt mcUsrAttempt = (McUsrAttempt) userAttemptsIter.next(); + + if ( mcUsrAttemptFinal == null || mcUsrAttempt.getAttemptOrder().compareTo(mcUsrAttemptFinal.getAttemptOrder()) > 0) + mcUsrAttemptFinal = mcUsrAttempt; + + addToAttemptMaps(mapAttemptOrderAttempts, mapAttemptOrderCorrectAttempts, mapAttemptOrderIncorrectAttempts, mcUsrAttempt); + } + + String questionDisplayOrderString = new Integer(i).toString(); + + Integer mark = null; + if ( mcUsrAttemptFinal != null ) { + mapFinalAnswersIsContent.put(questionDisplayOrderString, new Boolean(mcUsrAttemptFinal.isAttemptCorrect()).toString()); + mapFinalAnswersContent.put(questionDisplayOrderString, mcUsrAttemptFinal.getMcOptionsContent().getMcQueOptionText().toString()); + } + if (mapAttemptOrderAttempts.size() > 0) { + mapQueAttempts.put(questionDisplayOrderString, mapAttemptOrderAttempts); + } + if (mapAttemptOrderCorrectAttempts.size() > 0) { + mapQueCorrectAttempts.put(questionDisplayOrderString, mapAttemptOrderCorrectAttempts); + } + if (mapAttemptOrderIncorrectAttempts.size() > 0) { + mapQueIncorrectAttempts.put(questionDisplayOrderString, mapAttemptOrderIncorrectAttempts); + } + } + + if ( logger.isDebugEnabled() ) { + logger.debug("final mapFinalAnswersContent is: " + mapFinalAnswersContent); + logger.debug("final mapFinalAnswersIsContent is: " + mapFinalAnswersIsContent); + logger.debug("final mapQueAttempts is: " + mapQueAttempts); + logger.debug("final mapQueCorrectAttempts is: " + mapQueCorrectAttempts); + logger.debug("final mapQueIncorrectAttempts is: " + mapQueIncorrectAttempts); + } + + return new Map[] {mapFinalAnswersIsContent, mapFinalAnswersContent, mapQueAttempts, mapQueCorrectAttempts, mapQueIncorrectAttempts}; + } + private static void addToAttemptMaps(Map mapAttemptOrderAttempts, Map mapAttemptOrderCorrectAttempts, Map mapAttemptOrderIncorrectAttempts, McUsrAttempt mcUsrAttempt) { + String attemptOrderString = mcUsrAttempt.getAttemptOrder().toString(); + + Map attemptMap = (Map) mapAttemptOrderAttempts.get(attemptOrderString); + Map correctAttemptMap = (Map) mapAttemptOrderCorrectAttempts.get(attemptOrderString); + Map incorrectAttemptMap = (Map) mapAttemptOrderIncorrectAttempts.get(attemptOrderString); + + if ( attemptMap == null ) { + attemptMap = new TreeMap(new McComparator()); + mapAttemptOrderAttempts.put(attemptOrderString, attemptMap); + + correctAttemptMap = new TreeMap(new McComparator()); + mapAttemptOrderAttempts.put(attemptOrderString, correctAttemptMap); + + incorrectAttemptMap = new TreeMap(new McComparator()); + mapAttemptOrderAttempts.put(attemptOrderString, incorrectAttemptMap); + } + + int mapSize = attemptMap.size(); + String mapIndex = (new Integer(mapSize+1)).toString(); + attemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); + if ( mcUsrAttempt.isAttemptCorrect() ) + correctAttemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); + else + incorrectAttemptMap.put(mapIndex, mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); + + } + + /** Should we show the marks for each question - we show the marks if any of the questions + * have a mark > 1. + */ + public static Boolean isShowMarksOnQuestion(List listQuestionAndCandidateAnswersDTO) { + Iterator iter = listQuestionAndCandidateAnswersDTO.iterator(); + while (iter.hasNext()) { + McLearnerAnswersDTO elem = (McLearnerAnswersDTO) iter.next(); + if ( elem.getMark().intValue() > 1 ) { + return Boolean.TRUE; + } + } + return Boolean.FALSE; + } } Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java,v diff -u -r1.65 -r1.66 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java 17 Dec 2006 18:10:28 -0000 1.65 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningAction.java 15 Aug 2007 03:54:50 -0000 1.66 @@ -450,29 +450,16 @@ mcService.updateMcQueUsr(mcQueUsr); logger.debug("view summary requested by mcQueUsr: " + mcQueUsr); - - McUsrAttempt mcUsrAttempt = mcService.getAttemptWithLastAttemptOrderForUserInSession(mcQueUsr.getUid(), mcSession.getUid()); - logger.debug("mcUsrAttempt with highest attempt order: " + mcUsrAttempt); - String highestAttemptOrder=""; - - if (mcUsrAttempt != null) - { - highestAttemptOrder=mcUsrAttempt.getAttemptOrder().toString(); - logger.debug("highestAttemptOrder: " + highestAttemptOrder); - List userAttempts=mcService.getAttemptsForUserOnHighestAttemptOrderInSession(mcQueUsr.getUid(), mcSession.getUid(), new Integer(highestAttemptOrder)); - logger.debug("userAttempts:" + userAttempts); + List userAttempts=mcService.getLatestAttemptsForAUser(mcQueUsr.getUid()); + logger.debug("userAttempts:" + userAttempts); - Iterator itAttempts=userAttempts.iterator(); - while (itAttempts.hasNext()) - { - mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - mcUsrAttempt.setFinished(true); - mcService.updateMcUsrAttempt(mcUsrAttempt); - } - logger.debug("updated user records to finished"); + Iterator itAttempts=userAttempts.iterator(); + while (itAttempts.hasNext()) + { + McUsrAttempt mcUsrAttempt=(McUsrAttempt)itAttempts.next(); + mcUsrAttempt.setFinished(true); + mcService.updateMcUsrAttempt(mcUsrAttempt); } - logger.debug("redirecting to the nextUrl: "+ nextUrl); response.sendRedirect(nextUrl); @@ -552,203 +539,119 @@ * @param mcContent * @return */ - protected List buildSelectedQuestionAndCandidateAnswersDTO(List allQuestionUidsList, - List learnerInput, McTempDataHolderDTO mcTempDataHolderDTO, + protected List buildSelectedQuestionAndCandidateAnswersDTO(List learnerInput, McTempDataHolderDTO mcTempDataHolderDTO, IMcService mcService, McContent mcContent) { - logger.debug("starting buildSelectedQuestionAndCandidateAnswersDTO using allQuestionUidsList: " + allQuestionUidsList); - logger.debug("buildSelectedQuestionAndCandidateAnswersDTO: " + learnerInput); - logger.debug("mcContent: " + mcContent); - - logger.debug("learnerInput: " + learnerInput); - int mark=0; - int userWeight=0; - int userMarks=0; + if ( log.isDebugEnabled() ) { + logger.debug("starting buildSelectedQuestionAndCandidateAnswersDTO using learnerInput: " + learnerInput + +" and mcContent: " + mcContent); + } + + int learnerMarks=0; int totalMarksPossible=0; - Set questionUids=parseLearnerInput(learnerInput, mcContent, mcService); - logger.debug("set questionUids: " + questionUids); + if ( log.isDebugEnabled() ) + logger.debug("set questionUids: " + questionUids); List questionAndCandidateAnswersList= new LinkedList(); - int totalUserMarks= 0; - - - if (questionUids.size() == 0) - { - logger.debug("there are no selected answers for any questions: " + questionUids); - } - - Iterator allQuestionUidsListIterator=allQuestionUidsList.iterator(); - while (allQuestionUidsListIterator.hasNext()) + Iterator questionIterator = mcContent.getMcQueContents().iterator(); + while (questionIterator.hasNext()) { - logger.debug("started testing all uids"); + McQueContent mcQueContent = (McQueContent) questionIterator.next(); + String currentQuestionUid = mcQueContent.getUid().toString(); + int currentMark= mcQueContent.getMark().intValue(); + totalMarksPossible+=currentMark; - String currentQuestionUid=(String)allQuestionUidsListIterator.next(); - logger.debug("currentQuestionUid: " + currentQuestionUid); + McLearnerAnswersDTO mcLearnerAnswersDTO= new McLearnerAnswersDTO(); + mcLearnerAnswersDTO.setQuestion(mcQueContent.getQuestion()); + mcLearnerAnswersDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); + mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid()); + mcLearnerAnswersDTO.setFeedback(mcQueContent.getFeedback() != null ? mcQueContent.getFeedback() : ""); + + Map caMap= new TreeMap(new McStringComparator()); + Map caIdsMap= new TreeMap(new McStringComparator()); + long mapIndex=new Long(1); + + Iterator listLearnerInputIterator=learnerInput.iterator(); + while (listLearnerInputIterator.hasNext()) + { + String input=(String)listLearnerInputIterator.next(); + int pos=input.indexOf("-"); + String localQuestionUid=input.substring(0,pos); - - boolean selectedQuestionFound=false; - Iterator setQuestionUidsIterator=questionUids.iterator(); - while (setQuestionUidsIterator.hasNext()) - { - String questionUid=(String)setQuestionUidsIterator.next(); - logger.debug("questionUid: " + questionUid); - - McQueContent mcQueContent=mcService.findMcQuestionContentByUid(new Long(questionUid)); - logger.debug("mcQueContent: " + mcQueContent); + if ( log.isDebugEnabled() ) { + logger.debug("input: " + input); + logger.debug("pos: " + pos); + logger.debug("localQuestionUid: " + localQuestionUid); + } - logger.debug("mcQueContent text: " + mcQueContent.getQuestion()); - String question=mcQueContent.getQuestion(); - logger.debug("question: " + question); - logger.debug("question uid: " + mcQueContent.getUid()); - - logger.debug("testing for comparison currentQuestionUid and mcQueContent.getUid(): " + - currentQuestionUid + " and " + mcQueContent.getUid()); - - if (currentQuestionUid.equals(mcQueContent.getUid().toString())) + if (currentQuestionUid.equals(localQuestionUid)) { - selectedQuestionFound=true; - McLearnerAnswersDTO mcLearnerAnswersDTO= new McLearnerAnswersDTO(); - - logger.debug("this is a selected question with uid: " + mcQueContent.getUid()); - mcLearnerAnswersDTO.setQuestion(question); - mcLearnerAnswersDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); - mcLearnerAnswersDTO.setQuestionUid(mcQueContent.getUid().toString()); - mcLearnerAnswersDTO.setMark(mcQueContent.getMark().toString()); + String caUid=input.substring(pos+1); + McOptsContent mcOptsContent= mcQueContent.getOptionsContentByUID(new Long(caUid)); + String mapIndexAsString = new Long(mapIndex).toString(); + caMap.put(mapIndexAsString, mcOptsContent.getMcQueOptionText()); + caIdsMap.put(mapIndexAsString, caUid ); + mapIndex++; - int currentMark= mcQueContent.getMark().intValue(); - logger.debug("currentMark: " + currentMark); - totalMarksPossible+=currentMark; - - - String feedback=mcQueContent.getFeedback(); - if (feedback == null) feedback=""; - logger.debug("feedback: " + feedback); - - mcLearnerAnswersDTO.setFeedback(feedback); - - Map caMap= new TreeMap(new McStringComparator()); - Map caIdsMap= new TreeMap(new McStringComparator()); - Long mapIndex=new Long(1); - - Iterator listLearnerInputIterator=learnerInput.iterator(); - while (listLearnerInputIterator.hasNext()) - { - String input=(String)listLearnerInputIterator.next(); - logger.debug("input: " + input); - int pos=input.indexOf("-"); - logger.debug("pos: " + pos); - String localQuestionUid=input.substring(0,pos); - logger.debug("localQuestionUid: " + localQuestionUid); - - if (questionUid.equals(localQuestionUid)) - { - logger.debug("equal uids found : " + localQuestionUid); - String caUid=input.substring(pos+1); - logger.debug("caUid: " + caUid); - McOptsContent mcOptsContent= mcService.findMcOptionsContentByUid(new Long(caUid)); - logger.debug("mcOptsContent: " + mcOptsContent); - logger.debug("mcOptsContent text: " + mcOptsContent.getMcQueOptionText()); - caMap.put(mapIndex.toString(), mcOptsContent.getMcQueOptionText()); - caIdsMap.put(mapIndex.toString(), mcOptsContent.getUid().toString() ); - mapIndex=new Long(mapIndex.longValue()+1); - } - } - logger.debug("current caMap: " + caMap); - logger.debug("current caIdsMap: " + caIdsMap); - mcLearnerAnswersDTO.setCandidateAnswers(caMap); - - Long mcQueContentUid= mcQueContent.getUid(); - logger.debug("mcQueContentUid: " + mcQueContentUid); - - List correctOptions=(List) mcService.getPersistedSelectedOptions(mcQueContentUid); - logger.debug("correctOptions: " + correctOptions); - Map mapCorrectOptionUids=LearningUtil.buildMapCorrectOptionUids(correctOptions); - logger.debug("mapCorrectOptionUids: " + mapCorrectOptionUids); - - boolean isEqual=LearningUtil.compareMapItems(mapCorrectOptionUids, caIdsMap); - logger.debug("isEqual: " + isEqual); - boolean isEqualCross=LearningUtil.compareMapsItemsCross(mapCorrectOptionUids, caIdsMap); - logger.debug("isEqualCross: " + isEqualCross); - boolean compareResult= isEqual && isEqualCross; - logger.debug("compareResult: " + compareResult); + if ( log.isDebugEnabled() ) { + logger.debug("equal uids found : " + localQuestionUid+" caUid: " + caUid); + logger.debug("mcOptsContent: " + mcOptsContent); + logger.debug("mcOptsContent text: " + mcOptsContent.getMcQueOptionText()); + } + } + } + logger.debug("current caMap: " + caMap); + logger.debug("current caIdsMap: " + caIdsMap); + mcLearnerAnswersDTO.setCandidateAnswers(caMap); + + Long mcQueContentUid= mcQueContent.getUid(); + logger.debug("mcQueContentUid: " + mcQueContentUid); + + List correctOptions=(List) mcService.getPersistedSelectedOptions(mcQueContentUid); + logger.debug("correctOptions: " + correctOptions); + Map mapCorrectOptionUids=LearningUtil.buildMapCorrectOptionUids(correctOptions); + logger.debug("mapCorrectOptionUids: " + mapCorrectOptionUids); + + boolean isEqual=LearningUtil.compareMapItems(mapCorrectOptionUids, caIdsMap); + logger.debug("isEqual: " + isEqual); + boolean isEqualCross=LearningUtil.compareMapsItemsCross(mapCorrectOptionUids, caIdsMap); + logger.debug("isEqualCross: " + isEqualCross); + boolean compareResult= isEqual && isEqualCross; + logger.debug("compareResult: " + compareResult); - mcLearnerAnswersDTO.setAttemptCorrect(new Boolean(compareResult).toString()); - if (compareResult) - { - mcLearnerAnswersDTO.setFeedbackCorrect(mcQueContent.getFeedback()); - ++mark; - - totalUserMarks+=currentMark; - userMarks=userMarks + currentMark;; - } - else - { - mcLearnerAnswersDTO.setFeedbackIncorrect(mcQueContent.getFeedback()); - } - logger.debug("assesment complete"); - logger.debug("mark:: " + mark); - logger.debug("totalUserMarks: " + totalUserMarks); - - logger.debug("current mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); - questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); - - }//end if - } //end while - - if (!selectedQuestionFound) + mcLearnerAnswersDTO.setAttemptCorrect(new Boolean(compareResult).toString()); + if (compareResult) { - logger.debug("this is a not selected question, its uid: " + currentQuestionUid); - - McQueContent mcQueContentOrig=mcService.findMcQuestionContentByUid(new Long(currentQuestionUid)); - logger.debug("mcQueContentOrig: " + mcQueContentOrig); - McLearnerAnswersDTO mcLearnerAnswersDTO= new McLearnerAnswersDTO(); - - mcLearnerAnswersDTO.setQuestion(mcQueContentOrig.getQuestion()); - mcLearnerAnswersDTO.setDisplayOrder(mcQueContentOrig.getDisplayOrder().toString()); - mcLearnerAnswersDTO.setQuestionUid(mcQueContentOrig.getUid().toString()); - mcLearnerAnswersDTO.setMark(mcQueContentOrig.getMark().toString()); - - int currentMark= mcQueContentOrig.getMark().intValue(); - logger.debug("currentMark: " + currentMark); - totalMarksPossible+=currentMark; - - - String feedback=mcQueContentOrig.getFeedback(); - if (feedback == null) feedback=""; - logger.debug("feedback: " + feedback); - - mcLearnerAnswersDTO.setFeedback(feedback); - - Map caMap= new TreeMap(new McStringComparator()); - mcLearnerAnswersDTO.setCandidateAnswers(caMap); - - mcLearnerAnswersDTO.setAttemptCorrect(new Boolean(false).toString()); - mcLearnerAnswersDTO.setFeedbackIncorrect(mcQueContentOrig.getFeedback()); - - logger.debug("current mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); - questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); + mcLearnerAnswersDTO.setFeedbackCorrect(mcQueContent.getFeedback()); + mcLearnerAnswersDTO.setMark(new Integer(currentMark)); + learnerMarks+=currentMark; } - - } - logger.debug("final questionAndCandidateAnswersList: " + questionAndCandidateAnswersList); - logger.debug("final mark: " + mark); - - logger.debug("final userMarks: " + userMarks); - logger.debug("totalUserMarks: " + totalUserMarks); - logger.debug("totalMarksPossible: " + totalMarksPossible); + else + { + mcLearnerAnswersDTO.setFeedbackIncorrect(mcQueContent.getFeedback()); + mcLearnerAnswersDTO.setMark(new Integer(0)); + } + logger.debug("assesment complete"); + logger.debug("mark:: " + learnerMarks); + + logger.debug("current mcLearnerAnswersDTO: " + mcLearnerAnswersDTO); + questionAndCandidateAnswersList.add(mcLearnerAnswersDTO); + + }//end question iterator + mcTempDataHolderDTO.setLearnerMark(new Integer(learnerMarks)); + mcTempDataHolderDTO.setTotalMarksPossible(new Integer(totalMarksPossible)); - mcTempDataHolderDTO.setLearnerMark(new Integer(mark).toString()); - mcTempDataHolderDTO.setTotalUserMark(new Integer(userMarks).toString()); - mcTempDataHolderDTO.setTotalReportableUserMark(new Integer(totalUserMarks).toString()); - mcTempDataHolderDTO.setTotalMarksPossible(new Integer(totalMarksPossible).toString()); + if ( log.isDebugEnabled() ) { + logger.debug("final questionAndCandidateAnswersList: " + questionAndCandidateAnswersList); + logger.debug("final userMarks: " + learnerMarks); + logger.debug("totalMarksPossible: " + totalMarksPossible); + logger.debug("mcTempDataHolderDTO before return : " + mcTempDataHolderDTO); + } - - logger.debug("mcTempDataHolderDTO before return : " + mcTempDataHolderDTO); - return questionAndCandidateAnswersList; } @@ -867,15 +770,12 @@ McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); logger.debug("mcContent: " + mcContent); - List allQuestionUidsList = getAllQuestionUids(mcContent); - logger.debug("allQuestionUidsList: " + allQuestionUidsList); - McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); logger.debug("constructed a new mcGeneralLearnerFlowDTO"); McTempDataHolderDTO mcTempDataHolderDTO= new McTempDataHolderDTO(); - boolean allQuestionsChecked=allQuestionsChecked(mcService,learnerInput, allQuestionUidsList, mcTempDataHolderDTO); + boolean allQuestionsChecked=allQuestionsChecked(mcService,learnerInput, mcContent, mcTempDataHolderDTO); logger.debug("allQuestionsChecked: " + allQuestionsChecked); logger.debug("mcTempDataHolderDTO displayOrder: " + mcTempDataHolderDTO.getDisplayOrder()); @@ -905,80 +805,23 @@ - List selectedQuestionAndCandidateAnswersDTO=buildSelectedQuestionAndCandidateAnswersDTO(allQuestionUidsList, learnerInput,mcTempDataHolderDTO - , mcService, mcContent); + List selectedQuestionAndCandidateAnswersDTO=buildSelectedQuestionAndCandidateAnswersDTO(learnerInput,mcTempDataHolderDTO, mcService, mcContent); logger.debug("selectedQuestionAndCandidateAnswersDTO: " + selectedQuestionAndCandidateAnswersDTO); request.setAttribute(LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO, selectedQuestionAndCandidateAnswersDTO); logger.debug("LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_SELECTED_QUESTION_CANDIDATEANSWERS_DTO)); logger.debug("mcTempDataHolderDTO becomes: " + mcTempDataHolderDTO); - String learnerMark=mcTempDataHolderDTO.getLearnerMark(); - logger.debug("learnerMark: " + learnerMark); - String totalUserWeight=mcTempDataHolderDTO.getTotalUserWeight(); - logger.debug("totalUserWeight: " + totalUserWeight); - - String totalUserMark=mcTempDataHolderDTO.getTotalUserMark(); - logger.debug("totalUserMark: " + totalUserMark); - - String totalMarksPossible=mcTempDataHolderDTO.getTotalMarksPossible(); - logger.debug("totalMarksPossible: " + totalMarksPossible); - - mcGeneralLearnerFlowDTO.setQuestionListingMode(QUESTION_LISTING_MODE_COMBINED); + Integer learnerMark = mcTempDataHolderDTO.getLearnerMark(); + mcGeneralLearnerFlowDTO.setLearnerMark(learnerMark); int totalQuestionCount=mcContent.getMcQueContents().size(); - logger.debug("totalQuestionCount: " + totalQuestionCount); - mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(totalQuestionCount).toString()); - - mcGeneralLearnerFlowDTO.setTotalUserMark(totalUserMark); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(totalMarksPossible); - - mcGeneralLearnerFlowDTO.setLearnerMark(learnerMark.toString()); - - Integer passMark=mcContent.getPassMark(); - logger.debug("passMark: " + passMark); - mcGeneralLearnerFlowDTO.setUserOverPassMark(new Boolean(false).toString()); - - mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(false).toString()); - boolean passed=false; - if ((passMark != null)) - { - mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(true).toString()); - - logger.debug("totalUserMark versus passMark: " + totalUserMark + " versus " + passMark); - if (new Integer(totalUserMark).intValue() < passMark.intValue()) - { - logger.debug("USER FAILED"); - logger.debug("totalUserMark is less than passmark: " + totalUserMark + " < " + passMark.intValue()); - passed=false; - } - else - { - logger.debug("USER PASSED"); - passed=true; - mcGeneralLearnerFlowDTO.setUserOverPassMark(new Boolean(true).toString()); - } - } - - - if (passMark == null) - { - mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(false).toString()); - } - - String passMarkApplicable=mcGeneralLearnerFlowDTO.getPassMarkApplicable(); - logger.debug("passMarkApplicable: " + passMarkApplicable); - sessionMap.put(PASSMARK_APPLICABLE, passMarkApplicable); - - String userOverPassMark=mcGeneralLearnerFlowDTO.getUserOverPassMark(); - logger.debug("userOverPassMark: " + userOverPassMark); - sessionMap.put(USER_OVER_PASSMARK, userOverPassMark); - + mcGeneralLearnerFlowDTO.setTotalQuestionCount(new Integer(totalQuestionCount)); + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcTempDataHolderDTO.getTotalMarksPossible()); + request.getSession().setAttribute(httpSessionID, sessionMap); - - Long toolSessionUid=mcSession.getUid(); logger.debug("toolSessionUid: " + toolSessionUid); @@ -1024,35 +867,40 @@ logger.debug("final mcQueUsr: " + mcQueUsr); - String highestAttemptOrder="0"; - McUsrAttempt mcUsrAttempt = mcService.getAttemptWithLastAttemptOrderForUserInSession(mcQueUsr.getUid(), toolSessionUid); - logger.debug("mcUsrAttempt with highest attempt order: " + mcUsrAttempt); - if (mcUsrAttempt != null) - { - highestAttemptOrder=mcUsrAttempt.getAttemptOrder().toString(); - } - logger.debug("highestAttemptOrder: " + highestAttemptOrder); + Integer currentHighestAttemptOrder= mcQueUsr.getLastAttemptOrder(); + int newHighestAttempOrder = currentHighestAttemptOrder != null ? currentHighestAttemptOrder.intValue()+1 : 1; + logger.debug("newHighestAttempOrder: " + newHighestAttempOrder); + + // Have to work out in advance if passed so that we can store it against the attempts + boolean passed = mcQueUsr.isMarkPassed(learnerMark); + mcGeneralLearnerFlowDTO.setUserOverPassMark(new Boolean(passed).toString()); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(mcContent.getPassMark()!=null).toString()); + + LearningUtil.createLearnerAttempt(request, mcQueUsr, selectedQuestionAndCandidateAnswersDTO, passed, newHighestAttempOrder, null, mcService); + logger.debug("created user attempt in the db"); - int intHighestAttemptOrder=0; - intHighestAttemptOrder=new Integer(highestAttemptOrder).intValue(); - logger.debug("intHighestAttemptOrder: " + intHighestAttemptOrder); - logger.debug("new intHighestAttemptOrder: " + ++intHighestAttemptOrder); + mcQueUsr.setLastAttemptOrder(newHighestAttempOrder); + mcQueUsr.setLastAttemptTotalMark(learnerMark); + mcService.updateMcQueUsr(mcQueUsr); + + logger.debug("showMarks: " + mcContent.isShowMarks()); + mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(mcContent.isShowMarks()).toString()); + if ( mcContent.isShowMarks() ) { + Integer[] markStatistics = mcService.getMarkStatistics(mcSession); + mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); + mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); + mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); + } else { + Integer zero = new Integer(0); + mcGeneralLearnerFlowDTO.setTopMark(zero); + mcGeneralLearnerFlowDTO.setLowestMark(zero); + mcGeneralLearnerFlowDTO.setAverageMark(zero); + } - highestAttemptOrder = new Integer(intHighestAttemptOrder).toString(); - logger.debug("new highestAttemptOrder: " + highestAttemptOrder); - - LearningUtil.createLearnerAttempt(request, mcQueUsr, selectedQuestionAndCandidateAnswersDTO, new Integer(learnerMark).intValue(), passed, new Integer(highestAttemptOrder).intValue(), null, mcService); - logger.debug("created user attempt in the db"); - Map mapQuestionMarks=LearningUtil.buildMarksMap(request, mcContent.getMcContentId(), mcService); logger.debug("mapQuestionMarks:" + mapQuestionMarks); - - int learnerMarkAtLeast=LearningUtil.getMarksBasedLearnerMarkAtLeast(passMark,mapQuestionMarks); - logger.debug("learnerMarkAtLeast:" + learnerMarkAtLeast); - mcGeneralLearnerFlowDTO.setLearnerMarkAtLeast (new Integer(learnerMarkAtLeast).toString()); - logger.debug("user over passmark:" + mcGeneralLearnerFlowDTO.getUserOverPassMark()); logger.debug("is passmark applicable:" + mcGeneralLearnerFlowDTO.getPassMarkApplicable()); @@ -1063,26 +911,9 @@ String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); + logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - - totalMarksPossible=LearningUtil.getTotalMarksPossible(mcContent); - logger.debug("totalMarksPossible: " + totalMarksPossible); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(totalMarksPossible); - - - int topMark=LearningUtil.getTopMark(request, mcService, mcContent); - int lowestMark=LearningUtil.getLowestMark(request, mcService, mcContent); - int averageMark=LearningUtil.getAverageMark(request, mcService, mcContent); - - mcGeneralLearnerFlowDTO.setTopMark(new Integer(topMark).toString()); - mcGeneralLearnerFlowDTO.setLowestMark(new Integer(lowestMark).toString()); - mcGeneralLearnerFlowDTO.setAverageMark(new Integer(averageMark).toString()); - - boolean showMarks=mcContent.isShowMarks(); - logger.debug("showMarks: " + showMarks); - mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(showMarks).toString()); - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); @@ -1091,22 +922,22 @@ - public boolean allQuestionsChecked(IMcService mcService, List learnerInput, - List allQuestionUidsList, McTempDataHolderDTO mcTempDataHolderDTO) + public boolean allQuestionsChecked(IMcService mcService, List learnerInput, McContent mcContent, + McTempDataHolderDTO mcTempDataHolderDTO) { logger.debug("starting allQuestionsChecked learnerInput: " + learnerInput); - logger.debug("using allQuestionUidsList: " + allQuestionUidsList); boolean questionSelected=false; - Iterator allQuestionUidsListIterator=allQuestionUidsList.iterator(); - while (allQuestionUidsListIterator.hasNext()) - { - String uid=(String)allQuestionUidsListIterator.next(); + Iterator listIterator=mcContent.getMcQueContents().iterator(); + while (listIterator.hasNext()) + { + McQueContent mcQueContent = (McQueContent)listIterator.next(); + String uid=(String)mcQueContent.getUid().toString(); logger.debug("using uid: " + uid); questionSelected=false; Iterator learnerInputIterator=learnerInput.iterator(); - while (learnerInputIterator.hasNext()) + while (learnerInputIterator.hasNext() && !questionSelected) { String learnerInputLine=(String)learnerInputIterator.next(); logger.debug("using learnerInputLine: " + learnerInputLine); @@ -1121,20 +952,18 @@ { logger.debug("equal uids found: " + selectedUid); questionSelected=true; - break; } } logger.debug("iterated loop questionSelected: " + questionSelected); if (questionSelected == false) { - logger.debug("mcTempDataHolderDTO displayOrder:" + uid); - String unselectedQuestionUid=uid; - McQueContent mcQueContent=mcService.findMcQuestionContentByUid(new Long(unselectedQuestionUid)); - logger.debug("mcQueContent :" + mcQueContent); - logger.debug("mcQueContent displayorder:" + mcQueContent.getDisplayOrder()); - mcTempDataHolderDTO.setDisplayOrder(mcQueContent.getDisplayOrder().toString()); + if ( log.isDebugEnabled() ) { + logger.debug("Question not selected by user mcQueContent :" + mcQueContent); + logger.debug("mcQueContent displayorder:" + mcQueContent.getDisplayOrder()); + } + mcTempDataHolderDTO.setDisplayOrder(mcQueContent.getDisplayOrder()); return false; } } @@ -1239,14 +1068,10 @@ McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - String totalQuestionCount=mcGeneralLearnerFlowDTO.getTotalQuestionCount(); - logger.debug("totalQuestionCount: " + totalQuestionCount); - - int intTotalQuestionCount=new Integer(totalQuestionCount).intValue(); - int intQuestionIndex=new Integer(questionIndex).intValue(); - - logger.debug("intTotalQuestionCount versus intCurrentQuestionIndex: " + intTotalQuestionCount + " versus " + intQuestionIndex); - if (intTotalQuestionCount == intQuestionIndex) + Integer totalQuestionCount=mcGeneralLearnerFlowDTO.getTotalQuestionCount(); + Integer intQuestionIndex=new Integer(questionIndex); + logger.debug("intTotalQuestionCount versus intCurrentQuestionIndex: " + totalQuestionCount + " versus " + intQuestionIndex); + if (totalQuestionCount.equals(intQuestionIndex)) { logger.debug("totalQuestionCount has been reached :" + totalQuestionCount); mcGeneralLearnerFlowDTO.setTotalCountReached(new Boolean(true).toString()); @@ -1261,13 +1086,11 @@ mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - String totalMarksPossible=LearningUtil.getTotalMarksPossible(mcContent); - logger.debug("totalMarksPossible: " + totalMarksPossible); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(totalMarksPossible); + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(questionIndex).toString()); + mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(questionIndex)); request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); return (mapping.findForward(LOAD_LEARNER)); @@ -1320,29 +1143,15 @@ logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO)); McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - mcGeneralLearnerFlowDTO.setCurrentQuestionIndex(new Integer(1).toString()); + mcGeneralLearnerFlowDTO.setCurrentQuestionIndex(new Integer(1)); mcGeneralLearnerFlowDTO.setTotalCountReached(new Boolean(false).toString()); /*use existing session to extract PASSMARK_APPLICABLE and USER_OVER_PASSMARK*/ String httpSessionID=mcLearningForm.getHttpSessionID(); logger.debug("httpSessionID: " + httpSessionID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - logger.debug("sessionMap: " + sessionMap); - - String passMarkApplicable=(String)sessionMap.get(PASSMARK_APPLICABLE); - logger.debug("passMarkApplicable: " + passMarkApplicable); - mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); - mcLearningForm.setPassMarkApplicable(passMarkApplicable); - - String userOverPassMark=(String)sessionMap.get(USER_OVER_PASSMARK); - logger.debug("userOverPassMark: " + userOverPassMark); - mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); - mcLearningForm.setUserOverPassMark (userOverPassMark); - - /*create a new session*/ - sessionMap = new SessionMap(); + SessionMap sessionMap = new SessionMap(); List sequentialCheckedCa= new LinkedList(); sessionMap.put(QUESTION_AND_CANDIDATE_ANSWERS_KEY, sequentialCheckedCa); request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); @@ -1366,33 +1175,29 @@ McQueUsr mcQueUsr=mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); logger.debug("mcQueUsr: " + mcQueUsr); - Long queUsrId=mcQueUsr.getUid(); - logger.debug("queUsrId: " + queUsrId); - - int learnerBestMark=LearningUtil.getHighestMark(request, queUsrId, mcService); - logger.debug("learnerBestMark: " + learnerBestMark); - mcGeneralLearnerFlowDTO.setLearnerBestMark(new Integer(learnerBestMark).toString()); + mcGeneralLearnerFlowDTO.setLatestAttemptMark(mcQueUsr.getLastAttemptTotalMark()); + String passMarkApplicable=new Boolean(mcContent.isPassMarkApplicable()).toString(); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); + mcLearningForm.setPassMarkApplicable(passMarkApplicable); + + String userOverPassMark=new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString(); + mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); + mcLearningForm.setUserOverPassMark (userOverPassMark); - logger.debug("is tool reflective: " + mcContent.isReflect()); mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - logger.debug("reflection subject: " + mcContent.getReflectionSubject()); String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - String totalMarksPossible=LearningUtil.getTotalMarksPossible(mcContent); - logger.debug("totalMarksPossible: " + totalMarksPossible); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(totalMarksPossible); - + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); + + if ( logger.isDebugEnabled() ) + logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); return (mapping.findForward(REDO_QUESTIONS)); } @@ -1416,375 +1221,110 @@ { logger.debug("running prepareViewAnswersData..." + mcLearningForm); - logger.debug("getServlet() :" + getServlet()); + // may have to get service from the form - if class has been created by starter action, rather than by struts IMcService mcService=null; if (getServlet() != null) mcService = McServiceProxy.getMcService(getServlet().getServletContext()); else - { - logger.debug("getting service from the form :"); mcService=mcLearningForm.getMcService(); - } - logger.debug("mcService :" + mcService); String toolSessionID=request.getParameter(AttributeNames.PARAM_TOOL_SESSION_ID); - logger.debug("toolSessionID: " + toolSessionID); - McSession mcSession=mcService.retrieveMcSession(new Long(toolSessionID)); - logger.debug("retrieving mcSession: " + mcSession); String toolContentId=mcSession.getMcContent().getMcContentId().toString(); - logger.debug("toolContentId: " + toolContentId); - McContent mcContent=mcService.retrieveMc(new Long(toolContentId)); - logger.debug("mcContent: " + mcContent); + + if ( logger.isDebugEnabled() ) { + logger.debug("retrieving mcSession: " + mcSession); + logger.debug("mcContent: " + mcContent); + } McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - /* this section is needed to separate learner progress view from standard attempts list. Goes from here.. */ - String learnerProgress=mcLearningForm.getLearnerProgress(); - logger.debug("learnerProgress in prepareViewAnswersData: " + learnerProgress); - mcGeneralLearnerFlowDTO.setLearnerProgress(learnerProgress); - - String learnerProgressUserId=mcLearningForm.getLearnerProgressUserId(); - logger.debug("learnerProgressUserId: " + learnerProgressUserId); - mcGeneralLearnerFlowDTO.setLearnerProgressUserId(learnerProgressUserId); - - mcGeneralLearnerFlowDTO.setLearnerProgress(learnerProgress); - request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); - - int intTotalQuestionCount=mcContent.getMcQueContents().size(); - String totalQuestionCount= new Integer(intTotalQuestionCount).toString(); - logger.debug("totalQuestionCount: " + totalQuestionCount); - - Map mapQuestionsUidContent=AuthoringUtil.rebuildQuestionUidMapfromDB(request, new Long(toolContentId), mcService); - logger.debug("mapQuestionsUidContent:" + mapQuestionsUidContent); Map mapStartupGeneralOptionsContent=AuthoringUtil.rebuildStartupGeneralOptionsContentMapfromDB(request, mapQuestionsUidContent, mcService); - logger.debug("mapStartupGeneralOptionsContent:" + mapStartupGeneralOptionsContent); mcGeneralLearnerFlowDTO.setMapGeneralOptionsContent(mapStartupGeneralOptionsContent); - Map mapQuestionsContent=AuthoringUtil.rebuildQuestionMapfromDB(request, new Long(toolContentId), mcService); - logger.debug("mapQuestionsContent:" + mapQuestionsContent); mcGeneralLearnerFlowDTO.setMapQuestionsContent(mapQuestionsContent); Map mapFeedbackContent=AuthoringUtil.rebuildFeedbackMapfromDB(request, new Long(toolContentId), mcService); - logger.debug("mapFeedbackContent:" + mapFeedbackContent); mcGeneralLearnerFlowDTO.setMapFeedbackContent(mapFeedbackContent); + // Set up the user details. If this is the learner progress screen then we that id, + // otherwise we use the user from the session. + + String learnerProgress=mcLearningForm.getLearnerProgress(); + String learnerProgressUserId=mcLearningForm.getLearnerProgressUserId(); + mcGeneralLearnerFlowDTO.setLearnerProgressUserId(learnerProgressUserId); + mcGeneralLearnerFlowDTO.setLearnerProgress(learnerProgress); - boolean learnerProgressOn=false; - if (learnerProgressUserId != null) - { - if ((learnerProgress.equalsIgnoreCase("true")) && - (learnerProgressUserId.length() > 0)) - { - logger.debug("request is for learner progress: learnerProgress: " + learnerProgress); - logger.debug("request is for learner progress: learnerProgressUserId: " + learnerProgressUserId); - learnerProgressOn=true;; - } - } - logger.debug("final learnerProgressOn:" + learnerProgressOn); - /*..till here*/ - + Boolean learnerProgressOn=Boolean.parseBoolean(learnerProgress); + logger.debug("learnerProgressOn:" + learnerProgressOn); + McQueUsr mcQueUsr=null; - Long queUsrId=null; - if (learnerProgressOn == false) - { + if (learnerProgressOn.equals(Boolean.FALSE)) { + logger.debug("learnerProgress off, using user from session"); mcQueUsr=LearningUtil.getUser(request, mcService, toolSessionID); - logger.debug("mcQueUsr: " + mcQueUsr); - - queUsrId=mcQueUsr.getUid(); - logger.debug("queUsrId: " + queUsrId); } - else - { - logger.debug("using mcSession: " + mcSession); + else { logger.debug("using learnerProgressUserId: " + learnerProgressUserId); - mcQueUsr=mcService.getMcUserBySession(new Long(learnerProgressUserId), mcSession.getUid()); - logger.debug("mcQueUsr: " + mcQueUsr); - - queUsrId=mcQueUsr.getUid(); - logger.debug("queUsrId: " + queUsrId); } - logger.debug("final mcQueUsr: " + mcQueUsr); - logger.debug("final queUsrId: " + queUsrId); - Long toolContentUID=mcContent.getUid(); - logger.debug("toolContentUID: " + toolContentUID); - - - Map mapFinalAnswersIsContent= new TreeMap(new McComparator()); - Map mapFinalAnswersContent= new TreeMap(new McComparator()); - - McUsrAttempt mcUsrAttemptLocal = mcService.getAttemptWithLastAttemptOrderForUserInSession(mcQueUsr.getUid(), mcSession.getUid()); - logger.debug("obtain mcUsrAttemptLocal with highest attempt order: " + mcUsrAttemptLocal); - String highestAttemptOrder=""; - - List listUserAttempts=null; - if (mcUsrAttemptLocal != null) - { - highestAttemptOrder=mcUsrAttemptLocal.getAttemptOrder().toString(); - logger.debug("found highestAttemptOrder: " + highestAttemptOrder); - } - request.setAttribute("highestAttempOrder", highestAttemptOrder); - - - - Map mapQueAttempts= new TreeMap(new McComparator()); - Map mapQueCorrectAttempts= new TreeMap(new McComparator()); - Map mapQueIncorrectAttempts= new TreeMap(new McComparator()); - for (int i=1; i<= new Integer(totalQuestionCount).intValue(); i++) - { - logger.debug("doing question with display order: " + i); - McQueContent mcQueContent=mcService.getQuestionContentByDisplayOrder(new Long(i), toolContentUID); - logger.debug("mcQueContent uid: " + mcQueContent.getUid()); - - - - McUsrAttempt mcUsrAttemptFinal=mcService.getUserAttemptForQuestionContentAndSessionUid(mcQueUsr.getUid(), mcQueContent.getUid(), - mcSession.getUid(), new Integer(highestAttemptOrder)); - logger.debug("mcUsrAttemptFinal: " + mcUsrAttemptFinal); - logger.debug("mcUsrAttemptFinal is Correct?: " + mcUsrAttemptFinal.isAttemptCorrect()); - - mapFinalAnswersIsContent.put(new Integer(i).toString() , new Boolean(mcUsrAttemptFinal.isAttemptCorrect()).toString()); - mapFinalAnswersContent.put(new Integer(i).toString() , mcUsrAttemptFinal.getMcOptionsContent().getMcQueOptionText().toString()); - - Map mapAttemptOrderAttempts= new TreeMap(new McComparator()); - Map mapAttemptOrderCorrectAttempts= new TreeMap(new McComparator()); - Map mapAttemptOrderIncorrectAttempts= new TreeMap(new McComparator()); - for (int j=1; j <= MAX_ATTEMPT_HISTORY ; j++ ) - { - logger.debug("getting list for queUsrId: " + queUsrId); - List attemptsByAttemptOrder=mcService.getAttemptByAttemptOrder(queUsrId, mcQueContent.getUid(), new Integer(j)); - logger.debug("attemptsByAttemptOrder: " + j + " is: " + attemptsByAttemptOrder); - - Map mapAttempts= new TreeMap(new McComparator()); - Map mapAttemptsIncorrect= new TreeMap(new McComparator()); - Map mapAttemptsCorrect= new TreeMap(new McComparator()); - Iterator attemptIterator=attemptsByAttemptOrder.iterator(); - Long mapIndex=new Long(1); - while (attemptIterator.hasNext()) - { - McUsrAttempt mcUsrAttempt=(McUsrAttempt)attemptIterator.next(); - if (learnerProgressOn == false) - { - logger.debug("learnerProgressOn is false, populating map based on all the learners"); - if (mcUsrAttempt.isAttemptCorrect()) - { - mapAttemptsCorrect.put(mapIndex.toString(), mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - } - else - { - mapAttemptsIncorrect.put(mapIndex.toString(), mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - } - mapAttempts.put(mapIndex.toString(), mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - logger.debug("added attempt with order: " + mcUsrAttempt.getAttemptOrder() + " , option text is: " + mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - mapIndex=new Long(mapIndex.longValue()+1); - - } - else - { - /* this section is needed to separate learner progress view from standard attempts list. */ - logger.debug("learnerProgressOn is true, populating map based on the learner id: " + learnerProgressUserId); - logger.debug("retrieve user based on uid in the attempt: " + mcUsrAttempt.getQueUsrId()); - McQueUsr mcQueUsrLocal=mcService.getMcUserByUID(mcUsrAttempt.getQueUsrId()); - logger.debug("mcQueUsrLocal: " + mcQueUsrLocal); - - if (mcQueUsrLocal.getQueUsrId().toString().equals(learnerProgressUserId)) - { - logger.debug("found learner progress user: " + learnerProgressUserId); - if (mcUsrAttempt.isAttemptCorrect()) - { - mapAttemptsCorrect.put(mapIndex.toString(), mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - } - else - { - mapAttemptsIncorrect.put(mapIndex.toString(), mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - } - mapAttempts.put(mapIndex.toString(), mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - logger.debug("added attempt with order: " + mcUsrAttempt.getAttemptOrder() + " , option text is: " + mcUsrAttempt.getMcOptionsContent().getMcQueOptionText()); - mapIndex=new Long(mapIndex.longValue()+1); - } - } - - } - - logger.debug("final mapAttempts is: " + mapAttempts); - if (mapAttempts.size() > 0) - { - mapAttemptOrderAttempts.put(new Integer(j).toString(), mapAttempts); - } - if (mapAttemptsCorrect.size() > 0) - { - mapAttemptOrderCorrectAttempts.put(new Integer(j).toString(), mapAttemptsCorrect); - } - if (mapAttemptsIncorrect.size() > 0) - { - mapAttemptOrderIncorrectAttempts.put(new Integer(j).toString(), mapAttemptsIncorrect); - } - } - - logger.debug("final mapAttemptOrderAttempts is: " + mapAttemptOrderAttempts); - if (mapAttemptOrderAttempts.size() > 0) - { - mapQueAttempts.put(new Integer(i).toString(), mapAttemptOrderAttempts); - } - if (mapAttemptOrderCorrectAttempts.size() > 0) - { - mapQueCorrectAttempts.put(new Integer(i).toString(), mapAttemptOrderCorrectAttempts); - } - if (mapAttemptOrderIncorrectAttempts.size() > 0) - { - mapQueIncorrectAttempts.put(new Integer(i).toString(), mapAttemptOrderIncorrectAttempts); - } + if ( logger.isDebugEnabled() ) { + logger.debug("final mcQueUsr: " + mcQueUsr); } - - logger.debug("final mapFinalAnswersContent is: " + mapFinalAnswersContent); - logger.debug("final mapFinalAnswersIsContent is: " + mapFinalAnswersIsContent); - mcGeneralLearnerFlowDTO.setMapFinalAnswersIsContent(mapFinalAnswersIsContent); - mcGeneralLearnerFlowDTO.setMapFinalAnswersContent(mapFinalAnswersContent); + Long toolContentUID=mcContent.getUid(); - - logger.debug("final mapQueAttempts is: " + mapQueAttempts); - logger.debug("final mapQueCorrectAttempts is: " + mapQueCorrectAttempts); - logger.debug("final mapQueIncorrectAttempts is: " + mapQueIncorrectAttempts); - - mcGeneralLearnerFlowDTO.setMapQueAttempts(mapQueAttempts); - mcGeneralLearnerFlowDTO.setMapQueCorrectAttempts(mapQueCorrectAttempts); - mcGeneralLearnerFlowDTO.setMapQueIncorrectAttempts(mapQueIncorrectAttempts); - + Map[] attemptMaps = LearningUtil.getAttemptMapsForUser( mcContent.getMcQueContents().size(), toolContentUID, mcContent.isRetries(), mcService, mcQueUsr); + mcGeneralLearnerFlowDTO.setMapFinalAnswersIsContent(attemptMaps[0]); + mcGeneralLearnerFlowDTO.setMapFinalAnswersContent(attemptMaps[1]); + mcGeneralLearnerFlowDTO.setMapQueAttempts(attemptMaps[2]); + mcGeneralLearnerFlowDTO.setMapQueCorrectAttempts(attemptMaps[3]); + mcGeneralLearnerFlowDTO.setMapQueIncorrectAttempts(attemptMaps[4]); - logger.debug("is tool reflective: " + mcContent.isReflect()); mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); - logger.debug("reflection subject: " + mcContent.getReflectionSubject()); - String reflectionSubject=McUtils.replaceNewLines(mcContent.getReflectionSubject()); mcGeneralLearnerFlowDTO.setReflectionSubject(reflectionSubject); - - logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); - mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - - String userID = ""; - HttpSession ss = SessionManager.getSession(); - logger.debug("ss: " + ss); - - if (ss != null) - { - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - if ((user != null) && (user.getUserID() != null)) - { - userID = user.getUserID().toString(); - logger.debug("retrieved userId: " + userID); - } - } - - logger.debug("attempt getting notebookEntry: "); NotebookEntry notebookEntry = mcService.getEntry(new Long(toolSessionID), CoreNotebookConstants.NOTEBOOK_TOOL, - MY_SIGNATURE, new Integer(userID)); - - logger.debug("notebookEntry: " + notebookEntry); - + MY_SIGNATURE, new Integer(mcQueUsr.getQueUsrId().intValue())); if (notebookEntry != null) { String notebookEntryPresentable = notebookEntry.getEntry(); notebookEntryPresentable=McUtils.replaceNewLines(notebookEntryPresentable); mcGeneralLearnerFlowDTO.setNotebookEntry(notebookEntryPresentable); } - - String reportViewOnly=mcLearningForm.getReportViewOnly(); - logger.debug("reportViewOnly: " + reportViewOnly); - - mcGeneralLearnerFlowDTO.setReportViewOnly(reportViewOnly); - - - logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); + mcGeneralLearnerFlowDTO.setReportViewOnly(mcLearningForm.getReportViewOnly()); mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - - - - String httpSessionID=mcLearningForm.getHttpSessionID(); - logger.debug("httpSessionID: " + httpSessionID); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - logger.debug("sessionMap: " + sessionMap); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(new Boolean(mcContent.isPassMarkApplicable()).toString()); + mcGeneralLearnerFlowDTO.setUserOverPassMark (new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString()); + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(mcContent.isShowMarks()).toString()); + if ( mcContent.isShowMarks() ) { + Integer[] markStatistics = mcService.getMarkStatistics(mcSession); + mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); + mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); + mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); + } else { + Integer zero = new Integer(0); + mcGeneralLearnerFlowDTO.setTopMark(zero); + mcGeneralLearnerFlowDTO.setLowestMark(zero); + mcGeneralLearnerFlowDTO.setAverageMark(zero); + } - String requestByStarter = (String) request.getAttribute(REQUEST_BY_STARTER); - logger.debug("requestByStarter: " + requestByStarter); - - String passMarkApplicable=null; - String userOverPassMark =null; - - if (sessionMap != null) - passMarkApplicable=(String)sessionMap.get(PASSMARK_APPLICABLE); - - logger.debug("passMarkApplicable: " + passMarkApplicable); - - if (passMarkApplicable == null) - { - logger.debug("reading request parameters"); - passMarkApplicable=request.getParameter("passMarkApplicable"); - logger.debug("passMarkApplicable: " + passMarkApplicable); - } - - if (sessionMap != null) - userOverPassMark=(String)sessionMap.get(USER_OVER_PASSMARK); - - logger.debug("userOverPassMark: " + userOverPassMark); - - if (userOverPassMark == null) - { - userOverPassMark=request.getParameter("userOverPassMark"); - logger.debug("userOverPassMark: " + userOverPassMark); - } - - - if (passMarkApplicable != null) - { - mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); - mcLearningForm.setPassMarkApplicable(passMarkApplicable); - } - - if (userOverPassMark != null) - { - mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); - mcLearningForm.setUserOverPassMark (userOverPassMark); - } - - if (sessionMap != null) - { - if (passMarkApplicable != null) - sessionMap.put(PASSMARK_APPLICABLE, passMarkApplicable); - - if (userOverPassMark != null) - sessionMap.put(USER_OVER_PASSMARK, userOverPassMark); - request.getSession().setAttribute(httpSessionID, sessionMap); - } - - - String totalMarksPossible=LearningUtil.getTotalMarksPossible(mcContent); - logger.debug("totalMarksPossible: " + totalMarksPossible); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(totalMarksPossible); - - boolean showMarks=mcContent.isShowMarks(); - logger.debug("showMarks: " + showMarks); - mcGeneralLearnerFlowDTO.setShowMarks(new Boolean(showMarks).toString()); - + logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); logger.debug("end of prepareViewAnswersData."); } - /** * @@ -1886,20 +1426,17 @@ } logger.debug("countSessionComplete: " + countSessionComplete); + Integer[] markStatistics = mcService.getMarkStatistics(mcSession); - int topMark=LearningUtil.getTopMark(request, mcService, mcContent); - int lowestMark=LearningUtil.getLowestMark(request, mcService, mcContent); - int averageMark=LearningUtil.getAverageMark(request, mcService, mcContent); - logger.debug("countSessionComplete: " + countSessionComplete); - logger.debug("topMark: " + topMark); - logger.debug("lowestMark: " + lowestMark); - logger.debug("averageMark: " + averageMark); + logger.debug("topMark: " + markStatistics[0]); + logger.debug("lowestMark: " + markStatistics[1]); + logger.debug("averageMark: " + markStatistics[2]); mcGeneralLearnerFlowDTO.setCountSessionComplete(new Integer(countSessionComplete).toString()); - mcGeneralLearnerFlowDTO.setTopMark(new Integer(topMark).toString()); - mcGeneralLearnerFlowDTO.setLowestMark(new Integer(lowestMark).toString()); - mcGeneralLearnerFlowDTO.setAverageMark(new Integer(averageMark).toString()); + mcGeneralLearnerFlowDTO.setTopMark(markStatistics[0]); + mcGeneralLearnerFlowDTO.setLowestMark(markStatistics[1]); + mcGeneralLearnerFlowDTO.setAverageMark(markStatistics[2]); logger.debug("is tool reflective: " + mcContent.isReflect()); mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); @@ -1910,49 +1447,21 @@ logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - - String httpSessionID=mcLearningForm.getHttpSessionID(); - logger.debug("httpSessionID: " + httpSessionID); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - logger.debug("sessionMap: " + sessionMap); - - - String passMarkApplicable=(String)sessionMap.get(PASSMARK_APPLICABLE); - logger.debug("passMarkApplicable: " + passMarkApplicable); + String passMarkApplicable=new Boolean(mcContent.isPassMarkApplicable()).toString(); + mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); + mcLearningForm.setPassMarkApplicable(passMarkApplicable); - String userOverPassMark=(String)sessionMap.get(USER_OVER_PASSMARK); - logger.debug("userOverPassMark: " + userOverPassMark); - - - if (passMarkApplicable == null) - { - passMarkApplicable=request.getParameter("passMarkApplicable"); - } - logger.debug("passMarkApplicable: " + passMarkApplicable); - mcLearningForm.setPassMarkApplicable(passMarkApplicable); - mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); - - if (userOverPassMark == null) - { - userOverPassMark=request.getParameter("userOverPassMark"); - } - logger.debug("userOverPassMark: " + userOverPassMark); - mcLearningForm.setUserOverPassMark(userOverPassMark); + String userOverPassMark=new Boolean(mcQueUsr.isLastAttemptMarkPassed()).toString(); mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); - - - sessionMap.put(PASSMARK_APPLICABLE, passMarkApplicable); - sessionMap.put(USER_OVER_PASSMARK, userOverPassMark); + mcLearningForm.setUserOverPassMark (userOverPassMark); + + String httpSessionID=mcLearningForm.getHttpSessionID(); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); request.getSession().setAttribute(httpSessionID, sessionMap); + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); - String totalMarksPossible=LearningUtil.getTotalMarksPossible(mcContent); - logger.debug("totalMarksPossible: " + totalMarksPossible); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(totalMarksPossible); - - logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); @@ -2018,13 +1527,13 @@ logger.debug("randomize: " + randomize); - List listQuestionAndCandidateAnswersDTO=LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize,mcService); + List listQuestionAndCandidateAnswersDTO=LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize,mcService); logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); request.setAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO)); McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); - mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(1).toString()); + mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(1)); logger.debug("is tool reflective: " + mcContent.isReflect()); mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); @@ -2036,28 +1545,21 @@ logger.debug("mcContent.isRetries(): " + mcContent.isRetries()); mcGeneralLearnerFlowDTO.setRetries(new Boolean(mcContent.isRetries()).toString()); - String httpSessionID=mcLearningForm.getHttpSessionID(); - logger.debug("httpSessionID: " + httpSessionID); - - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(httpSessionID); - logger.debug("sessionMap: " + sessionMap); - - - String passMarkApplicable=(String)sessionMap.get(PASSMARK_APPLICABLE); - logger.debug("passMarkApplicable: " + passMarkApplicable); + String passMarkApplicable=new Boolean(mcContent.isPassMarkApplicable()).toString(); mcGeneralLearnerFlowDTO.setPassMarkApplicable(passMarkApplicable); mcLearningForm.setPassMarkApplicable(passMarkApplicable); - String userOverPassMark=(String)sessionMap.get(USER_OVER_PASSMARK); - logger.debug("userOverPassMark: " + userOverPassMark); + String userOverPassMark=Boolean.FALSE.toString(); mcGeneralLearnerFlowDTO.setUserOverPassMark (userOverPassMark); mcLearningForm.setUserOverPassMark (userOverPassMark); - String totalMarksPossible=LearningUtil.getTotalMarksPossible(mcContent); - logger.debug("totalMarksPossible: " + totalMarksPossible); - mcGeneralLearnerFlowDTO.setTotalMarksPossible(totalMarksPossible); - + mcGeneralLearnerFlowDTO.setTotalMarksPossible(mcContent.getTotalMarksPossible()); + // should we show the marks for each question - we show the marks if any of the questions + // have a mark > 1. + Boolean showMarks = LearningUtil.isShowMarksOnQuestion(listQuestionAndCandidateAnswersDTO); + mcGeneralLearnerFlowDTO.setShowMarks(showMarks.toString()); + logger.debug("mcGeneralLearnerFlowDTO for jsp: " + mcGeneralLearnerFlowDTO); request.setAttribute(MC_GENERAL_LEARNER_FLOW_DTO, mcGeneralLearnerFlowDTO); logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); @@ -2249,24 +1751,5 @@ } - public List getAllQuestionUids(McContent mcContent) - { - logger.debug("getAllQuestionsUids: " + mcContent); - - Iterator listIterator=mcContent.getMcQueContents().iterator(); - - List uidList= new LinkedList(); - while (listIterator.hasNext()) - { - McQueContent mcQueContent = (McQueContent)listIterator.next(); - logger.debug("mcQueContent: " + mcQueContent); - logger.debug("mcQueContent uid: " + mcQueContent.getUid()); - uidList.add(mcQueContent.getUid().toString()); - } - logger.debug("uidList: " + uidList); - - return uidList; - } - } \ No newline at end of file Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java,v diff -u -r1.74 -r1.75 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java 17 Dec 2006 18:10:27 -0000 1.74 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/McLearningStarterAction.java 15 Aug 2007 03:54:50 -0000 1.75 @@ -47,6 +47,7 @@ import org.lamsfoundation.lams.tool.mc.McApplicationException; import org.lamsfoundation.lams.tool.mc.McComparator; import org.lamsfoundation.lams.tool.mc.McGeneralLearnerFlowDTO; +import org.lamsfoundation.lams.tool.mc.McLearnerAnswersDTO; import org.lamsfoundation.lams.tool.mc.McLearnerStarterDTO; import org.lamsfoundation.lams.tool.mc.McUtils; import org.lamsfoundation.lams.tool.mc.pojos.McContent; @@ -269,6 +270,27 @@ mcLearningForm.setToolContentID(mcContent.getMcContentId().toString()); commonContentSetup(request, mcContent, mcService,mcLearningForm, toolSessionID); + /* find out if the content is set to run offline or online. If it is set to run offline , the learners are informed about that. */ + boolean isRunOffline=McUtils.isRunOffline(mcContent); + logger.debug("isRunOffline: " + isRunOffline); + if (isRunOffline == true) + { + logger.debug("the activity is offline."); + logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); + + logger.debug("fwding to :" + RUN_OFFLINE); + return (mapping.findForward(RUN_OFFLINE)); + } + + /* find out if the content is being modified at the moment. */ + boolean isDefineLater=McUtils.isDefineLater(mcContent); + logger.debug("isDefineLater: " + isDefineLater); + if (isDefineLater == true) + { + logger.debug("fwding to :" + DEFINE_LATER); + return (mapping.findForward(DEFINE_LATER)); + } + /* Is the request for a preview by the author? Preview The tool must be able to show the specified content as if it was running in a lesson. @@ -278,7 +300,7 @@ teacher learner */ - + /*handle PREVIEW mode*/ //String mode=mcLearningForm.getLearningMode(); String mode=request.getParameter(MODE); @@ -289,13 +311,12 @@ logger.debug("Author requests for a preview of the content."); } - /* by now, we know that the mode is either teacher or learner + /* by now, we know that the mode is either teacher or learner * check if the mode is teacher and request is for Learner Progress */ String userId=request.getParameter(USER_ID); logger.debug("userId: " + userId); - - + if ((userId != null) && (mode.equals("teacher"))) { logger.debug("request is for learner progress"); @@ -341,126 +362,48 @@ } /* by now, we know that the mode is learner*/ - - /* find out if the content is set to run offline or online. If it is set to run offline , the learners are informed about that. */ - boolean isRunOffline=McUtils.isRunOffline(mcContent); - logger.debug("isRunOffline: " + isRunOffline); - if (isRunOffline == true) - { - logger.debug("the activity is offline."); - logger.debug("MC_GENERAL_LEARNER_FLOW_DTO: " + request.getAttribute(MC_GENERAL_LEARNER_FLOW_DTO)); - - logger.debug("fwding to :" + RUN_OFFLINE); - return (mapping.findForward(RUN_OFFLINE)); - } - - /* find out if the content is being modified at the moment. */ - boolean isDefineLater=McUtils.isDefineLater(mcContent); - logger.debug("isDefineLater: " + isDefineLater); - if (isDefineLater == true) - { - logger.debug("fwding to :" + DEFINE_LATER); - return (mapping.findForward(DEFINE_LATER)); - } - /* * verify that userId does not already exist in the db. * If it does exist, that means, that user already responded to the content and * his answers must be displayed read-only * */ - String userID = ""; + Integer userID = null; HttpSession ss = SessionManager.getSession(); - logger.debug("ss: " + ss); - if (ss != null) { UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - if ((user != null) && (user.getUserID() != null)) + if (user != null) { - userID = user.getUserID().toString(); - logger.debug("retrieved userId: " + userID); + userID = user.getUserID(); } } - - McQueUsr mcQueUsr=mcService.getMcUserBySession(new Long(userID), mcSession.getUid()); - logger.debug("mcQueUsr:" + mcQueUsr); - - if (mcQueUsr != null) - { - logger.debug("mcQueUsr is available in the db:" + mcQueUsr); - Long queUsrId=mcQueUsr.getUid(); - logger.debug("queUsrId: " + queUsrId); - - int highestAttemptOrder=LearningUtil.getHighestAttemptOrder(request, queUsrId, mcService); - logger.debug("highestAttemptOrder: " + highestAttemptOrder); - if (highestAttemptOrder == 0) - highestAttemptOrder=1; - logger.debug("highestAttemptOrder: " + highestAttemptOrder); - - int learnerBestMark=LearningUtil.getHighestMark(request, queUsrId, mcService); - logger.debug("learnerBestMark: " + learnerBestMark); - } - else - { - logger.debug("mcQueUsr is not available in the db:" + mcQueUsr); - } - - logger.debug("users learning mode is: " + mode); + McQueUsr mcQueUsr=mcService.getMcUserBySession(new Long(userID.longValue()), mcSession.getUid()); + if ( logger.isDebugEnabled()) + logger.debug("mcQueUsr:" + mcQueUsr); + request.setAttribute(MC_LEARNER_STARTER_DTO, mcLearnerStarterDTO); boolean viewSummaryRequested=false; /*if the user's session id AND user id exists in the tool tables go to redo questions.*/ if (mcQueUsr != null) { - viewSummaryRequested=mcQueUsr.isViewSummaryRequested(); - logger.debug("viewSummaryRequested: " + viewSummaryRequested); - - //if (viewSummaryRequested) - //{ - Long sessionUid=mcQueUsr.getMcSessionId(); - logger.debug("users sessionUid: " + sessionUid); - McSession mcUserSession= mcService.getMcSessionByUID(sessionUid); - logger.debug("mcUserSession: " + mcUserSession); - String userSessionId=mcUserSession.getMcSessionId().toString(); - logger.debug("userSessionId: " + userSessionId); - - logger.debug("current toolSessionID: " + toolSessionID); - - if (toolSessionID.equals(userSessionId)) - { - logger.debug("the user's session id AND user id exists in the tool tables go to redo questions. " + toolSessionID + " mcQueUsr: " + - mcQueUsr + " user id: " + mcQueUsr.getQueUsrId()); - logger.debug("the learner has already responsed to this content, just generate a read-only report. Use redo questions for this."); - - boolean isRetries=mcContent.isRetries(); - logger.debug("isRetries: " + isRetries); - McLearningAction mcLearningAction= new McLearningAction(); - logger.debug("present to learner with previous attempts data"); - - String sessionStatus=mcUserSession.getSessionStatus(); - logger.debug("sessionStatus: " +sessionStatus); - /*one limitation by design here is that once a user finishes the activity, subsequent users in the same group are also assumed finished - * since they belong to the same ungrouped activity and these users have the same tool session id*/ - - boolean isResponseFinalised=mcQueUsr.isResponseFinalised(); - logger.debug("isResponseFinalised: " +isResponseFinalised); - - if (isResponseFinalised) - { - mcLearningForm.setReportViewOnly(new Boolean(true).toString()); - } - else - { - mcLearningForm.setReportViewOnly(new Boolean(false).toString()); - } + Long sessionUid=mcQueUsr.getMcSessionId(); + McSession mcUserSession= mcService.getMcSessionByUID(sessionUid); + String userSessionId=mcUserSession.getMcSessionId().toString(); + + if (toolSessionID.equals(userSessionId)) + { + McLearningAction mcLearningAction= new McLearningAction(); - request.setAttribute(REQUEST_BY_STARTER, new Boolean (true).toString()); - return mcLearningAction.viewAnswers(mapping, mcLearningForm, request, response); - } - //} + /*one limitation by design here is that once a user finishes the activity, subsequent users in the same group are also assumed finished + * since they belong to the same ungrouped activity and these users have the same tool session id*/ + mcLearningForm.setReportViewOnly(new Boolean(mcQueUsr.isResponseFinalised()).toString()); + request.setAttribute(REQUEST_BY_STARTER, (Boolean.TRUE).toString()); + return mcLearningAction.viewAnswers(mapping, mcLearningForm, request, response); + } } else if (mode.equals("teacher")) { @@ -492,16 +435,21 @@ boolean randomize=mcContent.isRandomize(); logger.debug("randomize: " + randomize); - List listQuestionAndCandidateAnswersDTO=LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize, mcService); + List listQuestionAndCandidateAnswersDTO=LearningUtil.buildQuestionAndCandidateAnswersDTO(request, mcContent, randomize, mcService); logger.debug("listQuestionAndCandidateAnswersDTO: " + listQuestionAndCandidateAnswersDTO); request.setAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO, listQuestionAndCandidateAnswersDTO); logger.debug("LIST_QUESTION_CANDIDATEANSWERS_DTO: " + request.getAttribute(LIST_QUESTION_CANDIDATEANSWERS_DTO)); McGeneralLearnerFlowDTO mcGeneralLearnerFlowDTO=LearningUtil.buildMcGeneralLearnerFlowDTO(mcContent); mcGeneralLearnerFlowDTO.setTotalCountReached(new Boolean(false).toString()); - mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(1).toString()); + mcGeneralLearnerFlowDTO.setQuestionIndex(new Integer(1)); + // should we show the marks for each question - we show the marks if any of the questions + // have a mark > 1. + Boolean showMarks = LearningUtil.isShowMarksOnQuestion(listQuestionAndCandidateAnswersDTO); + mcGeneralLearnerFlowDTO.setShowMarks(showMarks.toString()); + logger.debug("is tool reflective: " + mcContent.isReflect()); mcGeneralLearnerFlowDTO.setReflection(new Boolean(mcContent.isReflect()).toString()); logger.debug("reflection subject: " + mcContent.getReflectionSubject()); Index: lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java,v diff -u -r1.30 -r1.31 --- lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java 2 Dec 2006 12:44:09 -0000 1.30 +++ lams_tool_lamc/src/java/org/lamsfoundation/lams/tool/mc/web/MonitoringUtil.java 15 Aug 2007 03:54:50 -0000 1.31 @@ -22,6 +22,7 @@ /* $$Id$$ */ package org.lamsfoundation.lams.tool.mc.web; +import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -130,15 +131,11 @@ mcMonitoredAnswersDTO.setQuestion(mcQueContent.getQuestion()); mcMonitoredAnswersDTO.setMark(mcQueContent.getMark().toString()); - List listCandidateAnswers=mcService.findMcOptionNamesByQueId(mcQueContent.getUid()); - logger.debug("listCandidateAnswers:..." + listCandidateAnswers); - mcMonitoredAnswersDTO.setCandidateAnswers(listCandidateAnswers); - List listCandidateAnswersDTO=mcService.populateCandidateAnswersDTO(mcQueContent.getUid()); logger.debug("listCandidateAnswersDTO:..." + listCandidateAnswersDTO); mcMonitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); - Map questionAttemptData= buildGroupsAttemptData(request, mcContent, mcQueContent, mcQueContent.getUid().toString(), mcService, null); + Map questionAttemptData= buildGroupsAttemptData(request, mcContent, mcQueContent, mcQueContent.getUid(), mcService, null); logger.debug("questionAttemptData:..." + questionAttemptData); mcMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); listMonitoredAnswersContainerDTO.add(mcMonitoredAnswersDTO); @@ -187,19 +184,20 @@ mcMonitoredAnswersDTO.setQuestion(mcQueContent.getQuestion()); mcMonitoredAnswersDTO.setMark(mcQueContent.getMark().toString()); - List listCandidateAnswers=mcService.findMcOptionNamesByQueId(mcQueContent.getUid()); - logger.debug("listCandidateAnswers:..." + listCandidateAnswers); - mcMonitoredAnswersDTO.setCandidateAnswers(listCandidateAnswers); - List listCandidateAnswersDTO=mcService.populateCandidateAnswersDTO(mcQueContent.getUid()); logger.debug("listCandidateAnswersDTO:..." + listCandidateAnswersDTO); mcMonitoredAnswersDTO.setCandidateAnswersCorrect(listCandidateAnswersDTO); - Map questionAttemptData= buildGroupsAttemptData(request, mcContent, mcQueContent, mcQueContent.getUid().toString(), mcService, mcQueUsr); - logger.debug("questionAttemptData:..." + questionAttemptData); + // Get the attempts for this user. The maps must match the maps in buildGroupsAttemptData or the jsp won't work. + List listMonitoredUserContainerDTO=getAttemptEntries(request, mcService, mcQueUsr, mcSession, mcQueContent.getUid(), new LinkedList(), false); + Map questionAttemptData = new TreeMap(new McStringComparator()); + questionAttemptData.put(mcSession.getSession_name(), listMonitoredUserContainerDTO); + + if ( logger.isDebugEnabled() ) { + logger.debug("questionAttemptData:..." + questionAttemptData); + } mcMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); listMonitoredAnswersContainerDTO.add(mcMonitoredAnswersDTO); - } } logger.debug("final listMonitoredAnswersContainerDTO:..." + listMonitoredAnswersContainerDTO); @@ -208,78 +206,6 @@ /** - * - * List buildGroupsMarkDataForExportLearner(HttpServletRequest request, - * McContent mcContent, IMcService mcService, McSession mcSession, Long learnerUid) - * - * @param request - * @param mcContent - * @param mcService - * @param mcSession - * @param learnerUid - * @return - */ - public static List buildGroupsMarkDataForExportLearner(HttpServletRequest request, McContent mcContent, IMcService mcService, McSession mcSession, Long learnerUid) - { - logger.debug("will be building export learner groups mark data for content:..." + mcContent); - - logger.debug("mcSession: " + mcSession); - logger.debug("learnerUid: " + learnerUid); - List listMonitoredMarksContainerDTO= new LinkedList(); - - - McSessionMarkDTO mcSessionMarkDTO= new McSessionMarkDTO(); - mcSessionMarkDTO.setSessionId(mcSession.getMcSessionId().toString()); - mcSessionMarkDTO.setSessionName(mcSession.getSession_name().toString()); - - - LinkedList sessionUsersData= new LinkedList(); - Map mapSessionUsersData= new TreeMap(new McStringComparator()); - - McUserMarkDTO mcUserMarkDTO= new McUserMarkDTO(); - mcUserMarkDTO.setSessionId(mcSession.getMcSessionId().toString()); - - List listQuestions=mcService.getAllQuestionEntries(mcContent.getUid()); - logger.debug("listQuestions:..." + listQuestions); - - Iterator itListQuestions = listQuestions.iterator(); - LinkedList userMarks= new LinkedList(); - - while (itListQuestions.hasNext()) - { - McQueContent mcQueContent =(McQueContent)itListQuestions.next(); - logger.debug("mcQueContent:..." + mcQueContent); - if (mcQueContent != null) - { - String learnerMark=getLearnerMarkForQuestionInSession(mcQueContent.getUid(), mcSession.getUid(),learnerUid, mcSession, mcService); - logger.debug("learnerMark for queContent uid, mcSession uid, mcUser uid:..." + mcQueContent.getUid() + "--" + mcSession.getUid() - + "--" + "is: " + learnerMark); - - userMarks.add(learnerMark); - } - } - - logger.debug("final userMarks:..." + userMarks); - mcUserMarkDTO.setMarks(userMarks); - - String totalMark=getTotalUserMarkForQuestions(userMarks); - logger.debug("totalMark: " + totalMark); - mcUserMarkDTO.setTotalMark(totalMark); - - logger.debug("final mcUserMarkDTO:..." + mcUserMarkDTO); - sessionUsersData.add(mcUserMarkDTO); - logger.debug("final sessionUsersData: " + sessionUsersData); - mapSessionUsersData=convertToMcUserMarkDTOMap(sessionUsersData); - logger.debug("final mapSessionUsersData: " + mapSessionUsersData); - mcSessionMarkDTO.setUserMarks(mapSessionUsersData); - listMonitoredMarksContainerDTO.add(mcSessionMarkDTO); - - logger.debug("final listMonitoredMarksContainerDTO:..." + listMonitoredMarksContainerDTO); - return listMonitoredMarksContainerDTO; - } - - - /** * List buildGroupsMarkData(HttpServletRequest request, McContent mcContent, IMcService mcService) * * @param request @@ -293,8 +219,9 @@ List listMonitoredMarksContainerDTO= new LinkedList(); Set sessions=mcContent.getMcSessions(); Iterator sessionsIterator=sessions.iterator(); - - while (sessionsIterator.hasNext()) + int numQuestions = mcContent.getMcQueContents().size(); + + while (sessionsIterator.hasNext()) { McSession mcSession=(McSession) sessionsIterator.next(); logger.debug("iterating mcSession:..." + mcSession); @@ -306,8 +233,9 @@ Set sessionUsers=mcSession.getMcQueUsers(); Iterator usersIterator=sessionUsers.iterator(); - LinkedList sessionUsersData= new LinkedList(); - Map mapSessionUsersData= new TreeMap(new McStringComparator()); + Map mapSessionUsersData= new TreeMap(new McStringComparator()); + Long mapIndex=new Long(1); + while (usersIterator.hasNext()) { McQueUsr mcQueUsr=(McQueUsr) usersIterator.next(); @@ -317,315 +245,55 @@ mcUserMarkDTO.setSessionId(mcSession.getMcSessionId().toString()); mcUserMarkDTO.setSessionName(mcSession.getSession_name().toString()); mcUserMarkDTO.setUserName(mcQueUsr.getFullname()); - mcUserMarkDTO.setQueUsrId(mcQueUsr.getQueUsrId().toString()); + mcUserMarkDTO.setQueUsrId(mcQueUsr.getUid().toString()); - - List listQuestions=mcService.getAllQuestionEntries(mcContent.getUid()); - logger.debug("listQuestions:..." + listQuestions); - - Iterator itListQuestions = listQuestions.iterator(); - LinkedList userMarks= new LinkedList(); - - while (itListQuestions.hasNext()) + // The marks for the user must be listed in the display order of the question. + // Other parts of the code assume that the questions will be in consecutive display + // order starting 1 (e.g. 1, 2, 3, not 1, 3, 4) so we set up an array and use + // the ( display order - 1) as the index (arrays start at 0, rather than 1 hence -1) + // The user must answer all questions, so we can assume that they will have marks + // for all questions or no questions. + // At present there can only be one answer for each question but there may be more + // than one in the future and if so, we don't want to count the mark twice hence + // we need to check if we've already processed this question in the total. + Integer[] userMarks = new Integer[numQuestions]; + Iterator attemptIterator = mcService.getLatestAttemptsForAUser(mcQueUsr.getUid()).iterator(); + long totalMark = 0; + while (attemptIterator.hasNext()) { - McQueContent mcQueContent =(McQueContent)itListQuestions.next(); - logger.debug("mcQueContent:..." + mcQueContent); - if (mcQueContent != null) - { - String learnerMark=getLearnerMarkForQuestionInSession(mcQueContent.getUid(), mcSession.getUid(), mcQueUsr.getUid(), mcSession, mcService); - logger.debug("learnerMark for queContent uid, mcSession uid, mcUser uid:..." + mcQueContent.getUid() + "--" + mcSession.getUid() - + "--" + mcQueUsr.getUid() + "is: " + learnerMark); - - userMarks.add(learnerMark); - } - } + McUsrAttempt attempt =(McUsrAttempt)attemptIterator.next(); + Integer displayOrder = attempt.getMcQueContent().getDisplayOrder(); + int arrayIndex = displayOrder != null && displayOrder.intValue() > 0 ? displayOrder.intValue() - 1 : 1; + if ( userMarks[arrayIndex] == null ) { - logger.debug("final userMarks:..." + userMarks); - mcUserMarkDTO.setMarks(userMarks); - - String totalMark=getTotalUserMarkForQuestions(userMarks); - logger.debug("totalMark: " + totalMark); - mcUserMarkDTO.setTotalMark(totalMark); - - logger.debug("final mcUserMarkDTO:..." + mcUserMarkDTO); - sessionUsersData.add(mcUserMarkDTO); - } - logger.debug("final sessionUsersData: " + sessionUsersData); - mapSessionUsersData=convertToMcUserMarkDTOMap(sessionUsersData); - logger.debug("final mapSessionUsersData: " + mapSessionUsersData); - mcSessionMarkDTO.setUserMarks(mapSessionUsersData); - listMonitoredMarksContainerDTO.add(mcSessionMarkDTO); - } - - logger.debug("final listMonitoredMarksContainerDTO:..." + listMonitoredMarksContainerDTO); - return listMonitoredMarksContainerDTO; - } - - - /** - * List buildGroupingBasedResponsesData(HttpServletRequest request, McContent mcContent, IMcService mcService) - * - * @param request - * @param mcContent - * @param mcService - * @return - */ - public static List buildGroupingBasedResponsesData(HttpServletRequest request, McContent mcContent, IMcService mcService) - { - logger.debug("will be building grouping data for content:..." + mcContent); - List listMonitoredMarksContainerDTO= new LinkedList(); - Set sessions=mcContent.getMcSessions(); - Iterator sessionsIterator=sessions.iterator(); - - while (sessionsIterator.hasNext()) - { - McSession mcSession=(McSession) sessionsIterator.next(); - logger.debug("iterating mcSession:..." + mcSession); - - McSessionMarkDTO mcSessionMarkDTO= new McSessionMarkDTO(); - mcSessionMarkDTO.setSessionId(mcSession.getMcSessionId().toString()); - mcSessionMarkDTO.setSessionName(mcSession.getSession_name().toString()); - - Set sessionUsers=mcSession.getMcQueUsers(); - Iterator usersIterator=sessionUsers.iterator(); - - LinkedList sessionUsersData= new LinkedList(); - Map mapSessionUsersData= new TreeMap(new McStringComparator()); - while (usersIterator.hasNext()) - { - McQueUsr mcQueUsr=(McQueUsr) usersIterator.next(); - logger.debug("iterating mcQueUsr:..." + mcQueUsr); - - McUserMarkDTO mcUserMarkDTO= new McUserMarkDTO(); - mcUserMarkDTO.setSessionId(mcSession.getMcSessionId().toString()); - mcUserMarkDTO.setUserName(mcQueUsr.getFullname()); - mcUserMarkDTO.setQueUsrId(mcQueUsr.getQueUsrId().toString()); - - - List listQuestions=mcService.getAllQuestionEntries(mcContent.getUid()); - logger.debug("listQuestions:..." + listQuestions); - - Iterator itListQuestions = listQuestions.iterator(); - LinkedList userMarks= new LinkedList(); - - while (itListQuestions.hasNext()) - { - McQueContent mcQueContent =(McQueContent)itListQuestions.next(); - logger.debug("mcQueContent:..." + mcQueContent); - if (mcQueContent != null) - { - String learnerMark=getLearnerMarkForQuestionInSession(mcQueContent.getUid(), mcSession.getUid(), mcQueUsr.getUid(), mcSession, mcService); - logger.debug("learnerMark for queContent uid, mcSession uid, mcUser uid:..." + mcQueContent.getUid() + "--" + mcSession.getUid() - + "--" + mcQueUsr.getUid() + "is: " + learnerMark); - - userMarks.add(learnerMark); + // We get the mark for the attempt if the answer is correct and we don't allow + // retries, or if the answer is correct and the learner has met the passmark if + // we do allow retries. + Integer mark = attempt.getMarkForShow(mcSession.getMcContent().isRetries()); + userMarks[arrayIndex] = mark; + totalMark += mark.intValue(); } } - logger.debug("final userMarks:..." + userMarks); mcUserMarkDTO.setMarks(userMarks); - - String totalMark=getTotalUserMarkForQuestions(userMarks); - logger.debug("totalMark: " + totalMark); - mcUserMarkDTO.setTotalMark(totalMark); + mcUserMarkDTO.setTotalMark(new Long(totalMark)); - logger.debug("final mcUserMarkDTO:..." + mcUserMarkDTO); - sessionUsersData.add(mcUserMarkDTO); + mapSessionUsersData.put(mapIndex.toString(), mcUserMarkDTO); + mapIndex=new Long(mapIndex.longValue()+1); } - logger.debug("final sessionUsersData: " + sessionUsersData); - mapSessionUsersData=convertToMcUserMarkDTOMap(sessionUsersData); - logger.debug("final mapSessionUsersData: " + mapSessionUsersData); + mcSessionMarkDTO.setUserMarks(mapSessionUsersData); listMonitoredMarksContainerDTO.add(mcSessionMarkDTO); } - logger.debug("final listMonitoredMarksContainerDTO:..." + listMonitoredMarksContainerDTO); + if ( logger.isDebugEnabled() ) + logger.debug("final listMonitoredMarksContainerDTO:..." + listMonitoredMarksContainerDTO); + return listMonitoredMarksContainerDTO; } - /** - * - * String getLearnerMarkForQuestionInSession(Long mcQueContentUid, Long mcSessionUid, Long mcQueUsrUid, - * McSession mcSession, IMcService mcService) * - * @param mcQueContentUid - * @param mcSessionUid - * @param mcQueUsrUid - * @param mcSession - * @param mcService - * @return - */ - public static String getLearnerMarkForQuestionInSession(Long mcQueContentUid, Long mcSessionUid, Long mcQueUsrUid, McSession mcSession, IMcService mcService) - { - logger.debug("starting getLearnerMarkForQuestionInSession: mcQueContentUid" + mcQueContentUid); - logger.debug("using getLearnerMarkForQuestionInSession: mcSessionUid" + mcSessionUid); - logger.debug("using getLearnerMarkForQuestionInSession: mcQueUsrUid" + mcQueUsrUid); - - McUsrAttempt mcUsrAttempt = mcService.getAttemptWithLastAttemptOrderForUserInSession(mcQueUsrUid, mcSessionUid); - logger.debug("mcUsrAttempt with highest attempt order: " + mcUsrAttempt); - String highestAttemptOrder=""; - - List listUserAttempts=null; - if (mcUsrAttempt != null) - { - highestAttemptOrder=mcUsrAttempt.getAttemptOrder().toString(); - logger.debug("highestAttemptOrder: " + highestAttemptOrder); - listUserAttempts=mcService.getAttemptsOnHighestAttemptOrder(mcQueUsrUid,mcQueContentUid, mcSessionUid, new Integer(highestAttemptOrder)); - logger.debug("listUserAttempts: " + listUserAttempts); - } - else - { - return "0"; - } - - if (listUserAttempts.size() == 0) - return "0"; - - Iterator itAttempts=listUserAttempts.iterator(); - - if (!mcSession.getMcContent().isRetries()) - { - logger.debug("retries is OFF."); - boolean isAttemptCorrect=false; - McUsrAttempt mcUsrAttemptUser=null; - - { - mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - mcUsrAttemptUser=mcUsrAttempt; - - if (mcUsrAttempt != null) - { - if (mcUsrAttempt.isAttemptCorrect()) - { - isAttemptCorrect=true; - } - } - } - logger.debug("final isAttemptCorrect: " + isAttemptCorrect); - logger.debug("mcUsrAttemptUser: " + mcUsrAttemptUser); - - if (isAttemptCorrect) - { - //return mcUsrAttemptUser.getMcQueContent().getWeight().toString(); - return mcUsrAttemptUser.getMcQueContent().getMark().toString(); - } - else - { - return "0"; - } - } - else - { - logger.debug("retries is ON. User had to PASS. Print the final attempt's data"); - McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); - boolean isAttemptCorrect=false; - McUsrAttempt mcUsrAttemptGeneral=null; - while (itAttempts.hasNext()) - { - mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - mcUsrAttemptGeneral=mcUsrAttempt; - - if (mcUsrAttempt != null) - { - if (mcUsrAttempt.isFinished() && mcUsrAttempt.isPassed()) - { - logger.debug("this is a individual question attempt that is finished and passed: " + mcUsrAttempt); - isAttemptCorrect=mcService.getUserAttemptCorrectForQuestionContentAndSessionUid(mcQueUsrUid,mcQueContentUid, mcSession.getUid(), new Integer(highestAttemptOrder)); - logger.debug("isAttemptCorrect: " + isAttemptCorrect); - break; - } - } - } - - logger.debug("final isAttemptCorrect: " + isAttemptCorrect); - if (isAttemptCorrect) - { - //return mcUsrAttemptGeneral.getMcQueContent().getWeight().toString(); - return mcUsrAttemptGeneral.getMcQueContent().getMark().toString(); - } - else - { - return "0"; - } - } - } - - - /** - * String getTotalUserMarkForQuestions(LinkedList userMarks) - * - * @param userMarks - * @return - */ - public static String getTotalUserMarkForQuestions(LinkedList userMarks) - { - Iterator itAttempts=userMarks.iterator(); - int totalMark= 0; - while (itAttempts.hasNext()) - { - String mark=(String)itAttempts.next(); - int intMark= new Integer(mark).intValue(); - totalMark=totalMark + intMark; - } - return new Integer(totalMark).toString(); - } - - - /** - * List buildSessionQuestionData(HttpServletRequest request, McContent mcContent, Long sessionId, Long userID) - * - * @param request - * @param mcContent - * @param sessionId - * @param userID - * @return - */ - public static List buildSessionQuestionData(HttpServletRequest request, McContent mcContent, Long sessionId, Long userID, IMcService mcService) - { - logger.debug("doing buildSessionQuestionData with sessionId: " + sessionId); - logger.debug("doing buildSessionQuestionData with userID: " + userID); - logger.debug("will be building groups question data for content:..." + mcContent); - - List listQuestions=mcService.getAllQuestionEntries(mcContent.getUid()); - logger.debug("listQuestions:..." + listQuestions); - - List listMonitoredAnswersContainerDTO= new LinkedList(); - - Iterator itListQuestions = listQuestions.iterator(); - while (itListQuestions.hasNext()) - { - McQueContent mcQueContent =(McQueContent)itListQuestions.next(); - logger.debug("mcQueContent:..." + mcQueContent); - - if (mcQueContent != null) - { - McMonitoredAnswersDTO mcMonitoredAnswersDTO= new McMonitoredAnswersDTO(); - mcMonitoredAnswersDTO.setQuestionUid(mcQueContent.getUid().toString()); - mcMonitoredAnswersDTO.setQuestion(mcQueContent.getQuestion()); - - List listCandidateAnswers=mcService.findMcOptionNamesByQueId(mcQueContent.getUid()); - logger.debug("listCandidateAnswers:..." + listCandidateAnswers); - mcMonitoredAnswersDTO.setCandidateAnswers(listCandidateAnswers); - - Map questionAttemptData= buildSessionAttemptData(request, mcContent, mcQueContent, mcQueContent.getUid().toString(), sessionId, - userID, mcService); - logger.debug("questionAttemptData:..." + questionAttemptData); - mcMonitoredAnswersDTO.setQuestionAttempts(questionAttemptData); - listMonitoredAnswersContainerDTO.add(mcMonitoredAnswersDTO); - - } - } - logger.debug("final listMonitoredAnswersContainerDTO:..." + listMonitoredAnswersContainerDTO); - return listMonitoredAnswersContainerDTO; - } - - - - /** - * * buildGroupsAttemptData(HttpServletRequest request, McContent mcContent, McQueContent mcQueContent) * * helps populating user's attempt history @@ -636,225 +304,83 @@ * @return Map */ public static Map buildGroupsAttemptData(HttpServletRequest request, McContent mcContent, McQueContent mcQueContent, - String questionUid, IMcService mcService, McQueUsr mcQueUsr) + Long questionUid, IMcService mcService, McQueUsr mcQueUsr) { logger.debug("will be building groups attempt data for mcQueContent:..." + mcQueContent + " questionUid:" + questionUid); - Map mapMonitoredAttemptsContainerDTO= new TreeMap(new McStringComparator()); - List listMonitoredAttemptsContainerDTO= new LinkedList(); + Map mapMonitoredAttemptsContainerDTO= new TreeMap(new McStringComparator()); Map summaryToolSessions=populateToolSessionsId(request, mcContent, mcService); logger.debug("summaryToolSessions: " + summaryToolSessions); - if (mcQueUsr == null) + Iterator itMap = summaryToolSessions.entrySet().iterator(); + while (itMap.hasNext()) { - Iterator itMap = summaryToolSessions.entrySet().iterator(); - while (itMap.hasNext()) - { - Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - - if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) - { - logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); - McSession mcSession= mcService.findMcSessionById(new Long(pairs.getValue().toString())); - logger.debug("mcSession: " + " = " + mcSession); - - if (mcSession != null) - { - List listMcUsers=mcService.getMcUserBySessionOnly(mcSession); - logger.debug("listMcUsers for session id:" + mcSession.getMcSessionId() + " = " + listMcUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request,mcSession.getMcSessionId(), listMcUsers, questionUid, null, mcService); - - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } - } - } - } - else - { - Iterator itMap = summaryToolSessions.entrySet().iterator(); - while (itMap.hasNext()) - { - Map.Entry pairs = (Map.Entry)itMap.next(); - logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - - if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) - { - logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); - McSession mcSession= mcService.findMcSessionById(new Long(pairs.getValue().toString())); - logger.debug("mcSession: " + " = " + mcSession); - if (mcSession != null) - { - List listMcUsers=mcService.getMcUserBySessionOnly(mcSession); - logger.debug("listMcUsers for session id:" + mcSession.getMcSessionId() + " = " + listMcUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request,mcSession.getMcSessionId(), listMcUsers, questionUid, mcQueUsr.getQueUsrId(), mcService); - - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } - } - } - - } - - - - logger.debug("final listMonitoredAttemptsContainerDTO:..." + listMonitoredAttemptsContainerDTO); - mapMonitoredAttemptsContainerDTO=convertToMap(listMonitoredAttemptsContainerDTO); - logger.debug("final mapMonitoredAttemptsContainerDTO:..." + mapMonitoredAttemptsContainerDTO); - return mapMonitoredAttemptsContainerDTO; - } - - - /** - * Map buildGroupsAttemptDataForExportLearner(HttpServletRequest request, McContent mcContent, McQueContent mcQueContent, String questionUid, - IMcService mcService, McSession mcSession, McQueUsr mcQueUsr ) - - * @param request - * @param mcContent - * @param mcQueContent - * @param questionUid - * @param mcService - * @param mcSession - * @param mcQueUsr - * @return - */ - public static Map buildGroupsAttemptDataForExportLearner(HttpServletRequest request, McContent mcContent, McQueContent mcQueContent, String questionUid, - IMcService mcService, McSession mcSession, McQueUsr mcQueUsr ) - { - logger.debug("will be building groups attempt data for mcQueContent:..." + mcQueContent + " questionUid:" + questionUid); - logger.debug("using mcSession: " +mcSession); - logger.debug("using mcQueUsr: " +mcQueUsr); - - Map mapMonitoredAttemptsContainerDTO= new TreeMap(new McStringComparator()); - List listMonitoredAttemptsContainerDTO= new LinkedList(); + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("using the summary tool sessions pair: " + pairs.getKey() + " = " + pairs.getValue()); - logger.debug("mcSession: " + " = " + mcSession); - if (mcSession != null) - { - List listMcUsers=mcService.getMcUserBySessionOnly(mcSession); - logger.debug("listMcUsers for session id:" + mcSession.getMcSessionId() + " = " + listMcUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request,mcSession.getMcSessionId(), listMcUsers, questionUid, mcQueUsr.getQueUsrId(), mcService); - - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - } + if (!(pairs.getValue().toString().equals("None")) && !(pairs.getValue().toString().equals("All"))) + { + logger.debug("using the numerical summary tool sessions pair: " + " = " + pairs.getValue()); + McSession mcSession= mcService.findMcSessionById(new Long(pairs.getValue().toString())); + logger.debug("mcSession: " + " = " + mcSession); + if (mcSession != null) + { + List listMcUsers=mcService.getMcUserBySessionOnly(mcSession); + logger.debug("listMcUsers for session id:" + mcSession.getMcSessionId() + " = " + listMcUsers); + List sessionUsersAttempts=populateSessionUsersAttempts(request,mcSession.getMcSessionId(), listMcUsers, questionUid, mcService); - logger.debug("final listMonitoredAttemptsContainerDTO:..." + listMonitoredAttemptsContainerDTO); - mapMonitoredAttemptsContainerDTO=convertToMap(listMonitoredAttemptsContainerDTO); + // create a unique group name as the key for these attempts. This name will be shown on the output screen. + // the group name should be unique, so this a a "just in case" + String sessionName = mcSession.getSession_name(); + int extra = 1; + while ( mapMonitoredAttemptsContainerDTO.containsKey(sessionName) ) { + sessionName = sessionName + new Integer(extra).toString(); + extra++; + } + mapMonitoredAttemptsContainerDTO.put(sessionName, sessionUsersAttempts); + } + } + } + logger.debug("final mapMonitoredAttemptsContainerDTO:..." + mapMonitoredAttemptsContainerDTO); return mapMonitoredAttemptsContainerDTO; } - /** - * Map buildSessionAttemptData(HttpServletRequest request, McContent mcContent, McQueContent mcQueContent, String questionUid, - * Long sessionId, Long userID) - * - * @param request - * @param mcContent - * @param mcQueContent - * @param questionUid - * @param sessionId - * @param userID - * @return - */ - public static Map buildSessionAttemptData(HttpServletRequest request, McContent mcContent, McQueContent mcQueContent, String questionUid, Long sessionId, Long userID, IMcService mcService) - { - logger.debug("doing buildSessionAttemptData with sessionId: " + sessionId); - logger.debug("doing buildSessionAttemptData with userID: " + userID); - logger.debug("will be building groups attempt data for mcQueContent:..." + mcQueContent + " questionUid:" + questionUid); - - Map mapMonitoredAttemptsContainerDTO= new TreeMap(new McStringComparator()); - List listMonitoredAttemptsContainerDTO= new LinkedList(); - - McSession mcSession= mcService.findMcSessionById(sessionId); - logger.debug("mcSession: " + " = " + mcSession); - if (mcSession != null) - { - List listMcUsers=mcService.getMcUserBySessionOnly(mcSession); - logger.debug("listMcUsers for session id:" + mcSession.getMcSessionId() + " = " + listMcUsers); - Map sessionUsersAttempts=populateSessionUsersAttempts(request,mcSession.getMcSessionId(), listMcUsers, questionUid, userID, mcService); - - listMonitoredAttemptsContainerDTO.add(sessionUsersAttempts); - logger.debug("final listMonitoredAttemptsContainerDTO:..." + listMonitoredAttemptsContainerDTO); - mapMonitoredAttemptsContainerDTO=convertToMap(listMonitoredAttemptsContainerDTO); - logger.debug("final mapMonitoredAttemptsContainerDTO:..." + mapMonitoredAttemptsContainerDTO); - } - return mapMonitoredAttemptsContainerDTO; - } - - - /** - * return total attempt count from all the users - * getTotalAttemptCount(HttpServletRequest request) - * - * @param request - * @return int - */ - public static int getTotalAttemptCount(HttpServletRequest request, IMcService mcService) - { - List listMarks=mcService.getMarks(); - logger.debug("total attempt count: " + listMarks.size()); - return listMarks.size(); - } - - - /** * * populateSessionUsersAttempts(HttpServletRequest request,List listMcUsers) * * ends up populating all the user's attempt data of a particular tool session * + * if userID is not null, it only gets the attempts for that user. + * * @param request * @param listMcUsers * @return List */ - public static Map populateSessionUsersAttempts(HttpServletRequest request,Long sessionId, List listMcUsers, String questionUid, - Long userID, IMcService mcService) + public static List populateSessionUsersAttempts(HttpServletRequest request,Long sessionId, List listMcUsers, Long questionUid, IMcService mcService) { logger.debug("starting populateSessionUsersAttempts"); logger.debug("will be populating users marks for session id: " + sessionId); McSession mcSession=mcService.retrieveMcSession(sessionId); logger.debug("retrieving mcSession: " + mcSession); - logger.debug("userID: " + userID); - Map mapMonitoredUserContainerDTO= new TreeMap(new McStringComparator()); List listMonitoredUserContainerDTO= new LinkedList(); - logger.debug("generating standard summary page"); + logger.debug("generating standard summary page"); Iterator itUsers=listMcUsers.iterator(); while (itUsers.hasNext()) { McQueUsr mcQueUsr=(McQueUsr)itUsers.next(); logger.debug("current User is: " + mcQueUsr); - - if (mcQueUsr != null) - { - if (userID != null) - { - logger.debug("request is export portfolio " + userID); - logger.debug("mcQueUsr: " + mcQueUsr); - logger.debug("local mcQueUsr userID: " + mcQueUsr.getQueUsrId()); - logger.debug("mcQueUsr.getQueUsrId().toString versus userID.toString(): " + mcQueUsr.getQueUsrId().toString() + " versus " + userID.toString()); - - if (mcQueUsr.getQueUsrId().toString().equals(userID.toString())) - { - logger.debug("returning attempt entries for : " + mcQueUsr); - mapMonitoredUserContainerDTO=getAttemptEntries(request, mcService, mcQueUsr, mcSession, questionUid, listMonitoredUserContainerDTO, mapMonitoredUserContainerDTO); - } - } - else - { - logger.debug("request is standard summary page."); - mapMonitoredUserContainerDTO=getAttemptEntries(request, mcService, mcQueUsr, mcSession, questionUid, listMonitoredUserContainerDTO, mapMonitoredUserContainerDTO); - } - } + logger.debug("request is standard summary page."); + listMonitoredUserContainerDTO=getAttemptEntries(request, mcService, mcQueUsr, mcSession, questionUid, listMonitoredUserContainerDTO, true); } - logger.debug("returning: " + mapMonitoredUserContainerDTO); - return mapMonitoredUserContainerDTO; + + return listMonitoredUserContainerDTO; } - /** * Map getAttemptEntries(HttpServletRequest request, IMcService mcService, McQueUsr mcQueUsr, McSession mcSession, String questionUid, List listMonitoredUserContainerDTO, Map mapMonitoredUserContainerDTO) @@ -868,8 +394,8 @@ * @param mapMonitoredUserContainerDTO * @return */ - public static Map getAttemptEntries(HttpServletRequest request, IMcService mcService, McQueUsr mcQueUsr, McSession mcSession, - String questionUid, List listMonitoredUserContainerDTO, Map mapMonitoredUserContainerDTO) + public static List getAttemptEntries(HttpServletRequest request, IMcService mcService, McQueUsr mcQueUsr, McSession mcSession, + Long questionUid, List listMonitoredUserContainerDTO, boolean latestOnly) { logger.debug("starting getAttemptEntries."); logger.debug("mcQueUsr: " + mcQueUsr); @@ -879,131 +405,49 @@ { logger.debug("getting listUserAttempts for user id: " + mcQueUsr.getUid() + " and que content id: " + questionUid); - McUsrAttempt mcUsrAttempt = mcService.getAttemptWithLastAttemptOrderForUserInSession(mcQueUsr.getUid(), mcSession.getUid()); - logger.debug("mcUsrAttempt with highest attempt order: " + mcUsrAttempt); - String highestAttemptOrder=""; - - List listUserAttempts=null; - boolean attempExists=true; - if (mcUsrAttempt != null) - { - highestAttemptOrder=mcUsrAttempt.getAttemptOrder().toString(); - logger.debug("highestAttemptOrder: " + highestAttemptOrder); + McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); + mcMonitoredUserDTO.setUserName(mcQueUsr.getFullname()); + mcMonitoredUserDTO.setSessionId(mcSession.getMcSessionId().toString()); + mcMonitoredUserDTO.setQuestionUid(questionUid.toString()); + mcMonitoredUserDTO.setQueUsrId(mcQueUsr.getUid().toString()); - listUserAttempts=mcService.getAttemptsOnHighestAttemptOrder(mcQueUsr.getUid(), new Long(questionUid), mcSession.getUid(), new Integer(highestAttemptOrder)); - logger.debug("listUserAttempts: " + listUserAttempts); - } - else - { - attempExists=false; - McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); - mcMonitoredUserDTO.setUserName(mcQueUsr.getFullname()); - //mcMonitoredUserDTO.setSessionId(sessionId.toString()); - mcMonitoredUserDTO.setSessionId(mcSession.getMcSessionId().toString()); - mcMonitoredUserDTO.setQuestionUid(questionUid); - mcMonitoredUserDTO.setMark("0"); - logger.debug("final constructed mcMonitoredUserDTO: " + mcMonitoredUserDTO); - listMonitoredUserContainerDTO.add(mcMonitoredUserDTO); - } - logger.debug("attempExists: " + attempExists); - - if (attempExists) - { - Iterator itAttempts=listUserAttempts.iterator(); + List listUserAttempts = null; + if ( latestOnly ) + listUserAttempts = mcService.getLatestAttemptsForAUserForOneQuestionContent(mcQueUsr.getUid(), questionUid); + else + listUserAttempts = mcService.getAllAttemptsForAUserForOneQuestionContentOrderByAttempt(mcQueUsr.getUid(), questionUid); - if (!mcSession.getMcContent().isRetries()) - { - logger.debug("retries is OFF."); - boolean isAttemptCorrect=false; - McUsrAttempt mcUsrAttemptUser=null; - - while (itAttempts.hasNext()) - { - mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - mcUsrAttemptUser=mcUsrAttempt; + if (listUserAttempts.size() == 0 ) { - if (mcUsrAttempt != null) - { - if (mcUsrAttempt.isAttemptCorrect()) - { - isAttemptCorrect=true; - } - } - } - logger.debug("final isAttemptCorrect: " + isAttemptCorrect); - logger.debug("mcUsrAttemptUser: " + mcUsrAttemptUser); - - McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); - mcMonitoredUserDTO.setUserName(mcQueUsr.getFullname()); - //mcMonitoredUserDTO.setSessionId(sessionId.toString()); - mcMonitoredUserDTO.setSessionId(mcSession.getMcSessionId().toString()); - mcMonitoredUserDTO.setQuestionUid(questionUid); - - if (isAttemptCorrect) - { - //mcMonitoredUserDTO.setMark(mcUsrAttemptUser.getMcQueContent().getWeight().toString()); - mcMonitoredUserDTO.setMark(mcUsrAttemptUser.getMcQueContent().getMark().toString()); - } - else - { - mcMonitoredUserDTO.setMark("0"); - } - - logger.debug("final constructed mcMonitoredUserDTO: " + mcMonitoredUserDTO); - listMonitoredUserContainerDTO.add(mcMonitoredUserDTO); - } - else - { - logger.debug("retries is ON. User had to PASS. Print the final attempt's data"); - McMonitoredUserDTO mcMonitoredUserDTO = new McMonitoredUserDTO(); - boolean isAttemptCorrect=false; - McUsrAttempt mcUsrAttemptGeneral=null; - while (itAttempts.hasNext()) - { - mcUsrAttempt=(McUsrAttempt)itAttempts.next(); - logger.debug("mcUsrAttempt: " + mcUsrAttempt); - mcUsrAttemptGeneral=mcUsrAttempt; + mcMonitoredUserDTO.setMark(new Integer(0)); - if (mcUsrAttempt != null) - { - if (mcUsrAttempt.isFinished() && mcUsrAttempt.isPassed()) - { - logger.debug("this is a individual question attempt that is finished and passed: " + mcUsrAttempt); - isAttemptCorrect=mcService.getUserAttemptCorrectForQuestionContentAndSessionUid(mcQueUsr.getUid(), new Long(questionUid), mcSession.getUid(), new Integer(highestAttemptOrder)); - logger.debug("isAttemptCorrect: " + isAttemptCorrect); - break; - } - } - } + } else { - logger.debug("final isAttemptCorrect: " + isAttemptCorrect); - if (isAttemptCorrect) - { - //mcMonitoredUserDTO.setMark(mcUsrAttemptGeneral.getMcQueContent().getWeight().toString()); - mcMonitoredUserDTO.setMark(mcUsrAttemptGeneral.getMcQueContent().getMark().toString()); - } - else - { - mcMonitoredUserDTO.setMark("0"); - } + // At present, we expect there to be only one answer to a question but there + // could be more in the future - if that happens then we need to change + // String to a list of Strings. - mcMonitoredUserDTO.setUserName(mcQueUsr.getFullname()); - //mcMonitoredUserDTO.setSessionId(sessionId.toString()); - mcMonitoredUserDTO.setSessionId(mcSession.getMcSessionId().toString()); - mcMonitoredUserDTO.setQuestionUid(questionUid); - - logger.debug("final constructed mcMonitoredUserDTO: " + mcMonitoredUserDTO); - listMonitoredUserContainerDTO.add(mcMonitoredUserDTO); + // We get the mark for the attempt if the answer is correct and we don't allow + // retries, or if the answer is correct and the learner has met the passmark if + // we do allow retries. + + Map attemptMap = new TreeMap(); + for ( McUsrAttempt attempt : listUserAttempts) { + attemptMap.put(attempt.getAttemptOrder(), attempt.getMcOptionsContent().getMcQueOptionText()); + mcMonitoredUserDTO.setMark( attempt.getMarkForShow(mcSession.getMcContent().isRetries()) ); + mcMonitoredUserDTO.setIsCorrect( new Boolean(attempt.isAttemptCorrect()).toString() ); } + mcMonitoredUserDTO.setUsersAttempts(attemptMap); } + + if ( logger.isDebugEnabled() ) + logger.debug("final constructed mcMonitoredUserDTO: " + mcMonitoredUserDTO); + + listMonitoredUserContainerDTO.add(mcMonitoredUserDTO); + } - logger.debug("returning : " + listMonitoredUserContainerDTO); - //return listMonitoredUserContainerDTO; - logger.debug("final listMonitoredUserContainerDTO: " + listMonitoredUserContainerDTO); - mapMonitoredUserContainerDTO=convertToMcMonitoredUserDTOMap(listMonitoredUserContainerDTO); - logger.debug("final mapMonitoredUserContainerDTO:..." + mapMonitoredUserContainerDTO); - return mapMonitoredUserContainerDTO; + + return listMonitoredUserContainerDTO; } @@ -1095,58 +539,9 @@ mapIndex=new Long(mapIndex.longValue()+1); } return map; - } - + } /** - * Map convertToMcUserMarkDTOMap(List list) - * - * @param list - * @return - */ - public static Map convertToMcUserMarkDTOMap(List list) - { - logger.debug("using McUserMarkDTOMap: " + list); - Map map= new TreeMap(new McStringComparator()); - - Iterator listIterator=list.iterator(); - Long mapIndex=new Long(1); - - while (listIterator.hasNext()) - { - McUserMarkDTO data=(McUserMarkDTO)listIterator.next(); - map.put(mapIndex.toString(), data); - mapIndex=new Long(mapIndex.longValue()+1); - } - return map; - } - - - /** - * Map convertToMcMonitoredUserDTOMap(List list) - * - * @param list - * @return - */ - public static Map convertToMcMonitoredUserDTOMap(List list) - { - logger.debug("using convertToMcMonitoredUserDTOMap: " + list); - Map map= new TreeMap(new McStringComparator()); - - Iterator listIterator=list.iterator(); - Long mapIndex=new Long(1); - - while (listIterator.hasNext()) - { - McMonitoredUserDTO data=(McMonitoredUserDTO)listIterator.next(); - map.put(mapIndex.toString(), data); - mapIndex=new Long(mapIndex.longValue()+1); - } - return map; - } - - - /** * void buildMcStatsDTO(HttpServletRequest request, IMcService mcService, McContent mcContent) * * @param request