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
31 * DailyStatisticsController
33 public TotalJobsStatisticBean 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 TotalJobsStatisticBean query = new TotalJobsStatisticBean();
39 Total wholeTotal = new Total(0, 0, 0, 0, 0);
40 for (Date date = end.getTime(); !end.before(start); end.add(Calendar.DATE, -1), date = end.getTime()) {
41 ResultSet results = CassandraQuery("SELECT * FROM JobDateInfo WHERE jobday = " + date.getTime() + ";");
44 if (results.isExhausted())
46 Row therow = results.one();
47 Total res = new Total(therow.getLong("Total"), therow.getLong("TotalOK"), therow.getLong("TotalStopped"),
48 therow.getLong("TotalError"), therow.getLong("TotalTimeOut"));
49 if (!results.isExhausted()) {
50 Date dat = new Date(date.getTime());
51 log.warn("CassandraReader.ReadDateTable: date row for " + dat.toString() + " (" + date.getTime() + ") duplicated ");
53 query.setDateTotal(DateFormatter.DateLongToString(date.getTime(), DateFormatter.getFormatDDMMYY()), res);
54 wholeTotal.setTotal(res.getTotal() + wholeTotal.getTotal());
55 wholeTotal.setTotalOK(res.getTotalOK() + wholeTotal.getTotalOK());
56 wholeTotal.setTotalStopped(res.getTotalStopped() + wholeTotal.getTotalStopped());
57 wholeTotal.setTotalError(res.getTotalError() + wholeTotal.getTotalError());
58 wholeTotal.setTotalTimeOut(res.getTotalTimeOut() + wholeTotal.getTotalTimeOut());
60 query.setWholeTotal(wholeTotal);
65 * query: jobs and sequence at a date
68 * the date in long format
70 * the date in String format
74 * @return DateBean to the controller DailyStatisticsController
76 public DateBean readJobByDay(long day, String date, JobStatus status) {
77 DateBean res = new DateBean(date);
78 if (status == JobStatus.OK) {
79 ResultSet results = CassandraQuery("SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + day + ";");
80 if (results == null || results.isExhausted())
82 List<Row> rows = results.all();
84 res.setJobidAndSeq(r.getString("JobID"), r.getString("Protein"));
87 ResultSet results = CassandraQuery("SELECT JobID FROM FailLog WHERE jobtime = " + day + " and FinalStatus = '" + status.name()
89 if (results == null || results.isExhausted())
91 List<Row> rows = results.all();
93 String jobid = r.getString("JobID");
94 ResultSet results2 = CassandraQuery("SELECT Protein FROM ProteinLog WHERE JobID = '" + jobid + "';");
95 if (results2 == null || results2.isExhausted())
97 List<Row> jrows = results2.all();
98 if (1 == jrows.size()) {
99 String protein = jrows.get(0).getString("Protein");
100 res.setJobidAndSeq(jobid, protein);