1 package compbio.controllers;
3 import java.text.ParseException;
4 import java.text.SimpleDateFormat;
5 import java.util.Calendar;
10 import org.springframework.stereotype.Controller;
11 import org.springframework.web.bind.annotation.RequestMapping;
12 import org.springframework.web.bind.annotation.RequestMethod;
13 import org.springframework.web.bind.annotation.RequestParam;
15 import compbio.cassandra.DataBase;
16 import compbio.cassandra.DateBean;
17 import compbio.cassandra.TotalJobsStatisticBean;
18 import compbio.statistic.CassandraRequester;
19 import compbio.statistic.StatisticsProt;
22 * @author Alexander Sherstnev
23 * @author Natasha Sherstneva
26 public class DailyStatisticsController {
28 @RequestMapping(value = "/stat", method = RequestMethod.GET)
29 public String initFindForm(Map<String, Object> model) {
30 Calendar cal = Calendar.getInstance();
31 String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
32 cal.add(Calendar.DATE, -3);
33 String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
35 model.put("date1", date1);
36 model.put("date2", date2);
38 return "queryJobStatistics";
41 @RequestMapping(value = "/stat/query", method = RequestMethod.GET)
42 public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
43 @RequestParam("option") String option, Map<String, Object> model) {
44 final long startTime = System.currentTimeMillis();
46 CassandraRequester cr = new CassandraRequester();
47 if (option.equals("AllDates,off")) {
48 Calendar cal = Calendar.getInstance();
49 date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate());
50 date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
52 model.put("date1", date1);
53 model.put("date2", date2);
54 TotalJobsStatisticBean res = cr.countJobs(date1, date2);
55 model.put("result", res);
56 model.put("ndays", res.getDateTotal().size());
57 final long endTime = System.currentTimeMillis();
58 model.put("timeExecution", (endTime - startTime));
59 model.put("option", option);
60 return "/reportJobStatistics";
63 @RequestMapping(value = "/stat/oneday", method = RequestMethod.GET)
64 public String findJobsInOneDay(@RequestParam("date") String date, Map<String, Object> model) throws ParseException {
65 final long startTime = System.currentTimeMillis();
68 final SimpleDateFormat formaterDDMMYY = new SimpleDateFormat("dd/MM/yyyy");
69 final SimpleDateFormat formaterYYMMDD = new SimpleDateFormat("yyyy/MM/dd");
71 long thetime = formaterYYMMDD.parse(date).getTime();
75 realdate = formaterDDMMYY.format(new Date(thetime));
77 } catch (ParseException e) {
81 CassandraRequester cr = new CassandraRequester();
82 // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
83 DateBean r = cr.readJobByDay(realdate);
84 model.put("results", r);
86 model.put("njobs", r.getJobidAndSeq().size());
87 model.put("date", realdate);
88 final long endTime = System.currentTimeMillis();
89 model.put("timeExecution", (endTime - startTime));
90 return "/reportJobStatisticsOneDay";