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;
17 import compbio.cassandra.readers.CassandraReader;
18 import compbio.cassandra.readers.DailyStatisticsReader;
19 import compbio.cassandra.readers.ProteoDAO;
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
65 * (null 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 DailyStatisticsReader reader = new DailyStatisticsReader();
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 = reader.query(longDate1, longDate2);
104 model.put("result", res);
105 model.put("ndays", res.getDateTotal().size());
106 final long endTime = System.currentTimeMillis();
107 model.put("timeExecution", (endTime - startTime));
108 model.put("option", option);
109 return "/reportJobStatistics";
113 * form a report page for job statistics for one day only.
118 * date for the report
121 * @return link to the report JSP page
123 @RequestMapping(value = "/stat/jobsoneday/results", method = RequestMethod.GET)
124 public String findJobsInOneDay(@RequestParam("date") String date, @RequestParam("status") String status, Map<String, Object> model)
125 throws ParseException {
126 model.put("username", getPrincipalName());
127 final long startTime = System.currentTimeMillis();
132 thetime = formaterYYMMDD.parse(date).getTime();
136 realdate = formaterDDMMYY.format(new Date(thetime));
138 } catch (ParseException e) {
140 thetime = formaterDDMMYY.parse(realdate).getTime();
143 if (null == JobStatus.getJobStatus(status)) {
144 return "support/Notimplemented";
147 DailyStatisticsReader reader = new DailyStatisticsReader();
148 // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
149 DateBean r = reader.readJobByDay(thetime, realdate, JobStatus.getJobStatus(status));
150 model.put("results", r);
152 model.put("njobs", r.getJobidAndSeq().size());
153 model.put("date", realdate);
154 model.put("status", status);
155 final long endTime = System.currentTimeMillis();
156 model.put("timeExecution", (endTime - startTime));
157 return "/reportJobStatisticsOneDay";