Merge branch 'servlets' of https://source.jalview.org/git/proteocache into servlets
[proteocache.git] / server / compbio / controllers / DailyStatisticsController.java
index 22df505..b6d5bde 100644 (file)
@@ -12,10 +12,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
-
-import compbio.cassandra.DataBase;
+import compbio.cassandra.DateBean;
+import compbio.cassandra.TotalJobsStatisticBean;
 import compbio.statistic.CassandraRequester;
-import compbio.statistic.StatisticsProt;
 
 /**
  * @author Alexander Sherstnev
@@ -33,7 +32,7 @@ public class DailyStatisticsController {
 
                model.put("date1", date1);
                model.put("date2", date2);
-               
+
                return "queryJobStatistics";
        }
 
@@ -45,36 +44,47 @@ public class DailyStatisticsController {
                CassandraRequester cr = new CassandraRequester();
                if (option.equals("AllDates,off")) {
                        Calendar cal = Calendar.getInstance();
-                       date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate());
+                       date1 = cr.earliestDateString();
                        date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
                }
                model.put("date1", date1);
                model.put("date2", date2);
-               List<DataBase> res = cr.countJobs(date1, date2);
+               TotalJobsStatisticBean res = cr.countJobs(date1, date2);
                model.put("result", res);
+               model.put("ndays", res.getDateTotal().size());
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("option", option);
                return "/reportJobStatistics";
        }
-       
+
        @RequestMapping(value = "/stat/oneday", method = RequestMethod.GET)
        public String findJobsInOneDay(@RequestParam("date") String date, Map<String, Object> model) throws ParseException {
                final long startTime = System.currentTimeMillis();
 
+               String realdate;
                final SimpleDateFormat formaterDDMMYY = new SimpleDateFormat("dd/MM/yyyy");
                final SimpleDateFormat formaterYYMMDD = new SimpleDateFormat("yyyy/MM/dd");
-               String date1 = formaterYYMMDD.format(new Date(formaterDDMMYY.parse(date).getTime()));
-       
+               try {
+                       long thetime = formaterYYMMDD.parse(date).getTime();
+                       if (thetime < 0) {
+                               realdate = date;
+                       } else {
+                               realdate = formaterDDMMYY.format(new Date(thetime));
+                       }
+               } catch (ParseException e) {
+                       realdate = date;
+               }
+
                CassandraRequester cr = new CassandraRequester();
-               //List<DataBase> r1 = cr.countJobs(date1, date1);
-               List<DataBase> r = cr.readJobByDay(date);
+               // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
+               DateBean r = cr.readJobByDay(realdate);
                model.put("results", r);
-               model.put("njobs", r.size());
-               model.put("date", date1);
+               if (r != null)
+                       model.put("njobs", r.getJobidAndSeq().size());
+               model.put("date", realdate);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
-               System.out.println("Request for date = " + date1 + ": " + r.size() + " jobs found");
                return "/reportJobStatisticsOneDay";
        }
 }