X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=server%2Fcompbio%2Fcontrollers%2FDailyStatisticsController.java;h=ef399f5b245ee417188431bd274e1f9a9de5162d;hb=23ef7a6a36233ee82656f6d0f602b82f009847ed;hp=c9df6be01f9b3b141e898dd497644a8e3ebf3d3f;hpb=8f30a2189dc9926985d82a113aba87711a91c244;p=proteocache.git diff --git a/server/compbio/controllers/DailyStatisticsController.java b/server/compbio/controllers/DailyStatisticsController.java index c9df6be..ef399f5 100644 --- a/server/compbio/controllers/DailyStatisticsController.java +++ b/server/compbio/controllers/DailyStatisticsController.java @@ -4,7 +4,6 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; -import java.util.List; import java.util.Map; import org.springframework.stereotype.Controller; @@ -12,60 +11,87 @@ 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.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 * @author Natasha Sherstneva */ @Controller -public class DailyStatisticsController { - - @RequestMapping(value = "/stat", method = RequestMethod.GET) +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) { - Calendar cal = Calendar.getInstance(); + model.put("username", getPrincipalName()); 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 "queryJobStatistics"; + return "query/JobStatistics"; } - @RequestMapping(value = "/stat/query", method = RequestMethod.GET) + @RequestMapping(value = "/stat/jobsdaily/results", method = RequestMethod.GET) public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2, @RequestParam("option") String option, Map model) { - final long startTime = System.currentTimeMillis(); - + model.put("username", getPrincipalName()); + final long startTime = System.currentTimeMillis(); CassandraRequester cr = new CassandraRequester(); if (option.equals("AllDates,off")) { - 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); + 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"; } + + 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); - List res = cr.countJobs(date1, date2); + TotalJobsStatisticBean res = cr.countJobs(date1, date2); model.put("result", res); - model.put("ndays", res.size()); + 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 model) throws ParseException { + + @RequestMapping(value = "/stat/jobsoneday/results", method = RequestMethod.GET) + public String findJobsInOneDay(@RequestParam("date") String date, @RequestParam("status") String status, Map model) + throws ParseException { + model.put("username", getPrincipalName()); 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) { @@ -77,14 +103,36 @@ public class DailyStatisticsController { realdate = date; } + if (null == JobStatus.getJobStatus(status)) { + return "support/Notimplemented"; + } + CassandraRequester cr = new CassandraRequester(); // IMPORTANT: input should be suppied in the format: DD/MM/YYYY - List r = cr.readJobByDay(realdate); + DateBean r = cr.readJobByDay(realdate, JobStatus.getJobStatus(status)); model.put("results", r); - model.put("njobs", r.size()); + if (r != null) + model.put("njobs", r.getJobidAndSeq().size()); model.put("date", realdate); + model.put("status", status); final long endTime = System.currentTimeMillis(); 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; + } }