1 package compbio.cassandra.readers;
3 import java.util.ArrayList;
4 import java.util.HashMap;
8 import com.datastax.driver.core.ResultSet;
9 import com.datastax.driver.core.Row;
11 import compbio.beans.TotalByCounterBean;
13 public class ReaderByCounter extends CassandraReader {
15 public ReaderByCounter() {
20 * query protein sequences with number of jobs
22 * @param minimalcounter
24 * @return List<TotalByCounterBean> to the controller SequenceController
27 public List<TotalByCounterBean> readProteinByCounter(int minimalcounter) {
28 ResultSet results = CassandraQuery("SELECT Protein, JobID FROM ProteinRow;");
29 return QueryByCounter(results, "Protein", minimalcounter);
33 * query ip with number of jobs
35 * @param minimalcounter
37 * @return List<TotalByCounterBean> to the controller IPDataController
40 public List<TotalByCounterBean> readIpByCounter(Integer minimalcounter) {
41 ResultSet results = CassandraQuery("SELECT JobID, ip FROM ProteinLog;");
42 return QueryByCounter(results, "ip", minimalcounter);
46 * query number of jobs by counter and parameter: ip or protein
49 * cassandra query result
50 * @param counterParameter
51 * parameter for a query: ip or proteint
52 * @param minimalcounter
54 * @return List<TotalByCounterBean>
57 public List<TotalByCounterBean> QueryByCounter(ResultSet results, String counterParameter, int minimalcounter) {
58 List<TotalByCounterBean> query = new ArrayList<TotalByCounterBean>();
59 if (results.isExhausted())
61 List<Row> rows = results.all();
62 Map<String, Integer> res = new HashMap<String, Integer>();
64 String parameter = r.getString(counterParameter);
65 if (res.containsKey(parameter))
66 res.put(parameter, res.get(parameter) + 1);
68 res.put(parameter, 1);
70 for (Map.Entry<String, Integer> entry : res.entrySet()) {
71 if (entry.getValue() > minimalcounter) {
72 TotalByCounterBean bean = new TotalByCounterBean();
73 bean.setTotaljobs(entry.getValue());
74 bean.setName(entry.getKey());