X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=webservices%2Fcompbio%2Fstat%2Fservlet%2Futil%2FStatCollection.java;h=0409e2c353672040e95534332e2d58a3605dd24a;hb=bd0947557dcf7e83b1cd37b4f266646517d86df6;hp=d6644c3579caed17fb8fb407a104ae8c882c21f7;hpb=4ad65552bbb074e33263b03dd4eb96660765203e;p=jabaws.git diff --git a/webservices/compbio/stat/servlet/util/StatCollection.java b/webservices/compbio/stat/servlet/util/StatCollection.java index d6644c3..0409e2c 100644 --- a/webservices/compbio/stat/servlet/util/StatCollection.java +++ b/webservices/compbio/stat/servlet/util/StatCollection.java @@ -41,16 +41,15 @@ public class StatCollection { return localStat; } - public static Map getStats(int monthsToReport) + public static Map getStats(int monthsToReport) throws SQLException { Calendar fromCal = GregorianCalendar.getInstance(); fromCal.add(Calendar.MONTH, -monthsToReport); return getStats(fromCal.getTime()); } - public static Map getStats(Date fromDate) - throws SQLException { - Map allstats = new TreeMap(); + public static Map getStats(Date fromDate) throws SQLException { + Map allstats = new TreeMap(); Calendar fromCal = GregorianCalendar.getInstance(); fromCal.setTime(fromDate); @@ -58,35 +57,30 @@ public class StatCollection { Calendar toCal = GregorianCalendar.getInstance(); toCal.setTime(new Date()); - if (fromCal.after(toCal)) { throw new AssertionError("From Date must be before ToDate! "); } - - while (true) { + while (fromCal.before(toCal)) { Date from = fromCal.getTime(); fromCal.add(Calendar.MONTH, 1); - if (toCal.before(fromCal)) { - allstats.put(toCal.getTime(), - StatCollection.newStatCollecton(from, toCal.getTime())); - break; - } - // System.out.println("!" + from + " !!! " + fromCal.getTime()); - allstats.put(from, - StatCollection.newStatCollecton(from, fromCal.getTime())); + allstats.put(from, getJobCounts(from, fromCal.getTime())); } return allstats; } - public static Map getTotalStats( - Map detailedStats) { - Map totals = new TreeMap(); - for (Map.Entry stat : detailedStats.entrySet()) { - totals.put(stat.getKey(), Totals.sumStats(stat.getValue().allStat)); - } - return totals; + + private static Totals getJobCounts(Date from, Date to) throws SQLException { + StatDB db = new StatDB(); + Totals t = new Totals(); + Timestamp fromTime = new Timestamp(from.getTime()); + Timestamp toTime = new Timestamp(to.getTime()); + t.total = db.getTotalJobsCount(fromTime, toTime); + t.incomplete = db.getIncompleteCount(fromTime, toTime); + t.abandoned = db.getAbandonedCount(fromTime, toTime); + t.cancelled = db.getCancelledCount(fromTime, toTime); + return t; } - static StatCollection newStatCollecton(Date startDate, Date endDate) + public static StatCollection newStatCollecton(Date startDate, Date endDate) throws SQLException { Timestamp startStamp = new Timestamp(startDate.getTime());