Index: lams_tool_vote/conf/language/ApplicationResources.properties =================================================================== diff -u -r83ebb6f565f6d5ce638160e37fc6793c074c6356 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 83ebb6f565f6d5ce638160e37fc6793c074c6356) +++ lams_tool_vote/conf/language/ApplicationResources.properties (.../ApplicationResources.properties) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -40,6 +40,9 @@ label.add.option =Add New button.removeQuestion =Delete label.other =Other +label.view.chart =View Chart (All Votes) +label.view.pieChart =View Pie-Chart +label.view.barChart =View Bar-Chart button.delete =Delete label.fileContent =File Content label.withRetries =Voting with Retries Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/VoteAppConstants.java =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/VoteAppConstants.java (.../VoteAppConstants.java) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/VoteAppConstants.java (.../VoteAppConstants.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -44,6 +44,7 @@ public static final String LEARNING_STARTER ="learningStarter"; public static final String MONITORING_STARTER ="monitoringStarter"; public static final String LOAD_LEARNER ="loadLearner"; + public static final String GENERATE_CHART ="generateChart"; public static final String ALL_NOMINATIONS ="allNominations"; public static final String LOAD_MONITORING_CONTENT ="loadMonitoring"; public static final String LOAD_MONITORING_CONTENT_EDITACTIVITY ="loadMonitoringEditActivity"; @@ -106,6 +107,7 @@ public static final String MAP_QUESTIONS_CONTENT ="mapQuestionsContent"; public static final String MAP_QUESTION_CONTENT ="mapQuestionContent"; public static final String MAP_OPTIONS_CONTENT ="mapOptionsContent"; + public static final String MAP_VOTERATES_CONTENT ="mapVoteRatesContent"; public static final String MAP_OPTIONS_CONTENT_FCK ="mapOptionsContentFck"; public static final String MAP_DEFAULTOPTIONS_CONTENT ="mapDefaultOptionsContent"; public static final String MAP_DISABLED_QUESTIONS ="mapDisabledQuestions"; Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java =================================================================== diff -u -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java (.../IVoteUsrAttemptDAO.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/IVoteUsrAttemptDAO.java (.../IVoteUsrAttemptDAO.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -45,6 +45,12 @@ public List getUserEntries(); + public int getAllEntriesCount(); + + public int getUserRecordsEntryCount(final String userEntry); + + public int getAttemptsForQuestionContent(final Long voteQueContentId); + public void removeAttemptsForUser(final Long queUsrId); public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId); Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java =================================================================== diff -u -r83ebb6f565f6d5ce638160e37fc6793c074c6356 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java (.../VoteUsrAttemptDAO.java) (revision 83ebb6f565f6d5ce638160e37fc6793c074c6356) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/dao/hibernate/VoteUsrAttemptDAO.java (.../VoteUsrAttemptDAO.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -39,13 +39,11 @@ public class VoteUsrAttemptDAO extends HibernateDaoSupport implements IVoteUsrAttemptDAO { static Logger logger = Logger.getLogger(VoteUsrAttemptDAO.class.getName()); - private static final String LOAD_HIGHEST_MARK_BY_USER_ID = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; - - private static final String LOAD_HIGHEST_ATTEMPT_ORDER_BY_USER_ID = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; - private static final String LOAD_ATTEMPT_FOR_QUE_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; private static final String LOAD_ATTEMPT_FOR_USER = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; + + private static final String LOAD_ATTEMPT_FOR_QUESTION_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.voteQueContentId=:voteQueContentId"; private static final String LOAD_ATTEMPT_FOR_USER_AND_QUESTION_CONTENT = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteQueContentId=:voteQueContentId"; @@ -54,6 +52,10 @@ private static final String LOAD_USER_ENTRIES = "select distinct voteUsrAttempt.userEntry from VoteUsrAttempt voteUsrAttempt"; private static final String LOAD_USER_ENTRY_RECORDS = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.userEntry=:userEntry and voteUsrAttempt.voteQueContentId=1 "; + + private static final String LOAD_DISTINCT_USER_ENTRY_RECORDS = "select distinct voteUsrAttempt.queUsrId from VoteUsrAttempt voteUsrAttempt where voteUsrAttempt.userEntry=:userEntry"; + + private static final String LOAD_ALL_ENTRIES = "select voteUsrAttempt.userEntry from VoteUsrAttempt voteUsrAttempt"; public VoteUsrAttempt getVoteUserAttemptByUID(Long uid) @@ -85,6 +87,21 @@ return list; } + + public int getUserRecordsEntryCount(final String userEntry) + { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_DISTINCT_USER_ENTRY_RECORDS) + .setString("userEntry", userEntry) + .list(); + + if(list != null && list.size() > 0){ + return list.size(); + } + return 0; + } + + public void removeAttemptsForUser(final Long queUsrId) { HibernateTemplate templ = this.getHibernateTemplate(); @@ -106,7 +123,6 @@ public void removeAttemptsForUserandSession(final Long queUsrId, final Long voteSessionId) { - //String strGetUser = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId and voteUsrAttempt.voteSessionId=:voteSessionId"; String strGetUser = "from voteUsrAttempt in class VoteUsrAttempt where voteUsrAttempt.queUsrId=:queUsrId"; HibernateTemplate templ = this.getHibernateTemplate(); List list = getSession().createQuery(strGetUser) @@ -130,6 +146,20 @@ } + public int getAttemptsForQuestionContent(final Long voteQueContentId) + { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ATTEMPT_FOR_QUESTION_CONTENT) + .setLong("voteQueContentId", voteQueContentId.longValue()) + .list(); + + if(list != null && list.size() > 0){ + return list.size(); + } + + return 0; + } + public VoteUsrAttempt getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) { @@ -156,14 +186,6 @@ .setLong("voteQueContentId", voteQueContentId.longValue()) .list(); - /* - if(list != null && list.size() > 0){ - VoteUsrAttempt voteA = (VoteUsrAttempt) list.get(0); - return voteA; - } - - return null; - */ if(list != null && list.size() > 0){ Iterator listIterator=list.iterator(); while (listIterator.hasNext()) @@ -216,6 +238,14 @@ return list; } + public int getAllEntriesCount() + { + HibernateTemplate templ = this.getHibernateTemplate(); + List list = getSession().createQuery(LOAD_ALL_ENTRIES) + .list(); + return list.size(); + } + public void updateVoteUsrAttempt(VoteUsrAttempt voteUsrAttempt) { Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java =================================================================== diff -u -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java (.../IVoteService.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/IVoteService.java (.../IVoteService.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -82,6 +82,12 @@ public void updateVoteQueContent(VoteQueContent voteQueContent) throws VoteApplicationException; + public int getAttemptsForQuestionContent(final Long voteQueContentId) throws VoteApplicationException; + + public int getAllEntriesCount() throws VoteApplicationException; + + public int getUserRecordsEntryCount(final String userEntry) throws VoteApplicationException; + public VoteUsrAttempt getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) throws VoteApplicationException; public VoteUsrAttempt getAttemptsForUserAndQuestionContentAndSession(final Long queUsrId, final Long voteQueContentId, final Long toolSessionUid) throws VoteApplicationException; Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java =================================================================== diff -u -rc3d18ff9199715376d8d75d0173bbc595e53f4b5 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java (.../VoteServicePOJO.java) (revision c3d18ff9199715376d8d75d0173bbc595e53f4b5) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/service/VoteServicePOJO.java (.../VoteServicePOJO.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -188,6 +188,7 @@ } } + public VoteQueUsr getVoteQueUsrById(long voteQueUsrId) throws VoteApplicationException { try @@ -453,8 +454,52 @@ e); } } + + public int getAllEntriesCount() throws VoteApplicationException + { + try + { + return voteUsrAttemptDAO.getAllEntriesCount(); + } + catch (DataAccessException e) + { + throw new VoteApplicationException("Exception occured when lams is getting all attempts entries count: " + + e.getMessage(), + e); + } + } + + public int getUserRecordsEntryCount(final String userEntry) throws VoteApplicationException + { + try + { + return voteUsrAttemptDAO.getUserRecordsEntryCount(userEntry); + } + catch (DataAccessException e) + { + throw new VoteApplicationException("Exception occured when lams is getting userrecords entry count: " + + e.getMessage(), + e); + } + + } + + public int getAttemptsForQuestionContent(final Long voteQueContentId) throws VoteApplicationException + { + try + { + return voteUsrAttemptDAO.getAttemptsForQuestionContent(voteQueContentId); + } + catch (DataAccessException e) + { + throw new VoteApplicationException("Exception occured when lams is getting vote UsrAttempt by question content id only: " + + e.getMessage(), + e); + } + } + public VoteUsrAttempt getAttemptsForUserAndQuestionContent(final Long queUsrId, final Long voteQueContentId) throws VoteApplicationException { try Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/AuthoringUtil.java =================================================================== diff -u -r261d9a36d11a99322125fa55faaddffc16a041b3 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 261d9a36d11a99322125fa55faaddffc16a041b3) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/AuthoringUtil.java (.../AuthoringUtil.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -62,11 +62,6 @@ public class AuthoringUtil implements VoteAppConstants { static Logger logger = Logger.getLogger(AuthoringUtil.class.getName()); - protected static void setRadioboxes(VoteContent voteContent, VoteAuthoringForm voteAuthoringForm) - { - } - - public static boolean verifyDuplicatesOptionsMap(Map mapOptionsContent) { Map originalMapOptionsContent=mapOptionsContent; Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/LearningUtil.java =================================================================== diff -u -r83ebb6f565f6d5ce638160e37fc6793c074c6356 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/LearningUtil.java (.../LearningUtil.java) (revision 83ebb6f565f6d5ce638160e37fc6793c074c6356) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/LearningUtil.java (.../LearningUtil.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -177,7 +177,6 @@ if (voteQueContent != null) { - //VoteUsrAttempt existingVoteUsrAttempt=voteService.getAttemptsForUserAndQuestionContent(voteQueUsr.getQueUsrId(),voteQueContent.getVoteContentId()); VoteUsrAttempt existingVoteUsrAttempt=voteService.getAttemptsForUserAndQuestionContentAndSession(voteQueUsr.getQueUsrId(),voteQueContent.getVoteContentId(), voteSession.getUid()); logger.debug("existingVoteUsrAttempt: " + existingVoteUsrAttempt); @@ -284,7 +283,6 @@ logger.debug("updated mapCurrentOptions: " + mapCurrentOptions); mapFinal=mapCurrentOptions; - //request.getSession().setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapCurrentOptions); } else { @@ -297,12 +295,9 @@ mapLeanerCheckedOptionsContent.remove(voteLearningForm.getOptionIndex()); mapFinal=mapLeanerCheckedOptionsContent; - //request.getSession().setAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT, mapLeanerCheckedOptionsContent); } } - //mapGeneralCheckedOptionsContent=(Map) request.getSession().getAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT); - //logger.debug("final mapGeneralCheckedOptionsContent: " + mapGeneralCheckedOptionsContent); logger.debug("mapFinal: " + mapFinal); return mapFinal; } Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringUtil.java =================================================================== diff -u -r277d8412bc03b9c73992a0e6f3ad845cd0a4eba6 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision 277d8412bc03b9c73992a0e6f3ad845cd0a4eba6) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/MonitoringUtil.java (.../MonitoringUtil.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -544,6 +544,25 @@ } + public static double calculateTotal(Map mapVoteRatesContent) + { + logger.debug("calculating total for: " + mapVoteRatesContent); + double total=0d; + Iterator itMap = mapVoteRatesContent.entrySet().iterator(); + while (itMap.hasNext()) { + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("using the pair: " + pairs.getKey() + " = " + pairs.getValue()); + + if (pairs.getValue() != null) + { + total=total+ new Double(pairs.getValue().toString()).doubleValue(); + } + logger.debug("total: " + total); + } + return total; + } + + public static Map convertToMap(List list) { logger.debug("using convertToMap: " + list); @@ -560,5 +579,125 @@ } return map; } + + + public static void prepareChartData(HttpServletRequest request, IVoteService voteService, Long toolContentId) + { + logger.debug("starting prepareChartData: " + toolContentId); + VoteContent voteContent=voteService.retrieveVote(toolContentId); + + logger.debug("existing voteContent:" + voteContent); + Map mapOptionsContent= new TreeMap(new VoteComparator()); + logger.debug("mapOptionsContent: " + mapOptionsContent); + + Map mapVoteRatesContent= new TreeMap(new VoteComparator()); + logger.debug("mapVoteRatesContent: " + mapVoteRatesContent); + + int allEntriesCount=voteService.getAllEntriesCount(); + logger.debug("allEntriesCount: " + allEntriesCount); + + List userEntries=voteService.getUserEntries(); + logger.debug("userEntries: " + userEntries); + int distinctEntriesCount= userEntries.size(); + logger.debug("distinctEntriesCount: " + distinctEntriesCount); + + logger.debug("setting existing content data from the db"); + mapOptionsContent.clear(); + Iterator queIterator=voteContent.getVoteQueContents().iterator(); + Long mapIndex=new Long(1); + logger.debug("mapOptionsContent: " + mapOptionsContent); + while (queIterator.hasNext()) + { + VoteQueContent voteQueContent=(VoteQueContent) queIterator.next(); + if (voteQueContent != null) + { + logger.debug("question: " + voteQueContent.getQuestion()); + mapOptionsContent.put(mapIndex.toString(),voteQueContent.getQuestion()); + + int votesCount=voteService.getAttemptsForQuestionContent(voteQueContent.getUid()); + logger.debug("votesCount for questionContent uid: " + votesCount + " for" + voteQueContent.getUid()); + + double voteRate=0d; + if (allEntriesCount != 0) + { + voteRate=((votesCount * 100)/ allEntriesCount); + } + logger.debug("voteRate" + voteRate); + + mapVoteRatesContent.put(mapIndex.toString(), new Double(voteRate).toString()); + + + /** + * make the first entry the default(first) one for jsp + */ + if (mapIndex.longValue() == 1) + { + request.getSession().setAttribute(DEFAULT_OPTION_CONTENT, voteQueContent.getQuestion()); + } + + mapIndex=new Long(mapIndex.longValue()+1); + } + } + logger.debug("Map initialized with existing contentid to: " + mapOptionsContent); + + Iterator itListQuestions = userEntries.iterator(); + int mapVoteRatesSize=mapVoteRatesContent.size(); + logger.debug("mapVoteRatesSize: " + mapVoteRatesSize); + mapIndex=new Long(mapVoteRatesSize+1); + logger.debug("updated mapIndex: " + mapIndex); + + double total=MonitoringUtil.calculateTotal(mapVoteRatesContent); + logger.debug("updated mapIndex: " + mapIndex); + double share=100d-total ; + logger.debug("share: " + share); + + double totalUserRate=0d; + while (itListQuestions.hasNext()) + { + String userEntry =(String)itListQuestions.next(); + logger.debug("userEntry:..." + userEntry); + + if ((userEntry != null) && (userEntry.length() > 0)) + { + + int userEntryRate=voteService.getUserRecordsEntryCount(userEntry); + logger.debug("userEntryRate: " + userEntryRate); + totalUserRate=totalUserRate + userEntryRate; + } + } + logger.debug("totalUserRate: " + totalUserRate); + + + itListQuestions = userEntries.iterator(); + while (itListQuestions.hasNext()) + { + String userEntry =(String)itListQuestions.next(); + logger.debug("userEntry:..." + userEntry); + logger.debug("mapIndex: " + mapIndex); + + if ((userEntry != null) && (userEntry.length() > 0)) + { + + int userEntryRate=voteService.getUserRecordsEntryCount(userEntry); + logger.debug("userEntryRate: " + userEntryRate); + + double votesShare= (userEntryRate * share) / totalUserRate ; + logger.debug("votesShare: " + votesShare); + + mapVoteRatesContent.put(mapIndex.toString(), new Double(votesShare).toString()); + + mapOptionsContent.put(mapIndex.toString() ,userEntry); + mapIndex=new Long(mapIndex.longValue()+1); + } + } + + + logger.debug("Map initialized with mapVoteRatesContent: " + mapVoteRatesContent); + request.getSession().setAttribute(MAP_VOTERATES_CONTENT, mapVoteRatesContent); + logger.debug("starter initialized the MAP_VOTERATES_CONTENT Map: " + request.getSession().getAttribute(MAP_VOTERATES_CONTENT)); + + request.getSession().setAttribute(MAP_OPTIONS_CONTENT, mapOptionsContent); + logger.debug("final starter initialized the MAP_OPTIONS_CONTENT Map: " + request.getSession().getAttribute(MAP_OPTIONS_CONTENT) ); + } } Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteChartGenerator.java =================================================================== diff -u --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteChartGenerator.java (revision 0) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteChartGenerator.java (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -0,0 +1,127 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ + +package org.lamsfoundation.lams.tool.vote.web; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.data.general.DefaultPieDataset; +import org.lamsfoundation.lams.tool.vote.VoteAppConstants; + +/** + * @author Ozgur Demirtas + * generates JFreeCharts + */ +public class VoteChartGenerator extends HttpServlet implements VoteAppConstants { + static Logger logger = Logger.getLogger(VoteChartGenerator.class.getName()); + + public VoteChartGenerator(){ + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException + { + logger.debug("dispatching doGet for VoteChartGenerator..."); + + logger.debug("MAP_VOTERATES_CONTENT Map: " + request.getSession().getAttribute(MAP_VOTERATES_CONTENT)); + logger.debug("MAP_OPTIONS_CONTENT Map: " + request.getSession().getAttribute(MAP_OPTIONS_CONTENT)); + OutputStream out= response.getOutputStream(); + + try{ + String type=request.getParameter("type"); + logger.debug("type: " + type); + JFreeChart chart=null; + + if (type.equals("pie")) + { + logger.debug("creating pie chart"); + chart=createPieChart(request); + } + else if (type.equals("bar")) + { + logger.debug("creating bar chart"); + chart=createBarChart(); + } + + logger.debug("chart:" + chart); + if (chart != null) + { + response.setContentType("image/png"); + ChartUtilities.writeChartAsPNG(out, chart, 400, 300); + } + + } + catch(Exception e) + { + logger.error("error occurred generating chart: " + e); + } + finally + { + out.close(); + } + } + + private JFreeChart createPieChart(HttpServletRequest request) + { + logger.debug("starting createPieChart..."); + DefaultPieDataset data= new DefaultPieDataset(); + + Map mapNominationsContent=(Map)request.getSession().getAttribute(MAP_OPTIONS_CONTENT); + logger.error("mapNominationsContent: " + mapNominationsContent); + + Map mapVoteRatesContent=(Map)request.getSession().getAttribute(MAP_VOTERATES_CONTENT); + logger.error("mapVoteRatesContent: " + mapVoteRatesContent); + + Iterator itMap = mapNominationsContent.entrySet().iterator(); + while (itMap.hasNext()) + { + Map.Entry pairs = (Map.Entry)itMap.next(); + logger.debug("using the nomination content pair: " + pairs.getKey() + " = " + pairs.getValue()); + + String voteRate=(String) mapVoteRatesContent.get(pairs.getKey()); + logger.debug("voteRate:" + voteRate); + data.setValue(pairs.getValue().toString(), new Double(voteRate)); + } + + JFreeChart chart=ChartFactory.createPieChart("All Votes Chart", data, true, true, false); + return chart; + + } + + + private JFreeChart createBarChart() + { + return null; + } + +} Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java =================================================================== diff -u -r83ebb6f565f6d5ce638160e37fc6793c074c6356 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java (.../VoteLearningAction.java) (revision 83ebb6f565f6d5ce638160e37fc6793c074c6356) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningAction.java (.../VoteLearningAction.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -251,19 +251,6 @@ VoteUtils.cleanUpSessionAbsolute(request); - - /* REMOVE THIS this is temp code from here **/ - /* - VoteSession voteSession=null; - voteSession=voteService.retrieveVoteSession(toolSessionId); - logger.debug("retrieved voteSession: " + voteSession); - voteSession.setSessionStatus(VoteAppConstants.COMPLETED); - voteService.updateVoteSession(voteSession); - logger.debug("updated voteSession to COMPLETED" + voteSession); - */ - /* till here*/ - - String nextUrl=null; try { @@ -365,10 +352,6 @@ VoteUtils.cleanUpUserExceptions(request); logger.debug("dispatching continueOptionsCombined..."); - - - - VoteLearningForm voteLearningForm = (VoteLearningForm) form; voteLearningForm.setRevisitingPageActive(new Boolean(false).toString()); voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); @@ -409,28 +392,12 @@ return (mapping.findForward(LOAD_LEARNER)); } - - - - - - - - - //VoteLearningForm voteLearningForm = (VoteLearningForm) form; - //voteLearningForm.setRevisitingPageActive(new Boolean(false).toString()); - //voteLearningForm.setNominationsSubmited(new Boolean(false).toString()); - //voteLearningForm.setMaxNominationCountReached(new Boolean(false).toString()); - - IVoteService voteService =VoteUtils.getToolService(request); + IVoteService voteService =VoteUtils.getToolService(request); setContentInUse(request); - //Map mapGeneralCheckedOptionsContent=(Map) request.getSession().getAttribute(MAP_GENERAL_CHECKED_OPTIONS_CONTENT); logger.debug("final mapGeneralCheckedOptionsContent: " + mapGeneralCheckedOptionsContent); Long toolContentId=(Long) request.getSession().getAttribute(TOOL_CONTENT_ID); logger.debug("toolContentId: " + toolContentId); - - //String userEntry=voteLearningForm.getUserEntry(); logger.debug("userEntry: " + userEntry); boolean userEntryAvailable=false; @@ -474,12 +441,10 @@ } logger.debug("voteQueUsr: " + voteQueUsr); - //VoteQueUsr voteQueUsr=LearningUtil.getUser(request); logger.debug("voteQueUsr is : " + voteQueUsr); if (existingVoteQueUsr != null) { - //voteService.removeAttemptsForUser(existingVoteQueUsr.getUid()); logger.debug("attempt removing attempts for user id and session id:" + existingVoteQueUsr.getUid() + " " + voteSession.getUid() ); voteService.removeAttemptsForUserandSession(existingVoteQueUsr.getUid(), voteSession.getUid() ); logger.debug("votes deleted for user: " + voteQueUsr.getUid()); @@ -527,9 +492,10 @@ logger.debug("final mapGeneralCheckedOptionsContent: " + mapGeneralCheckedOptionsContent); voteLearningForm.setNominationsSubmited(new Boolean(true).toString()); - //logger.debug("fwd ing to: " + ALL_NOMINATIONS); - //return (mapping.findForward(ALL_NOMINATIONS)); + logger.debug("calling prepareChartData: " + toolContentId); + MonitoringUtil.prepareChartData(request, voteService, toolContentId); + return (mapping.findForward(INDIVIDUAL_REPORT)); } Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningForm.java =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningForm.java (.../VoteLearningForm.java) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningForm.java (.../VoteLearningForm.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -67,7 +67,6 @@ protected String responseId; protected String method; protected String answer; - protected String currentQuestionIndex; protected String submitAnswersContent; protected String getNextQuestion; protected String getPreviousQuestion; @@ -101,18 +100,6 @@ this.answer = answer; } /** - * @return Returns the currentQuestionIndex. - */ - public String getCurrentQuestionIndex() { - return currentQuestionIndex; - } - /** - * @param currentQuestionIndex The currentQuestionIndex to set. - */ - public void setCurrentQuestionIndex(String currentQuestionIndex) { - this.currentQuestionIndex = currentQuestionIndex; - } - /** * @return Returns the endLearning. */ public String getEndLearning() { Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningStarterAction.java =================================================================== diff -u -r6e806e2588289bb42a1791b145a0f403a72a883d -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningStarterAction.java (.../VoteLearningStarterAction.java) (revision 6e806e2588289bb42a1791b145a0f403a72a883d) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteLearningStarterAction.java (.../VoteLearningStarterAction.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -268,9 +268,7 @@ /* PREVIEW_ONLY for jsp*/ request.getSession().setAttribute(PREVIEW_ONLY, new Boolean(true).toString()); - - request.getSession().setAttribute(CURRENT_QUESTION_INDEX, "1"); - VoteLearningAction voteLearningAction= new VoteLearningAction(); + VoteLearningAction voteLearningAction= new VoteLearningAction(); return voteLearningAction.redoQuestions(mapping, form, request, response); } @@ -332,10 +330,8 @@ request.getSession().setAttribute(MAP_QUESTION_CONTENT_LEARNER, mapQuestionsContent); logger.debug("MAP_QUESTION_CONTENT_LEARNER: " + request.getSession().getAttribute(MAP_QUESTION_CONTENT_LEARNER)); - logger.debug("voteContent has : " + mapQuestionsContent.size() + " entries."); + request.getSession().setAttribute(MAP_OPTIONS_CONTENT, mapQuestionsContent); - request.getSession().setAttribute(CURRENT_QUESTION_INDEX, "1"); - logger.debug("CURRENT_QUESTION_INDEX: " + request.getSession().getAttribute(CURRENT_QUESTION_INDEX)); /* * verify that userId does not already exist in the db. @@ -470,10 +466,6 @@ logger.debug("MAP_QUESTION_CONTENT_LEARNER: " + request.getSession().getAttribute(MAP_QUESTION_CONTENT_LEARNER)); logger.debug("voteContent has : " + mapQuestionsContent.size() + " entries."); request.getSession().setAttribute(TOTAL_QUESTION_COUNT, new Long(mapQuestionsContent.size()).toString()); - - request.getSession().setAttribute(CURRENT_QUESTION_INDEX, "1"); - logger.debug("CURRENT_QUESTION_INDEX: " + request.getSession().getAttribute(CURRENT_QUESTION_INDEX)); - } Index: lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteMonitoringStarterAction.java =================================================================== diff -u -r6e806e2588289bb42a1791b145a0f403a72a883d -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteMonitoringStarterAction.java (.../VoteMonitoringStarterAction.java) (revision 6e806e2588289bb42a1791b145a0f403a72a883d) +++ lams_tool_vote/src/java/org/lamsfoundation/lams/tool/vote/web/VoteMonitoringStarterAction.java (.../VoteMonitoringStarterAction.java) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -23,9 +23,6 @@ package org.lamsfoundation.lams.tool.vote.web; import java.io.IOException; -import java.util.Iterator; -import java.util.Map; -import java.util.TreeMap; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -41,10 +38,8 @@ import org.apache.struts.action.ActionMessages; import org.lamsfoundation.lams.tool.vote.VoteAppConstants; import org.lamsfoundation.lams.tool.vote.VoteApplicationException; -import org.lamsfoundation.lams.tool.vote.VoteComparator; import org.lamsfoundation.lams.tool.vote.VoteUtils; import org.lamsfoundation.lams.tool.vote.pojos.VoteContent; -import org.lamsfoundation.lams.tool.vote.pojos.VoteQueContent; import org.lamsfoundation.lams.tool.vote.service.IVoteService; import org.lamsfoundation.lams.tool.vote.service.VoteServiceProxy; import org.lamsfoundation.lams.web.util.AttributeNames; @@ -98,50 +93,26 @@ IVoteService voteService = VoteServiceProxy.getVoteService(getServlet().getServletContext()); - - /* we have made sure TOOL_CONTENT_ID is passed */ Long toolContentId =(Long) request.getSession().getAttribute(TOOL_CONTENT_ID); logger.debug("toolContentId: " + toolContentId); + + logger.debug("calling prepareChartData: " + toolContentId); + MonitoringUtil.prepareChartData(request, voteService, toolContentId); - VoteContent voteContent=voteService.retrieveVote(toolContentId); - - logger.debug("existing voteContent:" + voteContent); - Map mapOptionsContent= new TreeMap(new VoteComparator()); - logger.debug("mapOptionsContent: " + mapOptionsContent); - - logger.debug("setting existing content data from the db"); - mapOptionsContent.clear(); - Iterator queIterator=voteContent.getVoteQueContents().iterator(); - Long mapIndex=new Long(1); - logger.debug("mapOptionsContent: " + mapOptionsContent); - while (queIterator.hasNext()) - { - VoteQueContent voteQueContent=(VoteQueContent) queIterator.next(); - if (voteQueContent != null) - { - logger.debug("question: " + voteQueContent.getQuestion()); - mapOptionsContent.put(mapIndex.toString(),voteQueContent.getQuestion()); - /** - * make the first entry the default(first) one for jsp - */ - if (mapIndex.longValue() == 1) - { - request.getSession().setAttribute(DEFAULT_OPTION_CONTENT, voteQueContent.getQuestion()); - } - - mapIndex=new Long(mapIndex.longValue()+1); - } - } - logger.debug("Map initialized with existing contentid to: " + mapOptionsContent); - request.getSession().setAttribute(MAP_OPTIONS_CONTENT, mapOptionsContent); - logger.debug("starter initialized the Comparable Map: " + request.getSession().getAttribute(MAP_OPTIONS_CONTENT) ); + VoteContent voteContent=voteService.retrieveVote(toolContentId); + int allUserEntriesCount=voteService.getAllEntriesCount(); + logger.debug("allUserEntriesCount: " + allUserEntriesCount); - /*true means there is at least 1 response*/ if (voteService.studentActivityOccurredGlobal(voteContent)) { + request.getSession().setAttribute(USER_EXCEPTION_NO_TOOL_SESSIONS, new Boolean(false).toString()); + logger.debug("USER_EXCEPTION_NO_TOOL_SESSIONS is set to false"); + } + else if (allUserEntriesCount > 0) + { request.getSession().setAttribute(USER_EXCEPTION_NO_TOOL_SESSIONS, new Boolean(false).toString()); - logger.debug("USER_EXCEPTION_NO_TOOL_SESSIONS is set to false"); + logger.debug("allUserEntriesCount is:" + allUserEntriesCount + " USER_EXCEPTION_NO_TOOL_SESSIONS is set to false"); } else { @@ -167,9 +138,6 @@ request.getSession().setAttribute(REQUEST_LEARNING_REPORT, new Boolean(false).toString()); request.getSession().setAttribute(USER_EXCEPTION_NO_TOOL_SESSIONS, new Boolean(true).toString()); - /* - * persist time zone information to session scope. - */ VoteUtils.persistTimeZone(request); /* we have made sure TOOL_CONTENT_ID is passed */ @@ -230,9 +198,6 @@ logger.debug("refreshing instructions data..."); voteMonitoringAction.refreshInstructionsData(request, voteContent); - /* this section is related to instructions tab. Starts here. */ - /* ends here. */ - logger.debug("end initializing monitoring data..."); return true; } Index: lams_tool_vote/web/WEB-INF/struts-config.xml =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -8,6 +8,7 @@ + Index: lams_tool_vote/web/WEB-INF/web.xml =================================================================== diff -u -rad683fcaeabe83c702b599c5c866bb7d30cd7191 -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/web/WEB-INF/web.xml (.../web.xml) (revision ad683fcaeabe83c702b599c5c866bb7d30cd7191) +++ lams_tool_vote/web/WEB-INF/web.xml (.../web.xml) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -132,7 +132,14 @@ exportPortfolio org.lamsfoundation.lams.tool.vote.web.VoteExportServlet + + + chartGenerator + org.lamsfoundation.lams.tool.vote.web.VoteChartGenerator + + + Connector @@ -163,6 +170,11 @@ /portfolioExport + + chartGenerator + /chartGenerator/* + + Connector /fckeditor/editor/filemanager/browser/default/connectors/jsp/connector Index: lams_tool_vote/web/learning/AllNominations.jsp =================================================================== diff -u -rae28185f07883077586773f760d1bde953e2d9bf -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/web/learning/AllNominations.jsp (.../AllNominations.jsp) (revision ae28185f07883077586773f760d1bde953e2d9bf) +++ lams_tool_vote/web/learning/AllNominations.jsp (.../AllNominations.jsp) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -57,14 +57,19 @@ - CHART FOR ALL RESULTS + + + + + + + - -      +      Index: lams_tool_vote/web/monitoring/SummaryContent.jsp =================================================================== diff -u -re6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c -r2be43d0e5d701ff9c00b32c85e0d35f3367d52cb --- lams_tool_vote/web/monitoring/SummaryContent.jsp (.../SummaryContent.jsp) (revision e6d4c9ba0ba0e2b42b4ff2f997618bfedc28dd7c) +++ lams_tool_vote/web/monitoring/SummaryContent.jsp (.../SummaryContent.jsp) (revision 2be43d0e5d701ff9c00b32c85e0d35f3367d52cb) @@ -31,7 +31,6 @@ - @@ -43,13 +42,32 @@ - + + + + + + + + + + +
+ + + + + + +
+     +