From: Sasa M. <sa...@us...> - 2004-05-31 09:05:30
|
Update of /cvsroot/jrobin/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21037 Modified Files: PlottableDemo.java Log Message: Final changes in NIO Index: PlottableDemo.java =================================================================== RCS file: /cvsroot/jrobin/src/PlottableDemo.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PlottableDemo.java 26 Feb 2004 12:24:45 -0000 1.4 --- PlottableDemo.java 31 May 2004 09:04:50 -0000 1.5 *************** *** 8,16 **** --- 8,38 ---- import java.util.Date; import java.util.GregorianCalendar; + import java.util.Calendar; class PlottableDemo { + static double[] SF_DOWNLOAD_COUNT = { + 0, 0, 13, 34, 76, 72, 255, 144, 135, 194, 358, 304, 247 + }; + static double[] SF_PAGE_HITS = { + 0, 1072, 517, 979, 2132, 2532, 5515, 3519, 3500, 4942, 7858, 7797, 5509 + }; + static GregorianCalendar[] SF_TIMESTAMPS = new GregorianCalendar[SF_DOWNLOAD_COUNT.length]; + static Date SF_START_DATE = new GregorianCalendar(2003, 4, 1).getTime(); // May 1st 2004. + + static { + for(int i = 0; i < SF_TIMESTAMPS.length; i++) { + GregorianCalendar gc = new GregorianCalendar(); + gc.setTime(SF_START_DATE); + gc.add(Calendar.MONTH, i); + SF_TIMESTAMPS[i] = gc; + } + } + private PlottableDemo() throws RrdException, IOException { createGraph1(); createGraph2(); + createGraph3(); + createGraph4(); + createGraph5(); } *************** *** 83,86 **** --- 105,169 ---- } + private void createGraph3() throws RrdException, IOException { + LinearInterpolator linear = new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); + RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); + gDef.setTitle("JRobin page hits per month"); + gDef.setTimeAxisLabel("month"); + gDef.setVerticalLabel("page hits"); + gDef.datasource("linear", linear); + gDef.area("linear", Color.GREEN, null); + gDef.line("linear", Color.RED, "page hits@L", 2); + gDef.vrule(new GregorianCalendar(2004, 0, 1), Color.BLUE, null, 3); + gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); + gDef.comment("Data provided by SourceForge.net@r"); + RrdGraph graph = new RrdGraph(gDef); + String filename = Util.getJRobinDemoPath("plottable3.png"); + graph.saveAsPNG(filename, 400, 200); + System.out.println("Graph3 saved to " + filename); + } + + private void createGraph4() throws RrdException, IOException { + LinearInterpolator linear = new LinearInterpolator(SF_TIMESTAMPS, SF_DOWNLOAD_COUNT); + RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); + gDef.setTitle("JRobin download count per month"); + gDef.setTimeAxisLabel("month"); + gDef.setVerticalLabel("download count"); + gDef.datasource("linear", linear); + gDef.area("linear", Color.GREEN, null); + gDef.line("linear", Color.RED, "download count@L", 2); + gDef.vrule(new GregorianCalendar(2004, 0, 1), Color.BLUE, null, 3); + gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); + gDef.comment("Data provided by SourceForge.net@r"); + RrdGraph graph = new RrdGraph(gDef); + String filename = Util.getJRobinDemoPath("plottable4.png"); + graph.saveAsPNG(filename, 400, 200); + System.out.println("Graph4 saved to " + filename); + } + + private void createGraph5() throws RrdException, IOException { + LinearInterpolator hitsInterpolator = + new LinearInterpolator(SF_TIMESTAMPS, SF_PAGE_HITS); + LinearInterpolator downloadsInterpolator = + new LinearInterpolator(SF_TIMESTAMPS, SF_DOWNLOAD_COUNT); + RrdGraphDef gDef = new RrdGraphDef(SF_TIMESTAMPS[0], SF_TIMESTAMPS[SF_TIMESTAMPS.length - 1]); + gDef.setTitle("JRobin statistics at SourceForge"); + gDef.setTimeAxisLabel("month"); + gDef.setVerticalLabel("hits/downloads"); + gDef.datasource("hits", hitsInterpolator); + gDef.datasource("downloads", downloadsInterpolator); + gDef.datasource("ratio", "downloads,0,EQ,UNKN,hits,downloads,/,IF"); + gDef.area("hits", Color.GREEN, null); + gDef.line("hits", Color.RED, "page hits", 2); + gDef.area("downloads", Color.MAGENTA, "downloads@L"); + gDef.vrule(new GregorianCalendar(2004, 0, 1), Color.BLUE, null, 3); + gDef.setTimeAxis(TimeAxisUnit.MONTH, 1, TimeAxisUnit.MONTH, 1, "MMM", false); + gDef.gprint("ratio", "AVERAGE", "Average number of page hits per download: @0@r"); + gDef.comment("Data provided by SourceForge.net@r"); + RrdGraph graph = new RrdGraph(gDef); + String filename = Util.getJRobinDemoPath("plottable5.png"); + graph.saveAsPNG(filename, 400, 200); + System.out.println("Graph5 saved to " + filename); + } + public static void main(String[] args) throws RrdException, IOException { new PlottableDemo(); |