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;
16 import compbio.cassandra.DataBase;
17 import compbio.statistic.CassandraRequester;
18 import compbio.statistic.StatisticsProt;
21 * @author Alexander Sherstnev
22 * @author Natasha Sherstneva
25 public class DailyStatisticsController {
27 @RequestMapping(value = "/stat", method = RequestMethod.GET)
28 public String initFindForm(Map<String, Object> model) {
29 Calendar cal = Calendar.getInstance();
30 String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
31 cal.add(Calendar.DATE, -3);
32 String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
34 model.put("date1", date1);
35 model.put("date2", date2);
37 return "queryJobStatistics";
40 @RequestMapping(value = "/stat/query", method = RequestMethod.GET)
41 public String findJobsInPeriod(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
42 @RequestParam("option") String option, Map<String, Object> model) {
43 final long startTime = System.currentTimeMillis();
45 CassandraRequester cr = new CassandraRequester();
46 if (option.equals("AllDates,off")) {
47 Calendar cal = Calendar.getInstance();
48 date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate());
49 date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
51 model.put("date1", date1);
52 model.put("date2", date2);
53 List<DataBase> res = cr.countJobs(date1, date2);
54 model.put("result", res);
55 model.put("ndays", res.size());
56 final long endTime = System.currentTimeMillis();
57 model.put("timeExecution", (endTime - startTime));
58 model.put("option", option);
59 return "/reportJobStatistics";
62 @RequestMapping(value = "/stat/oneday", method = RequestMethod.GET)
63 public String findJobsInOneDay(@RequestParam("date") String date, Map<String, Object> model) throws ParseException {
64 final long startTime = System.currentTimeMillis();
67 final SimpleDateFormat formaterDDMMYY = new SimpleDateFormat("dd/MM/yyyy");
68 final SimpleDateFormat formaterYYMMDD = new SimpleDateFormat("yyyy/MM/dd");
70 long thetime = formaterYYMMDD.parse(date).getTime();
74 realdate = formaterDDMMYY.format(new Date(thetime));
76 } catch (ParseException e) {
80 CassandraRequester cr = new CassandraRequester();
81 // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
82 List<DataBase> r = cr.readJobByDay(realdate);
83 model.put("results", r);
84 model.put("njobs", r.size());
85 model.put("date", realdate);
86 final long endTime = System.currentTimeMillis();
87 model.put("timeExecution", (endTime - startTime));
88 return "/reportJobStatisticsOneDay";