1 package compbio.controllers;
3 import java.text.ParseException;
4 import java.util.Calendar;
8 import org.springframework.stereotype.Controller;
9 import org.springframework.web.bind.annotation.RequestMapping;
10 import org.springframework.web.bind.annotation.RequestMethod;
11 import org.springframework.web.bind.annotation.RequestParam;
13 import compbio.engine.JobStatus;
14 import compbio.cassandra.CassandraReader;
15 import compbio.cassandra.DateBean;
16 import compbio.cassandra.DateFormatter;
17 import compbio.cassandra.TotalJobsStatisticBean;
18 import compbio.statistic.CassandraRequester;
21 * @author Alexander Sherstnev
22 * @author Natasha Sherstneva
23 * @version 1.0 Dec 2013
26 public class DailyStatisticsController extends BasicController {
29 * form a query page for daily job statistics. The servlet should be
30 * available for users and admins only. By defaults the report time range is
31 * from the earliest day with jobs to today ("Query for all dates" is
32 * ticked). If the user removes the tick the time range is from today - 3
33 * days to today. Currently, the input model is empty.
37 * @return link to the JSP query page
39 @RequestMapping(value = "/stat/jobs/query", method = RequestMethod.GET)
40 public String initFindForm(Map<String, Object> model) {
41 model.put("username", getPrincipalName());
42 Calendar loccal = Calendar.getInstance();
43 String date2 = loccal.get(Calendar.YEAR) + "/" + (loccal.get(Calendar.MONTH) + 1) + "/" + loccal.get(Calendar.DATE);
44 loccal.add(Calendar.DATE, -3);
45 String date1 = loccal.get(Calendar.YEAR) + "/" + (loccal.get(Calendar.MONTH) + 1) + "/" + loccal.get(Calendar.DATE);
46 model.put("date1", date1);
47 model.put("date2", date2);
48 return "query/JobStatistics";
52 * form a report page for daily job statistics.
57 * initial date for the report (if option is set, date2 = the
58 * earliest date with jobs in DB)
60 * the final date for the report (if option is set, date2 =
63 * defined whether the whole time range of jobs is reported
64 * (null means date1 and date2 are used)
65 * @return link to the report JSP page
67 @RequestMapping(value = "/stat/jobsdaily/results", method = RequestMethod.GET)
68 public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
69 @RequestParam("option") String option, Map<String, Object> model) {
70 model.put("username", getPrincipalName());
71 Calendar loccal = Calendar.getInstance();
72 final long startTime = System.currentTimeMillis();
73 CassandraRequester cr = new CassandraRequester();
74 if (option.equals("AllDates,off")) {
75 date1 = theEaerlistDate;
76 date2 = theCurrentDate;
79 // dates in string format
80 String trimmeddate1 = date1.replaceAll("\\s", "");
81 String trimmeddate2 = date2.replaceAll("\\s", "");
82 // dates in long format
83 long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD);
84 long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD);
85 String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2);
87 model.put("error", error);
88 model.put("date1", date1);
89 model.put("date2", date2);
90 return "query/JobStatistics";
93 if (longDate1 < CassandraReader.earliestDate())
94 longDate1 = CassandraReader.earliestDate();
95 if (longDate2 > loccal.getTimeInMillis())
96 longDate2 = loccal.getTimeInMillis();
98 date1 = DateFormatter.DateLongToString(longDate1, formaterYYMMDD);
99 date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD);
100 model.put("date1", date1);
101 model.put("date2", date2);
102 TotalJobsStatisticBean res = cr.countJobs(date1, date2);
103 model.put("result", res);
104 model.put("ndays", res.getDateTotal().size());
105 final long endTime = System.currentTimeMillis();
106 model.put("timeExecution", (endTime - startTime));
107 model.put("option", option);
108 return "/reportJobStatistics";
112 * form a report page for job statistics for one day only.
117 * date for the report
120 * @return link to the report JSP page
122 @RequestMapping(value = "/stat/jobsoneday/results", method = RequestMethod.GET)
123 public String findJobsInOneDay(@RequestParam("date") String date, @RequestParam("status") String status, Map<String, Object> model)
124 throws ParseException {
125 model.put("username", getPrincipalName());
126 final long startTime = System.currentTimeMillis();
130 long thetime = formaterYYMMDD.parse(date).getTime();
134 realdate = formaterDDMMYY.format(new Date(thetime));
136 } catch (ParseException e) {
140 if (null == JobStatus.getJobStatus(status)) {
141 return "support/Notimplemented";
144 CassandraRequester cr = new CassandraRequester();
145 // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
146 DateBean r = cr.readJobByDay(realdate, JobStatus.getJobStatus(status));
147 model.put("results", r);
149 model.put("njobs", r.getJobidAndSeq().size());
150 model.put("date", realdate);
151 model.put("status", status);
152 final long endTime = System.currentTimeMillis();
153 model.put("timeExecution", (endTime - startTime));
154 return "/reportJobStatisticsOneDay";