X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=server%2Fcompbio%2Fcontrollers%2FDailyStatisticsController.java;fp=server%2Fcompbio%2Fcontrollers%2FDailyStatisticsController.java;h=d6a0c1eaeebbb4e27d41e7b957f33eb2d6b4277a;hb=5a44c7fd7f9802f255bf43489ff325af2df5eb94;hp=ef399f5b245ee417188431bd274e1f9a9de5162d;hpb=d616db97e837bcde43c939f228993c7d6e396a3c;p=proteocache.git diff --git a/server/compbio/controllers/DailyStatisticsController.java b/server/compbio/controllers/DailyStatisticsController.java index ef399f5..d6a0c1e 100644 --- a/server/compbio/controllers/DailyStatisticsController.java +++ b/server/compbio/controllers/DailyStatisticsController.java @@ -12,12 +12,10 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import compbio.engine.JobStatus; -import compbio.cassandra.CassandraReader; import compbio.cassandra.DateBean; -import compbio.cassandra.DateFormatter; import compbio.cassandra.TotalJobsStatisticBean; import compbio.statistic.CassandraRequester; - +import compbio.statistic.StatisticsProt; /** * @author Alexander Sherstnev @@ -25,20 +23,18 @@ import compbio.statistic.CassandraRequester; */ @Controller public class DailyStatisticsController extends BasicController { - Calendar cal = Calendar.getInstance(); - final SimpleDateFormat formaterDDMMYY = DateFormatter.getFormatDDMMYY(); - final SimpleDateFormat formaterYYMMDD = DateFormatter.getFormatYYMMDD(); - String theEaerlistDate = DateFormatter.DateLongToString(CassandraReader.earliestDate(), formaterYYMMDD); - String theCurrentDate = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); - + @RequestMapping(value = "/stat/jobs/query", method = RequestMethod.GET) public String initFindForm(Map model) { model.put("username", getPrincipalName()); + Calendar cal = Calendar.getInstance(); String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE); cal.add(Calendar.DATE, -3); String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE); + model.put("date1", date1); model.put("date2", date2); + return "query/JobStatistics"; } @@ -46,34 +42,14 @@ public class DailyStatisticsController extends BasicController { public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2, @RequestParam("option") String option, Map model) { model.put("username", getPrincipalName()); - final long startTime = System.currentTimeMillis(); + final long startTime = System.currentTimeMillis(); + CassandraRequester cr = new CassandraRequester(); if (option.equals("AllDates,off")) { - date1 = theEaerlistDate; - date2 = theCurrentDate; - } - - // dates in string format - String trimmeddate1 = date1.replaceAll("\\s", ""); - String trimmeddate2 = date2.replaceAll("\\s", ""); - // dates in long format - long longDate1 = DateFormatter.DateParsing(date1,formaterYYMMDD); - long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD); - String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2); - if (error != null) { - model.put("error", error); - model.put("date1", date1); - model.put("date2", date2); - return "query/JobStatistics"; + Calendar cal = Calendar.getInstance(); + date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate()); + date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); } - - if (longDate1 < CassandraReader.earliestDate()) - longDate1 = CassandraReader.earliestDate(); - if (longDate2 > cal.getTimeInMillis()) - longDate2 = cal.getTimeInMillis(); - - date1 = DateFormatter.DateLongToString(longDate1, formaterYYMMDD); - date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD); model.put("date1", date1); model.put("date2", date2); TotalJobsStatisticBean res = cr.countJobs(date1, date2); @@ -92,6 +68,8 @@ public class DailyStatisticsController extends BasicController { final long startTime = System.currentTimeMillis(); String realdate; + final SimpleDateFormat formaterDDMMYY = new SimpleDateFormat("dd/MM/yyyy"); + final SimpleDateFormat formaterYYMMDD = new SimpleDateFormat("yyyy/MM/dd"); try { long thetime = formaterYYMMDD.parse(date).getTime(); if (thetime < 0) { @@ -119,20 +97,4 @@ public class DailyStatisticsController extends BasicController { model.put("timeExecution", (endTime - startTime)); return "/reportJobStatisticsOneDay"; } - - private String DateChecking(String trimmeddate1, String trimmeddate2, long longDate1, long longDate2) { - - if (trimmeddate1.equalsIgnoreCase("") || trimmeddate2.equalsIgnoreCase("")) - return "The date cann't be empty"; - else if (!DateFormatter.isThisDateValid(trimmeddate1, formaterYYMMDD) || !DateFormatter.isThisDateValid(trimmeddate2, formaterYYMMDD)) - return "The date format in invalid. Try format yyyy/mm/dd"; - else if (longDate2 < CassandraReader.earliestDate()) - return "The date2 is after the earlestDate " + theEaerlistDate; - else if (longDate1 > cal.getTimeInMillis()) - return "The date1 is before the current date " + theCurrentDate; - else if (longDate1 > longDate2) - return "Wrong date's diaposon. The date1 is more than date2."; - else - return null; - } }