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.Total;
12 import compbio.beans.TotalJobsStatisticBean;
13 import compbio.cassandra.DateFormatter;
14 import compbio.engine.JobStatus;
16 public class DailyStatisticsReader extends CassandraReader {
18 public DailyStatisticsReader() {
23 * query: total number of jobs 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 DailyStatisticsController
32 public TotalJobsStatisticBean query(long dateStart, long dateEnd) {
33 Calendar start = Calendar.getInstance();
34 start.setTime(new Date(dateStart));
35 Calendar end = Calendar.getInstance();
36 end.setTime(new Date(dateEnd));
37 TotalJobsStatisticBean query = new TotalJobsStatisticBean();
38 Total wholeTotal = new Total(0, 0, 0, 0, 0);
39 for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
40 ResultSet results = CassandraQuery("SELECT * FROM JobDateInfo WHERE jobday = " + date.getTime() + ";");
43 if (results.isExhausted())
45 Row therow = results.one();
46 Total res = new Total(therow.getLong("Total"), therow.getLong("TotalOK"), therow.getLong("TotalStopped"),
47 therow.getLong("TotalError"), therow.getLong("TotalTimeOut"));
48 if (!results.isExhausted()) {
49 Date dat = new Date(date.getTime());
50 log.warn("CassandraReader.ReadDateTable: date row for " + dat.toString() + " (" + date.getTime() + ") duplicated ");
52 query.setDateTotal(DateFormatter.DateLongToString(date.getTime(), DateFormatter.getFormatDDMMYY()), res);
53 wholeTotal.setTotal(res.getTotal() + wholeTotal.getTotal());
54 wholeTotal.setTotalOK(res.getTotalOK() + wholeTotal.getTotalOK());
55 wholeTotal.setTotalStopped(res.getTotalStopped() + wholeTotal.getTotalStopped());
56 wholeTotal.setTotalError(res.getTotalError() + wholeTotal.getTotalError());
57 wholeTotal.setTotalTimeOut(res.getTotalTimeOut() + wholeTotal.getTotalTimeOut());
59 query.setWholeTotal(wholeTotal);
64 * query: jobs and sequence at a date
67 * the date in long format
69 * the date in String format
73 * @return DateBean to the controller DailyStatisticsController
75 public DateBean readJobByDay(long day, String date, JobStatus status) {
76 DateBean res = new DateBean(date);
77 if (status == JobStatus.OK) {
78 ResultSet results = CassandraQuery("SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + day + ";");
79 if (results == null || results.isExhausted())
81 List<Row> rows = results.all();
83 res.setJobidAndSeq(r.getString("JobID"), r.getString("Protein"));
87 ResultSet results = CassandraQuery("SELECT JobID FROM FailLog WHERE jobtime = " + day + " and FinalStatus = '" + status.name() + "';");
88 if (results == null || results.isExhausted())
90 List<Row> rows = results.all();
92 String jobid = r.getString("JobID");
93 ResultSet results2 = CassandraQuery("SELECT Protein FROM ProteinLog WHERE JobID = '" + jobid + "';");
94 if (results2 == null || results2.isExhausted())
96 List<Row> jrows = results2.all();
97 if (1 == jrows.size()) {
98 String protein = jrows.get(0).getString("Protein");
99 res.setJobidAndSeq(jobid, protein);