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.Total;
18 import compbio.cassandra.TotalJobsStatisticBean;
19 import compbio.statistic.CassandraRequester;
22 * @author Alexander Sherstnev
23 * @author Natasha Sherstneva
24 * @version 1.0 Dec 2013
27 public class DailyStatisticsController extends BasicController {
30 * form a query page for daily job statistics. The servlet should be
31 * available for users and admins only. By defaults the report time range is
32 * from the earliest day with jobs to today ("Query for all dates" is
33 * ticked). If the user removes the tick the time range is from today - 3
34 * days to today. Currently, the input model is empty.
38 * @return link to the JSP query page
40 @RequestMapping(value = "/stat/jobs/query", method = RequestMethod.GET)
41 public String initFindForm(Map<String, Object> model) {
42 model.put("username", getPrincipalName());
43 Calendar loccal = Calendar.getInstance();
44 String date2 = loccal.get(Calendar.YEAR) + "/" + (loccal.get(Calendar.MONTH) + 1) + "/" + loccal.get(Calendar.DATE);
45 loccal.add(Calendar.DATE, -3);
46 String date1 = loccal.get(Calendar.YEAR) + "/" + (loccal.get(Calendar.MONTH) + 1) + "/" + loccal.get(Calendar.DATE);
47 model.put("date1", date1);
48 model.put("date2", date2);
49 return "query/JobStatistics";
53 * form a report page for daily job statistics.
58 * initial date for the report (if option is set, date2 = the
59 * earliest date with jobs in DB)
61 * the final date for the report (if option is set, date2 =
64 * defined whether the whole time range of jobs is reported (null
65 * means date1 and date2 are used)
66 * @return link to the report JSP page
68 @RequestMapping(value = "/stat/jobsdaily/results", method = RequestMethod.GET)
69 public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
70 @RequestParam("option") String option, Map<String, Object> model) {
71 model.put("username", getPrincipalName());
72 Calendar loccal = Calendar.getInstance();
73 final long startTime = System.currentTimeMillis();
74 CassandraRequester cr = new CassandraRequester();
75 if (option.equals("AllDates,off")) {
76 date1 = theEaerlistDate;
77 date2 = theCurrentDate;
80 // dates in string format
81 String trimmeddate1 = date1.replaceAll("\\s", "");
82 String trimmeddate2 = date2.replaceAll("\\s", "");
83 // dates in long format
84 long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD);
85 long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD);
86 String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2);
88 model.put("error", error);
89 model.put("date1", date1);
90 model.put("date2", date2);
91 return "query/JobStatistics";
94 if (longDate1 < CassandraReader.earliestDate())
95 longDate1 = CassandraReader.earliestDate();
96 if (longDate2 > loccal.getTimeInMillis())
97 longDate2 = loccal.getTimeInMillis();
99 date1 = DateFormatter.DateLongToString(longDate1, formaterYYMMDD);
100 date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD);
101 model.put("date1", date1);
102 model.put("date2", date2);
103 TotalJobsStatisticBean res = cr.countJobs(date1, date2);
104 model.put("result", res);
105 Map<String, Total> results = res.getDateTotal();
106 String csvline = "\'Date\',\'Total\',\'OK\',\'Stopped\',\'Error\',\'Timeout\'%0A";
107 for (Map.Entry<String, Total> entry : results.entrySet()) {
108 csvline += "\'" + entry.getKey() + "\',\'" + entry.getValue().getTotal() + "\',\'" + entry.getValue().getTotalOK() + "\',\'"
109 + entry.getValue().getTotalStopped() + "\',\'" + entry.getValue().getTotalError() + "\',\'"
110 + entry.getValue().getTotalTimeOut() + "\'%0A";
112 model.put("csvfile", csvline);
113 model.put("ndays", res.getDateTotal().size());
114 final long endTime = System.currentTimeMillis();
115 model.put("timeExecution", (endTime - startTime));
116 model.put("option", option);
117 return "/reportJobStatistics";
121 * form a report page for job statistics for one day only.
126 * date for the report
129 * @return link to the report JSP page
131 @RequestMapping(value = "/stat/jobsoneday/results", method = RequestMethod.GET)
132 public String findJobsInOneDay(@RequestParam("date") String date, @RequestParam("status") String status, Map<String, Object> model)
133 throws ParseException {
134 model.put("username", getPrincipalName());
135 final long startTime = System.currentTimeMillis();
139 long thetime = formaterYYMMDD.parse(date).getTime();
143 realdate = formaterDDMMYY.format(new Date(thetime));
145 } catch (ParseException e) {
149 if (null == JobStatus.getJobStatus(status)) {
150 return "support/Notimplemented";
153 CassandraRequester cr = new CassandraRequester();
154 // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
155 DateBean r = cr.readJobByDay(realdate, JobStatus.getJobStatus(status));
156 model.put("results", r);
158 model.put("njobs", r.getJobidAndSeq().size());
159 model.put("date", realdate);
160 model.put("status", status);
161 final long endTime = System.currentTimeMillis();
162 model.put("timeExecution", (endTime - startTime));
163 return "/reportJobStatisticsOneDay";