1 package compbio.cassandra.readers;
3 import java.util.Calendar;
7 import com.datastax.driver.core.ResultSet;
8 import com.datastax.driver.core.Row;
10 import compbio.beans.DateBean;
11 import compbio.beans.ExecutionTimeBean;
12 import compbio.beans.TotalExecutionTime;
13 import compbio.cassandra.DateFormatter;
14 import compbio.engine.Pair;
16 public class ExecutionTimeReader extends CassandraReader {
18 public ExecutionTimeReader() {
23 * query: execution time statistics for the period from date1 till date2
26 * the first date in the period
28 * the last date in the period
30 * @return TotalJobsStatisticBean to the controller
33 public ExecutionTimeBean query(long dateStart, long dateEnd) {
34 Calendar start = Calendar.getInstance();
35 start.setTime(new Date(dateStart));
36 Calendar end = Calendar.getInstance();
37 end.setTime(new Date(dateEnd));
38 ExecutionTimeBean query = new ExecutionTimeBean();
39 TotalExecutionTime wholeTotal = new TotalExecutionTime(0, 0, 0, 0, 0, 0);
41 for (Date date = end.getTime(); !end.before(start); end.add(Calendar.DATE, -1), date = end.getTime()) {
42 ResultSet results = CassandraQuery("SELECT ExecTime FROM ProteinData WHERE jobtime = " + date.getTime() + ";");
45 if (results.isExhausted())
47 List<Row> rows = results.all();
48 TotalExecutionTime currentTotal = new TotalExecutionTime(0, 0, 0, 0, 0, 0);
50 long timeExec = r.getInt("ExecTime")/1000;
52 currentTotal.setTotal0_30s(currentTotal.getTotal0_30s() + 1);
53 else if (timeExec > 30 && timeExec <= 60)
54 currentTotal.setTotal30_60s(currentTotal.getTotal30_60s() + 1);
55 else if (timeExec > 60 && timeExec <= 120)
56 currentTotal.setTotal1_2m(currentTotal.getTotal1_2m() + 1);
57 else if (timeExec > 120 && timeExec <= 600)
58 currentTotal.setTotal2_10m(currentTotal.getTotal2_10m() + 1);
60 currentTotal.setTotal10m(currentTotal.getTotal10m() + 1);
63 currentTotal.setTotal(currentTotal.getTotal0_30s() + currentTotal.getTotal30_60s() + currentTotal.getTotal1_2m() +
64 currentTotal.getTotal2_10m() + currentTotal.getTotal10m());
65 query.setDateTotal(DateFormatter.DateLongToString(date.getTime(), DateFormatter.getFormatDDMMYY()), currentTotal);
66 wholeTotal.setTotal(currentTotal.getTotal() + wholeTotal.getTotal());
67 wholeTotal.setTotal0_30s(currentTotal.getTotal0_30s() + wholeTotal.getTotal0_30s());
68 wholeTotal.setTotal30_60s(currentTotal.getTotal30_60s() + wholeTotal.getTotal30_60s());
69 wholeTotal.setTotal1_2m(currentTotal.getTotal1_2m() + wholeTotal.getTotal1_2m());
70 wholeTotal.setTotal2_10m(currentTotal.getTotal2_10m() + wholeTotal.getTotal2_10m());
71 wholeTotal.setTotal10m(currentTotal.getTotal10m() + wholeTotal.getTotal10m());
73 query.setWholeTotal(wholeTotal);
78 * query: jobs and sequence at a date with current execution time interval
81 * the date in long format
83 * the date in String format
86 * buttom and top bounds of the interval Pair<buttom, top>
87 * @return DateBean to the controller JobController
89 public DateBean readJobByDay(long day, String date, Pair<Integer,Integer> interval) {
90 DateBean res = new DateBean(date);
91 ResultSet results = CassandraQuery("SELECT * FROM ProteinData WHERE jobtime = " + day + ";");
92 if (results == null || results.isExhausted())
94 List<Row> rows = results.all();
96 if (interval.getElement0() <= r.getInt("ExecTime")/1000 && r.getInt("ExecTime")/1000 < interval.getElement1())
97 res.setJobidAndSeq(r.getString("JobID"), r.getString("Protein"));