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.beans.DateBean;
15 import compbio.beans.TotalJobsStatisticBean;
16 import compbio.cassandra.DateFormatter;
18 import compbio.beans.Total;
19 import compbio.cassandra.readers.CassandraReader;
20 import compbio.cassandra.readers.DailyStatisticsReader;
24 * @author Alexander Sherstnev
25 * @author Natasha Sherstneva
26 * @version 1.0 Dec 2013
29 public class DailyStatisticsController extends BasicController {
32 * form a query page for daily job statistics. The servlet should be
33 * available for users and admins only. By defaults the report time range is
34 * from the earliest day with jobs to today ("Query for all dates" is
35 * ticked). If the user removes the tick the time range is from today - 3
36 * days to today. Currently, the input model is empty.
40 * @return link to the JSP query page
42 @RequestMapping(value = "/stat/jobs/query", method = RequestMethod.GET)
43 public String initFindForm(Map<String, Object> model) {
44 model.put("username", getPrincipalName());
45 Calendar loccal = Calendar.getInstance();
46 String date2 = loccal.get(Calendar.YEAR) + "/" + (loccal.get(Calendar.MONTH) + 1) + "/" + loccal.get(Calendar.DATE);
47 loccal.add(Calendar.DATE, -3);
48 String date1 = loccal.get(Calendar.YEAR) + "/" + (loccal.get(Calendar.MONTH) + 1) + "/" + loccal.get(Calendar.DATE);
49 model.put("date1", date1);
50 model.put("date2", date2);
51 return "query/JobStatistics";
55 * form a report page for daily job statistics.
60 * initial date for the report (if option is set, date2 = the
61 * earliest date with jobs in DB)
63 * the final date for the report (if option is set, date2 =
66 * defined whether the whole time range of jobs is reported (null
67 * means date1 and date2 are used)
68 * @return link to the report JSP page
70 @RequestMapping(value = "/stat/jobsdaily/results", method = RequestMethod.GET)
71 public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
72 @RequestParam("option") String option, Map<String, Object> model) {
73 model.put("username", getPrincipalName());
74 Calendar loccal = Calendar.getInstance();
75 final long startTime = System.currentTimeMillis();
76 DailyStatisticsReader reader = new DailyStatisticsReader();
77 if (option.equals("AllDates,off")) {
78 date1 = theEaerlistDate;
79 date2 = theCurrentDate;
82 // dates in string format
83 String trimmeddate1 = date1.replaceAll("\\s", "");
84 String trimmeddate2 = date2.replaceAll("\\s", "");
85 // dates in long format
86 long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD);
87 long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD);
88 String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2);
90 model.put("error", error);
91 model.put("date1", date1);
92 model.put("date2", date2);
93 return "query/JobStatistics";
96 if (longDate1 < CassandraReader.earliestDate())
97 longDate1 = CassandraReader.earliestDate();
98 if (longDate2 > loccal.getTimeInMillis())
99 longDate2 = loccal.getTimeInMillis();
101 date1 = DateFormatter.DateLongToString(longDate1, formaterYYMMDD);
102 date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD);
103 model.put("date1", date1);
104 model.put("date2", date2);
105 TotalJobsStatisticBean res = reader.query(longDate1, longDate2);
106 model.put("result", res);
107 Map<String, Total> results = res.getDateTotal();
108 String csvline = "\'Date\',\'Total\',\'OK\',\'Stopped\',\'Error\',\'Timeout\'%0A";
109 for (Map.Entry<String, Total> entry : results.entrySet()) {
110 csvline += "\'" + entry.getKey() + "\',\'" + entry.getValue().getTotal() + "\',\'" + entry.getValue().getTotalOK() + "\',\'"
111 + entry.getValue().getTotalStopped() + "\',\'" + entry.getValue().getTotalError() + "\',\'"
112 + entry.getValue().getTotalTimeOut() + "\'%0A";
114 model.put("csvfile", csvline);
115 model.put("ndays", res.getDateTotal().size());
116 final long endTime = System.currentTimeMillis();
117 model.put("timeExecution", (endTime - startTime));
118 model.put("option", option);
119 return "/reportJobStatistics";
123 * form a report page for job statistics for one day only.
128 * date for the report
131 * @return link to the report JSP page
133 @RequestMapping(value = "/stat/jobsoneday/results", method = RequestMethod.GET)
134 public String findJobsInOneDay(@RequestParam("date") String date, @RequestParam("status") String status, Map<String, Object> model)
135 throws ParseException {
136 model.put("username", getPrincipalName());
137 final long startTime = System.currentTimeMillis();
142 thetime = formaterYYMMDD.parse(date).getTime();
146 realdate = formaterDDMMYY.format(new Date(thetime));
148 } catch (ParseException e) {
150 thetime = formaterDDMMYY.parse(realdate).getTime();
153 if (null == JobStatus.getJobStatus(status)) {
154 return "support/Notimplemented";
157 DailyStatisticsReader reader = new DailyStatisticsReader();
158 // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
159 DateBean r = reader.readJobByDay(thetime, realdate, JobStatus.getJobStatus(status));
160 model.put("results", r);
162 model.put("njobs", r.getJobidAndSeq().size());
163 model.put("date", realdate);
164 model.put("status", status);
165 final long endTime = System.currentTimeMillis();
166 model.put("timeExecution", (endTime - startTime));
167 return "/reportJobStatisticsOneDay";