SVN: toys/cvsstats/web: README WebContent/index.jsp build.xml data data/full.xml data/top-bottom.xml...

pawelz pawelz at pld-linux.org
Mon Apr 5 16:49:36 CEST 2010


Author: pawelz
Date: Mon Apr  5 16:49:35 2010
New Revision: 11307

Added:
   toys/cvsstats/web/data/
   toys/cvsstats/web/data/full.xml   (contents, props changed)
   toys/cvsstats/web/data/top-bottom.xml   (contents, props changed)
Modified:
   toys/cvsstats/web/README
   toys/cvsstats/web/WebContent/index.jsp
   toys/cvsstats/web/build.xml
   toys/cvsstats/web/src/cvsstats.properties
   toys/cvsstats/web/src/pl/org/pld/cvsstats/Configuration.java
   toys/cvsstats/web/src/pl/org/pld/cvsstats/Stats.java
Log:
- implemented queries sets configurable via external xml files.
  It will be possible to change SQL queries and their descriptions without
  recompiling or even restarting webapp.


Modified: toys/cvsstats/web/README
==============================================================================
--- toys/cvsstats/web/README	(original)
+++ toys/cvsstats/web/README	Mon Apr  5 16:49:35 2010
@@ -2,6 +2,8 @@
 
    - Create JNDI jdbc data source in your servlet container
    - set JNDI name in WEB-INF/classes/cvsstats.properties file
