Add version collapsing to downloads page, add latest JTDA binaries

This commit is contained in:
mchr3k 2012-08-14 13:50:53 +01:00
parent 8f050aa770
commit 809af6982e
8 changed files with 123 additions and 110 deletions

View File

@ -1,6 +1,5 @@
#Mon Apr 23 22:28:35 BST 2012
eclipse.preferences.version=1
filesCopiedToWebInfLib=appengine-api-1.0-sdk-1.6.4.jar|appengine-api-labs-1.6.4.jar|appengine-jsr107cache-1.6.4.jar|jsr107cache-1.1.jar|datanucleus-appengine-1.0.10.final.jar|datanucleus-core-1.1.5.jar|datanucleus-jpa-1.1.5.jar|geronimo-jpa_3.0_spec-1.1.1.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-eb.jar
filesCopiedToWebInfLib=appengine-api-labs.jar|appengine-jsr107cache-1.6.4.jar|jsr107cache-1.1.jar|appengine-api-1.0-sdk-1.6.4.jar|datanucleus-appengine-1.0.10.final.jar|datanucleus-core-1.1.5.jar|datanucleus-jpa-1.1.5.jar|geronimo-jpa_3.0_spec-1.1.1.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-eb.jar
gaeDeployDialogSettings=
gaeIsEclipseDefaultInstPath=true
googleCloudSqlEnabled=false

View File

@ -7,6 +7,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
@ -136,7 +138,10 @@ public class Counter
return detachedList;
}
public static Map<String,Map<String,Integer>> getPerFilePerDateMap(List<Counter> xiList)
private static final Pattern sVerPattern = Pattern.compile("(.+)_([0-9]+(\\.[0-9]+)*)(\\..+)");
public static Map<String,Map<String,Integer>> getPerFilePerDateMap(List<Counter> xiList,
boolean xiCollapseVers)
{
Map<String,Map<String,Integer>> lFileMap = new HashMap<String, Map<String,Integer>>();
@ -146,6 +151,15 @@ public class Counter
String lDateStr = lCounter.mDate;
Integer lCount = lCounter.mCount;
if (xiCollapseVers)
{
Matcher matcher = sVerPattern.matcher(lFile);
if (matcher.matches())
{
lFile = matcher.group(1) + "*" + matcher.group(4);
}
}
Map<String, Integer> lDateMap = lFileMap.get(lFile);
if (lDateMap == null)
{
@ -153,7 +167,20 @@ public class Counter
lFileMap.put(lFile, lDateMap);
}
lDateMap.put(lDateStr, lCount);
if (xiCollapseVers)
{
Integer lAllVersCount = lDateMap.get(lDateStr);
if (lAllVersCount == null)
{
lAllVersCount = 0;
}
lAllVersCount += lCount;
lDateMap.put(lDateStr, lAllVersCount);
}
else
{
lDateMap.put(lDateStr, lCount);
}
}
return lFileMap;

View File

@ -18,25 +18,50 @@ public class CounterTest
@Test
public void testMapping()
{
List<Counter> lTestData = new ArrayList<Counter>();
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2010, 1, 1),
"test.wav"));
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2011, 2, 2),
"test.wav"));
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2011, 2, 2),
"foo.wav"));
{
List<Counter> lTestData = new ArrayList<Counter>();
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2010, 1, 1),
"test.wav"));
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2011, 2, 2),
"test.wav"));
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2011, 2, 2),
"foo.wav"));
Map<String, Map<String, Integer>> map = Counter.getPerFilePerDateMap(lTestData);
assertEquals(2, map.keySet().size());
assertTrue(map.keySet().toString(), map.keySet().contains("test.wav"));
assertTrue(map.keySet().toString(), map.keySet().contains("foo.wav"));
Map<String, Integer> lData = map.get("test.wav");
assertEquals(2, lData.keySet().size());
assertTrue(lData.keySet().toString(), lData.keySet().contains("2010/01/01"));
assertTrue(lData.keySet().toString(), lData.keySet().contains("2011/02/02"));
Map<String, Map<String, Integer>> map = Counter.getPerFilePerDateMap(lTestData, false);
assertEquals(2, map.keySet().size());
assertTrue(map.keySet().toString(), map.keySet().contains("test.wav"));
assertTrue(map.keySet().toString(), map.keySet().contains("foo.wav"));
Map<String, Integer> lData = map.get("test.wav");
assertEquals(2, lData.keySet().size());
assertTrue(lData.keySet().toString(), lData.keySet().contains("2010/01/01"));
assertTrue(lData.keySet().toString(), lData.keySet().contains("2011/02/02"));
}
{
List<Counter> lTestData = new ArrayList<Counter>();
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2010, 1, 1),
"test_1.0.1.wav"));
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2010, 1, 1),
"test_1.0.2.wav"));
lTestData.add(new Counter(Type.DAY,
Type.DAY.getPartialStr(2011, 2, 2),
"test_1.0.3.wav"));
Map<String, Map<String, Integer>> map = Counter.getPerFilePerDateMap(lTestData, true);
assertEquals(1, map.keySet().size());
assertTrue(map.keySet().toString(), map.keySet().contains("test*.wav"));
Map<String, Integer> lData = map.get("test*.wav");
assertEquals(2, lData.keySet().size());
assertTrue(lData.keySet().toString(), lData.keySet().contains("2010/01/01"));
assertEquals((Integer)2, lData.get("2010/01/01"));
assertTrue(lData.keySet().toString(), lData.keySet().contains("2011/02/02"));
assertEquals((Integer)1, lData.get("2011/02/02"));
}
}
@Test

