Merge branch 'DAO'
[proteocache.git] / server / compbio / controllers / DailyStatisticsController.java
index 75ab67a..5d183f9 100644 (file)
@@ -14,9 +14,10 @@ import compbio.engine.JobStatus;
 import compbio.beans.DateBean;
 import compbio.beans.TotalJobsStatisticBean;
 import compbio.cassandra.DateFormatter;
+
+import compbio.beans.Total;
 import compbio.cassandra.readers.CassandraReader;
 import compbio.cassandra.readers.DailyStatisticsReader;
-import compbio.cassandra.readers.ProteoDAO;
 
 /**
  * @author Alexander Sherstnev
@@ -27,11 +28,13 @@ import compbio.cassandra.readers.ProteoDAO;
 public class DailyStatisticsController extends BasicController {
 
        /**
-        * form a query page for daily job statistics. The servlet should be
-        * available for users and admins only. By defaults the report time range is
-        * from the earliest day with jobs to today ("Query for all dates" is
-        * ticked). If the user removes the tick the time range is from today - 3
-        * days to today. Currently, the input model is empty.
+        * form a query page for daily job statistics.
+        * 
+        * The servlet should be available for users and admins only. By defaults
+        * the report time range is from the earliest day with jobs to current date
+        * ("Query for all dates" is ticked). If the user removes the tick the time
+        * range is from today - 3 days to today. Currently, the input model is
+        * empty.
         * 
         * @param model
         *            MVC model
@@ -61,8 +64,8 @@ public class DailyStatisticsController extends BasicController {
         *            the final date for the report (if option is set, date2 =
         *            today)
         * @param option
-        *            defined whether the whole time range of jobs is reported
-        *            (null means date1 and date2 are used)
+        *            defined whether the whole time range of jobs is reported (null
+        *            means date1 and date2 are used)
         * @return link to the report JSP page
         */
        @RequestMapping(value = "/stat/jobsdaily/results", method = RequestMethod.GET)
@@ -102,11 +105,19 @@ public class DailyStatisticsController extends BasicController {
                model.put("date2", date2);
                TotalJobsStatisticBean res = reader.query(longDate1, longDate2);
                model.put("result", res);
+               Map<String, Total> results = res.getDateTotal();
+               String csvline = "\'Date\',\'Total\',\'OK\',\'Stopped\',\'Error\',\'Timeout\'%0A";
+               for (Map.Entry<String, Total> entry : results.entrySet()) {
+                       csvline += "\'" + entry.getKey() + "\',\'" + entry.getValue().getTotal() + "\',\'" + entry.getValue().getTotalOK() + "\',\'"
+                                       + entry.getValue().getTotalStopped() + "\',\'" + entry.getValue().getTotalError() + "\',\'"
+                                       + entry.getValue().getTotalTimeOut() + "\'%0A";
+               }
+               model.put("csvfile", csvline);
                model.put("ndays", res.getDateTotal().size());
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("option", option);
-               return "/reportJobStatistics";
+               return "reports/JobStatistics";
        }
 
        /**
@@ -139,10 +150,10 @@ public class DailyStatisticsController extends BasicController {
                        realdate = date;
                        thetime = formaterDDMMYY.parse(realdate).getTime();
                }
-               
-               if (null == JobStatus.getJobStatus(status)) {
+
+               if (null == JobStatus.getJobStatus(status)) 
                        return "support/Notimplemented";
-               }
+
 
                DailyStatisticsReader reader = new DailyStatisticsReader();
                // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
@@ -154,6 +165,6 @@ public class DailyStatisticsController extends BasicController {
                model.put("status", status);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               return "/reportJobStatisticsOneDay";
+               return "reports/JobStatisticsOneDay";
        }
 }