Merge branch 'master' into PROT-9-webservice
[proteocache.git] / datadb / compbio / cassandra / CassandraReaderOld.java
index f29bc9f..f483dc1 100644 (file)
@@ -12,7 +12,12 @@ import com.datastax.driver.core.Row;
 import com.datastax.driver.core.Session;
 import com.datastax.driver.core.ResultSet;
 
+import compbio.beans.DateBean;
+import compbio.beans.JobBean;
+import compbio.beans.ProteinBean;
+import compbio.beans.Total;
 import compbio.engine.JobStatus;
+import compbio.engine.Pair;
 
 public class CassandraReaderOld {
        private Session session;
@@ -119,7 +124,7 @@ public class CassandraReaderOld {
                String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';";
                System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
-               if (results.isExhausted())
+               if (results.isExhausted()) 
                        return null;
                final long queryTime = System.currentTimeMillis();
                List<Row> rows = results.all();
@@ -202,36 +207,34 @@ public class CassandraReaderOld {
         * getting protein sequence from the db ProteinRow
         */
        public Map<String, String> ReadProtein() {
-               final long startTime = System.currentTimeMillis();
+               //final long startTime = System.currentTimeMillis();
                String com = "SELECT * FROM ProteinRow;";
                System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
                if (results.isExhausted())
                        return null;
-               final long queryTime = System.currentTimeMillis();
+               //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, String> res = new HashMap<String, String>();
-               int c = 0;
+               Map<String, String> output = new HashMap<String, String>();
                for (Row r : rows) {
-                       String prot = r.getString("Protein");
+                       String protein = r.getString("Protein");
                        String prediction = findJnetpred(r.getMap("Predictions", String.class, String.class));
-                       if (prot != null || prediction != null) 
-                               res.put(prot, prediction);
+                       if (protein != null && prediction != null) {
+                               output.put(protein, prediction);
+                       }
                }
-               final long endTime = System.currentTimeMillis();
-               System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
-               return res;
+               //final long endTime = System.currentTimeMillis();
+               return output;
        }
 
-       private String findJnetpred (Map<String,String> pred) {
+       private String findJnetpred(Map<String, String> pred) {
                if (pred != null) {
-                       if (pred.containsKey("jnetpred")) 
+                       if (pred.containsKey("jnetpred"))
                                return pred.get("jnetpred");
                }
                return null;
        }
+
        /*
         * getting protein sequences by counter
         */
@@ -250,7 +253,6 @@ public class CassandraReaderOld {
                int c = 0;
                for (Row r : rows) {
                        String protein = r.getString("Protein");
-                       String id = r.getString("JobID");
                        if (res.containsKey(protein))
                                res.put(protein, res.get(protein) + 1);
                        else
@@ -279,7 +281,6 @@ public class CassandraReaderOld {
                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
@@ -310,6 +311,12 @@ public class CassandraReaderOld {
                Row row1 = results1.one();
                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));
+               String program = row.getString("ProgramName");
+               String version = row.getString("ProgramVersion");
+               if (null != program && null != version) {
+                       res.setProgramName(program);
+                       res.setProgramVersion(version);
+               }
                System.out.println("Query time is " + (queryTime - startTime) + " msec");
                final long endTime = System.currentTimeMillis();
                System.out.println(" rows analysed, execution time is " + (endTime - startTime) + " msec");