View File

@ -38,7 +38,10 @@
Type lType = Type.WEEK;
// Check file
String lFileStr = request.getParameter("file");
String lFileStr = request.getParameter("file");
// Check whether to collapse versions
String lCollapseVersions = request.getParameter("collapseversions");
// Check type
String lModeStr = request.getParameter("mode");
@ -64,12 +67,13 @@
List<Counter> lRecords = Counter.getAllByType(lFetchType);
// Filename -> DateStr -> Count
Map<String,Map<String,Integer>> lPerFilePerDateStrDownloads = Counter.getPerFilePerDateMap(lRecords);
Map<String,Map<String,Integer>> lPerFilePerDateStrDownloads = Counter.getPerFilePerDateMap(lRecords,
(lCollapseVersions != null));
if (lType == Type.WEEK)
{
lPerFilePerDateStrDownloads = Counter.getFilePerWeekMap(lPerFilePerDateStrDownloads);
}
// Filenames
List<String> lFilenames = new ArrayList<String>(lPerFilePerDateStrDownloads.keySet());
Collections.sort(lFilenames);
@ -80,7 +84,10 @@
lFileStr = Utils.dec(lFileStr);
Map<String,Integer> lSingleValue = lPerFilePerDateStrDownloads.get(lFileStr);
lPerFilePerDateStrDownloads.clear();
lPerFilePerDateStrDownloads.put(lFileStr, lSingleValue);
if (lSingleValue != null)
{
lPerFilePerDateStrDownloads.put(lFileStr, lSingleValue);
}
}
// Date strings
@ -183,16 +190,8 @@
}
function setMode(mode)
{
if (getUrlVars()['file'])
{
window.location.href = "downloads.jsp?file=" + getUrlVars()['file'] +
"&mode=" + mode;
}
else
{
window.location.href = "downloads.jsp?mode=" + mode;
}
{
loadWithUrlArg('mode', mode);
}
function selectFile()
@ -201,16 +200,25 @@
var file = picker.value;
if (file)
{
if (getUrlVars()['mode'])
loadWithUrlArg('file', file);
}
}
function loadWithUrlArg(key, value)
{
var args = getUrlVars();
args[key] = value;
var newUrl = "downloads.jsp?";
for each (var item in ['mode','file','collapseversions'])
{
if (args[item])
{
window.location.href = "downloads.jsp?file=" + file +
"&mode=" + getUrlVars()['mode'];
newUrl += item + "=" + args[item] + "&";
}
else
{
window.location.href = "downloads.jsp?file=" + file;
}
}
}
window.location.href = newUrl;
}
// Read a page's GET URL variables and return them as an associative array.
@ -226,6 +234,19 @@
}
return vars;
}
function setCollapse()
{
var collapseEl = document.getElementById("collapseversions");
if (collapseEl.checked)
{
loadWithUrlArg('collapseversions', true);
}
else
{
loadWithUrlArg('collapseversions');
}
}
</script>
<select id="filePicker" onchange="selectFile()">
<option selected value="">Choose File...</option>
@ -237,7 +258,13 @@
<input type="submit" value="Year" onclick="setMode('year')" />
<input type="submit" value="Month" onclick="setMode('month')" />
<input type="submit" value="Week" onclick="setMode('week')" />
<input type="submit" value="Day" onclick="setMode('day')" /><br>
<input type="submit" value="Day" onclick="setMode('day')" />
<input type="checkbox"
id="collapseversions"
value="collapseversions"
onclick="setCollapse()"
<% if (lCollapseVersions != null) { %>checked="checked" <% } %>/> Collapse Versions
<br>
<div style="width: 100%;" id="visualization"></div>
<div id="normaltable">
<table>

Binary file not shown.

View File

@ -1,65 +0,0 @@
<!--
You are free to copy and use this sample in accordance with the terms of the
Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Some raw data (not necessarily accurate)
var countries =
['Bolivia', 'Ecuador',
'Madagascar', 'Papua Guinea', 'Rwanda'];
var months = ['2004/05', '2005/06', '2006/07', '2007/08', '2008/09'];
var productionByCountry = [[165, 135, 157, 139, 136],
[938, 1120, 1167, 1110, 691],
[522, 599, 587, 615, 629],
[998, 1268, 807, 968, 1026],
[450, 288, 397, 215, 366]];
// Create and populate the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
for (var i = 0; i < countries.length; ++i) {
data.addColumn('number', countries[i]);
}
data.addRows(months.length);
for (var i = 0; i < months.length; ++i) {
data.setCell(i, 0, months[i]);
}
for (var i = 0; i < countries.length; ++i) {
var country = productionByCountry[i];
for (var month = 0; month < months.length; ++month) {
data.setCell(month, i + 1, country[month]);
}
}
// Create and draw the visualization.
var ac = new google.visualization.AreaChart(document.getElementById('visualization'));
ac.draw(data, {
title : 'Monthly Coffee Production by Country',
isStacked: true,
width: 600,
height: 400,
vAxis: {title: "Cups"},
hAxis: {title: "Month"}
});
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="visualization" style="width: 600px; height: 400px;"></div>
</body>
</html>