⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getuserpercentagesdistributionaction.java

📁 老外的在线考试
💻 JAVA
字号:
/* * CyberTester - J2EE Web application for creating, delivering and managing tests/exams/surveys.  * Copyright (C) 2003 CyberDemia Research and Services Pty Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * 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 (see the file COPYING); if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * See the COPYING file located in the top-level-directory of * the archive of this program for complete text of license. */package com.cyberdemia.cybertester.admin.report;import java.util.*;import java.io.ByteArrayOutputStream;import java.awt.Font;import javax.servlet.http.*;import org.apache.struts.action.*;import com.cyberdemia.school.*;import com.cyberdemia.cybertester.*;import com.cyberdemia.cybertester.common.*;import java.util.logging.*;import com.cyberdemia.cybertester.admin.*;import org.jfree.chart.*;import org.jfree.data.*;import org.jfree.chart.labels.*;import org.jfree.chart.axis.*;import org.jfree.chart.renderer.*;import org.jfree.chart.entity.StandardEntityCollection;import org.jfree.chart.plot.PlotOrientation;/** *  * GetUserPercentagesDistributionAction is a Struts action to retrieve distribution * of users' percentages. * * @author Alexander Yap */public final class GetUserPercentagesDistributionAction extends AbstractAdminAction{	protected ActionForward doPerform(		ActionMapping mapping, ActionForm form,		HttpServletRequest request, HttpServletResponse response,		HttpSession session) throws Exception	{		Logger logger = CyberTesterUtils.getLogger();		try		{			DefaultCategoryDataset dataset = new DefaultCategoryDataset();			// Calculation various distributions by questions			ReportGeneratorHome reportGenHome = CyberTesterUtils.getReportGeneratorHome();			ReportGenerator reportGen = (ReportGenerator)reportGenHome.create();			Map distMap = reportGen.getScorePercentageDistributionByUsers(10.0);			Iterator highValIter = distMap.keySet().iterator();			int maxCount = 100;			while (highValIter.hasNext())			{				Double highVal = (Double)highValIter.next();				Integer count = (Integer)distMap.get(highVal);				if (count.intValue() > maxCount)				{					maxCount = count.intValue();				}				dataset.addValue(count, "0", highVal);			}			JFreeChart chart = ChartFactory.createBarChart(				"",				"Overall score %", "Number of users", dataset, PlotOrientation.VERTICAL, false, true, false);			chart.setTitle(new TextTitle("User % Distribution", new Font("SansSerif",Font.BOLD, 12)));			((CategoryAxis)chart.getCategoryPlot().getDomainAxis()).setVerticalCategoryLabels(true);			CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();			ValueAxis rangeAxis = chart.getCategoryPlot().getRangeAxis();			rangeAxis.setMaximumAxisValue((double)maxCount);			rangeAxis.setMinimumAxisValue(0.0);			renderer.setItemLabelGenerator(				new CategoryItemLabelGenerator()				{					public String generateItemLabel(CategoryDataset data, int series, int category)					{						return data.getValue(series, category).toString();					}					public String generateToolTip(CategoryDataset data, int series, int category)					{						String lowerVal = (category>0) ? data.getColumnKey(category-1).toString() : "0";						return "Number of users scoring "+lowerVal+"%-"+data.getColumnKey(category)+"% : "+data.getValue(series, category).toString();					}				}			);			chart.setAntiAlias(true);			int width = 600;			int height = 600;			try			{				width = Integer.parseInt( request.getParameter("width") );			}			catch (NumberFormatException nfex)			{ }			try			{				height = Integer.parseInt( request.getParameter("height") );			}			catch (NumberFormatException nfex)			{ }						final ByteArrayOutputStream baos = new ByteArrayOutputStream();			final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());			ChartUtilities.writeChartAsPNG( baos , chart,width, height, info );			ChartDataCache cache = new ChartDataCache();			cache.data = baos.toByteArray();			cache.info = info;			Map chartsCache = (Map)session.getAttribute(Constants.CHARTS_CACHE_KEY);			String chartId = String.valueOf(System.currentTimeMillis());			chartsCache.put(chartId, cache);			request.setAttribute(Constants.CHART_ID_KEY, chartId );		}		catch (Exception ex)		{			logger.log( Level.SEVERE, "Error getting user percentages distribution", ex);			throw ex;		}					return mapping.findForward(Constants.SUCCESS);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -