create DateBean, UserBean, TotalBean
[proteocache.git] / datadb / compbio / cassandra / CassandraReader.java
index 6e3587b..69f7c08 100644 (file)
@@ -53,7 +53,7 @@ public class CassandraReader {
        /*
         * getting data from the db
         */
-       public List<Pair<String, String>> ReadProteinData(long day) {
+       public DateBean ReadProteinData(long day, String date) {
                final long startTime = System.currentTimeMillis();
                String com = "SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + day + ";";
                System.out.println("Command: " + com);
@@ -63,11 +63,10 @@ public class CassandraReader {
                final long queryTime = System.currentTimeMillis();
                List<Row> rows = results.all();
                System.out.println("Query time is " + (queryTime - startTime) + " msec");
-               List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
+               DateBean res = new DateBean(date);
                int c = 0;
                for (Row r : rows) {
-                       Pair<String, String> pair = new Pair<String, String>(r.getString("JobID"), r.getString("Protein"));
-                       res.add(pair);
+                       res.setJobidAndSeq(r.getString("JobID"), r.getString("Protein"));
                        ++c;
                }
                final long endTime = System.currentTimeMillis();
@@ -77,27 +76,24 @@ public class CassandraReader {
        /*
         * getting data from the db JobDateInfo
         */
-       public List<Long> ReadDateTable(long queryDate) {
+       public Total ReadDateTable(long queryDate) {
                ResultSet results = session.execute("SELECT * FROM JobDateInfo WHERE jobday = " + queryDate + ";");
                if (results.isExhausted())
                        return null;
                Row therow = results.one();
-               List<Long> res = new ArrayList<Long>();
-               res.add(therow.getLong("Total"));
-               res.add(therow.getLong("TotalOK"));
-               res.add(therow.getLong("TotalStopped"));
-               res.add(therow.getLong("TotalError"));
-               res.add(therow.getLong("TotalTimeOut"));
+               Total res = new Total(therow.getLong("Total"), therow.getLong("TotalOK"), therow.getLong("TotalStopped"), 
+                               therow.getLong("TotalError"), therow.getLong("TotalTimeOut"));
                if (!results.isExhausted()) {
                        Date date = new Date (queryDate);
                        log.warn("CassandraReader.ReadDateTable: date row for " + date.toString () + " ("+ queryDate + ") duplicated ");
                }
                return res;
        }
+
        /*
         * getting whole protein sequence from the db ProteinRow
         */
-       public List<AnnotatedProteinSequenceBean> ReadWholeSequence(String queryProtein) {
+       public List<ProteinBean> ReadWholeSequence(String queryProtein) {
                final long startTime = System.currentTimeMillis();
                String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';";
                System.out.println("Command: " + com);
@@ -106,20 +102,48 @@ public class CassandraReader {
                        return null;
                final long queryTime = System.currentTimeMillis();
                List<Row> rows = results.all();
+               System.out.println("first size : " + rows.size());
                System.out.println("Query time is " + (queryTime - startTime) + " msec");
                System.out.println(" rows analysed,  " + rows.size());
-               List<AnnotatedProteinSequenceBean> res = new ArrayList<AnnotatedProteinSequenceBean>();
+               List<ProteinBean> res = new ArrayList<ProteinBean>();
+               ProteinBean structure = new ProteinBean(queryProtein, rows.get(0).getMap(
+                               "Predictions", String.class, String.class));
+               System.out.println("second size : " + rows.size());
                int c = 0;
                for (Row r : rows) {
-                       AnnotatedProteinSequenceBean structure = new AnnotatedProteinSequenceBean(queryProtein, r.getString("JobID"), r.getMap(
-                                       "Predictions", String.class, String.class));
-                       if (structure.getPrediction().containsKey("jnetpred"))
-                               structure.setJnetpred(structure.getPrediction().get("jnetpred"));
-                       else
-                               structure.setJnetpred("");
-                       res.add(structure);
+                       structure.setJobid(r.getString("JobID"));                       
                        ++c;
                }
+               res.add(structure);
+               final long endTime = System.currentTimeMillis();
+               System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+
+       
+       /*
+        * getting jobs by ip
+        */
+       public Map<String, String[]> ReadIpWithJobs(String ip) {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT JobID, Protein, FinalStatus, DataBegin FROM ProteinLog WHERE ip = '" + ip + "';";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               Map<String, String[]> res = new HashMap<String, String[]>();
+               System.out.println("Query time is " + (queryTime - startTime) + " msec");
+               System.out.println(" rows analysed,  " + rows.size());
+               int c = 0;
+               for (Row r : rows) {
+                       if (r.getString("FinalStatus").equals("OK")) { 
+                               String date = r.getString("DataBegin");
+                               res.put(r.getString("JobID"), new String[] {date.substring(0, date.indexOf(":")), r.getString("Protein")});
+                               ++c;
+                       }
+               }
                final long endTime = System.currentTimeMillis();
                System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
                return res;
@@ -128,7 +152,7 @@ public class CassandraReader {
        /*
         * getting part of protein sequence from the db ProteinRow
         */
-       public List<AnnotatedProteinSequenceBean> ReadPartOfSequence(String queryProtein) {
+       public List<ProteinBean> ReadPartOfSequence(String queryProtein) {
                final long startTime = System.currentTimeMillis();
                String com = "SELECT * FROM ProteinRow;";
                System.out.println("Command: " + com);
@@ -139,13 +163,13 @@ public class CassandraReader {
                List<Row> rows = results.all();
                System.out.println("Query time is " + (queryTime - startTime) + " msec");
                System.out.println(" rows analysed,  " + rows.size());
-               List<AnnotatedProteinSequenceBean> res = new ArrayList<AnnotatedProteinSequenceBean>();
+               List<ProteinBean> res = new ArrayList<ProteinBean>();
                int c = 0;
                for (Row r : rows) {
                        String prot = r.getString("Protein");
                        if (prot.matches("(.*)" + queryProtein + "(.*)")) {
-                               AnnotatedProteinSequenceBean structure = new AnnotatedProteinSequenceBean(prot, r.getString("JobID"), r.getMap("Predictions",
-                                               String.class, String.class));
+                               ProteinBean structure = new ProteinBean(prot,  r.getMap("Predictions", String.class, String.class));
+                               structure.setJobid(r.getString("JobID"));
                                res.add(structure);
                                ++c;
                        }
@@ -185,9 +209,38 @@ public class CassandraReader {
        }
 
        /*
+        * getting ip by counter
+        */
+       public Map<String, Integer> ReadIpByCounter() {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT JobID, ip FROM ProteinLog;";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               System.out.println("Query time is " + (queryTime - startTime) + " msec");
+               System.out.println(" rows analysed,  " + rows.size());
+               Map<String, Integer> res = new HashMap<String, Integer>();
+               int c = 0;
+               for (Row r : rows) {
+                       String ip = r.getString("ip");
+                       String id = r.getString("JobID");
+                       if (res.containsKey(ip))
+                               res.put(ip, res.get(ip) + 1);
+                       else
+                               res.put(ip, 1);
+               }
+               final long endTime = System.currentTimeMillis();
+               System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+
+       /*
         * getting log info for jobid
         */
-       public StructureJobLog ReadJobLog(String jobid) {
+       public JobBean ReadJobLog(String jobid) {
                final long startTime = System.currentTimeMillis();
                String com = "SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';";
                System.out.println("Command: " + com);
@@ -202,7 +255,7 @@ public class CassandraReader {
                if (results1.isExhausted())
                        return null;
                Row row1 = results1.one();
-               StructureJobLog res = new StructureJobLog(row.getString("Protein"), row.getString("JobID"), row.getString("DataBegin"),
+               JobBean res = new JobBean(row.getString("Protein"), row.getString("JobID"), row.getString("DataBegin"),
                                row.getString("DataEnd"), row.getString("ip"), row1.getMap("Predictions", String.class, String.class));
                System.out.println("Query time is " + (queryTime - startTime) + " msec");
                final long endTime = System.currentTimeMillis();