+   - create /var/lib/cvsstats and copy data/*.xml to that dir (you can
+     override path changing datadir property in cvsstats.properties file).
 
    Unlike most web application, cvsstats does not come with all dependencies.
    Depending on your java webserver you may need to install joda-time.jar and

Modified: toys/cvsstats/web/WebContent/index.jsp
==============================================================================
--- toys/cvsstats/web/WebContent/index.jsp	(original)
+++ toys/cvsstats/web/WebContent/index.jsp	Mon Apr  5 16:49:35 2010
@@ -1,11 +1,15 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
-    pageEncoding="UTF-8" import="pl.org.pld.cvsstats.Stats" %>
+    pageEncoding="UTF-8" import="pl.org.pld.cvsstats.Stats,pl.org.pld.cvsstats.QueriesSet" %>
 <%@ page import="org.joda.time.Interval"%>
 <%@ page import="org.joda.time.Period"%>
 <%@ page import="org.joda.time.DateTime;"%>
 
-<% Stats s = new Stats(); %>
+<%
+	Stats s = new Stats();
+	QueriesSet topbottom = new QueriesSet("top-bottom", s);
+	QueriesSet full = new QueriesSet("full", s);
+%>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
@@ -16,10 +20,11 @@
 <body>
 
 <h1>Basic stats</h1>
+<p>
 Number of commiters: <%=s.simpleQuery("SELECT COUNT(DISTINCT author) FROM commits @WHERE@") %><br />
 Number of commits: <%=s.simpleQuery("SELECT COUNT(*) FROM commits @WHERE@") %><br />
-<br />
-Most hard-working developers:<br />
-<%=s.query("SELECT author, sum(added)+sum(removed) AS `Number of changed lines`, sum(added), sum(removed) FROM commits @WHERE@ GROUP BY author ORDER BY `Number of changed lines` DESC").getHtml() %>
+</p>
+<%=topbottom.getHtml() %>
+<%=full.getHtml() %>
 </body>
 </html>
\ No newline at end of file

Modified: toys/cvsstats/web/build.xml
==============================================================================
--- toys/cvsstats/web/build.xml	(original)
+++ toys/cvsstats/web/build.xml	Mon Apr  5 16:49:35 2010
@@ -8,10 +8,12 @@
 
 	<property name="servlet.jar" value="/usr/share/java/servlet-api.jar" />
 	<property name="joda-time.jar" value="/usr/share/java/joda-time.jar" />
+	<property name="xerces.jar" value="/usr/share/java/xerces-j2.jar" />
 
 	<path id="build.path">
 		<pathelement location="${servlet.jar}" />
 		<pathelement location="${joda-time.jar}" />
+		<pathelement location="${xerces.jar}" />
 	</path>
 
 	<property name="war" value="${appname}.war" />

Added: toys/cvsstats/web/data/full.xml
==============================================================================
--- (empty file)
+++ toys/cvsstats/web/data/full.xml	Mon Apr  5 16:49:35 2010
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<queriesset>
+	<title>Full stats</title>
+	<queries>
+		<query id="1">
+			<title>Modified lines per deveoper</title>
+			<description>
+				Number of changed lines per developer. Each added or removed line
+				counts as 1. Modified line counts as 2 (1 removed + 1 added).
+			</description>
+			<sql>
+				SELECT author, sum(added)+sum(removed) AS `Number of changed lines`, sum(added), sum(removed)
+				FROM commits
+				@WHERE@
+				GROUP BY author
+				ORDER BY `Number of changed lines` DESC
+			</sql>
+		</query>
+	</queries>
+</queriesset>
+<!-- vim:tabstop=2 -->

Added: toys/cvsstats/web/data/top-bottom.xml
==============================================================================
--- (empty file)
+++ toys/cvsstats/web/data/top-bottom.xml	Mon Apr  5 16:49:35 2010
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<queriesset>
+	<title>Top/bottom</title>
+	<queries>
+		<query id="1">
+			<title>Most hard-working developers</title>
+			<description>
+				Most hard-working developers, i.e. developers that scored most number of
+				added/removed lines.
+			</description>
+			<sql>
+				SELECT author, sum(added)+sum(removed) AS `Number of changed lines`, sum(added), sum(removed)
+				FROM commits
+				@WHERE@
+				GROUP BY author
+				ORDER BY `Number of changed lines` DESC
+				LIMIT 3
+			</sql>
+		</query>
+	</queries>
+</queriesset>
+<!-- vim:tabstop=2 -->

Modified: toys/cvsstats/web/src/cvsstats.properties
==============================================================================
--- toys/cvsstats/web/src/cvsstats.properties	(original)
+++ toys/cvsstats/web/src/cvsstats.properties	Mon Apr  5 16:49:35 2010
@@ -1 +1,2 @@
 database.jndi=java:comp/env/jdbc/cvsstats
+datadir=/var/lib/cvsstats

Modified: toys/cvsstats/web/src/pl/org/pld/cvsstats/Configuration.java
==============================================================================
--- toys/cvsstats/web/src/pl/org/pld/cvsstats/Configuration.java	(original)
+++ toys/cvsstats/web/src/pl/org/pld/cvsstats/Configuration.java	Mon Apr  5 16:49:35 2010
@@ -6,6 +6,7 @@
 public class Configuration {
 	private static String version = null;
 	private static String dbJNDI = null;
+	private static String dataDir = null;
 
 	public static String getVersion() {
 		if (version == null) version = initializeVersion();
@@ -17,6 +18,11 @@
 		return dbJNDI;
 	}
 	
+	public static String getDataDir() {
+		if (dataDir == null) initializeConfig();
+		return dataDir;
+	}
+	
 	private static String initializeVersion() {
 		try {
 			Properties v = new Properties();
@@ -35,6 +41,7 @@
 			Properties v = new Properties();
 			v.load(Configuration.class.getResourceAsStream("/cvsstats.properties"));
 			dbJNDI = v.getProperty("database.jndi");
+			dataDir = v.getProperty("datadir");
 		}
 		catch(IOException e)
 		{

Modified: toys/cvsstats/web/src/pl/org/pld/cvsstats/Stats.java
==============================================================================
--- toys/cvsstats/web/src/pl/org/pld/cvsstats/Stats.java	(original)
+++ toys/cvsstats/web/src/pl/org/pld/cvsstats/Stats.java	Mon Apr  5 16:49:35 2010
@@ -14,6 +14,7 @@
 
 public class Stats {
 	String intervalExpression = "";
+	Interval interval;
 	
 	/* CONSTRUCTORS */
 	public Stats() {
@@ -30,6 +31,7 @@
 		MySQLDateTime start = new MySQLDateTime(p.getStart());
 		MySQLDateTime end = new MySQLDateTime(p.getEnd());
 		
+		interval = p;
 		intervalExpression = "date >= '"+start.getTimeStamp()+"' AND date < '"+end.getTimeStamp()+"'";
 	}
 	
@@ -100,4 +102,8 @@
 		Matcher m = r.matcher(query);
 		return m.replaceFirst("WHERE "+intervalExpression);
 	}
+	
+	public Interval getInterval() {
+		return interval;
+	}
 }
\ No newline at end of file


More information about the pld-cvs-commit mailing list