X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=datadb%2Fcompbio%2Fcassandra%2FCassandraReader.java;h=69f7c088f639a4029552f3ef16499bfe348bfe9b;hb=574c70838a48dd41cfadda11a493b04f02de5604;hp=cb2492e1c33aa32006255eb02efaa50ba6a380fc;hpb=4458e44cf92e699159ee1257b1bea6300a9abebe;p=proteocache.git diff --git a/datadb/compbio/cassandra/CassandraReader.java b/datadb/compbio/cassandra/CassandraReader.java index cb2492e..69f7c08 100644 --- a/datadb/compbio/cassandra/CassandraReader.java +++ b/datadb/compbio/cassandra/CassandraReader.java @@ -53,7 +53,7 @@ public class CassandraReader { /* * getting data from the db */ - public List> 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 rows = results.all(); System.out.println("Query time is " + (queryTime - startTime) + " msec"); - List> res = new ArrayList>(); + DateBean res = new DateBean(date); int c = 0; for (Row r : rows) { - Pair pair = new Pair(r.getString("JobID"), r.getString("Protein")); - res.add(pair); + res.setJobidAndSeq(r.getString("JobID"), r.getString("Protein")); ++c; } final long endTime = System.currentTimeMillis(); @@ -77,17 +76,13 @@ public class CassandraReader { /* * getting data from the db JobDateInfo */ - public List 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 res = new ArrayList(); - 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 "); @@ -98,7 +93,7 @@ public class CassandraReader { /* * getting whole protein sequence from the db ProteinRow */ - public List ReadWholeSequence(String queryProtein) { + public List ReadWholeSequence(String queryProtein) { final long startTime = System.currentTimeMillis(); String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';"; System.out.println("Command: " + com); @@ -107,16 +102,48 @@ public class CassandraReader { return null; final long queryTime = System.currentTimeMillis(); List 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 res = new ArrayList(); + List res = new ArrayList(); + 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)); - 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 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 rows = results.all(); + Map res = new HashMap(); + 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; @@ -125,7 +152,7 @@ public class CassandraReader { /* * getting part of protein sequence from the db ProteinRow */ - public List ReadPartOfSequence(String queryProtein) { + public List ReadPartOfSequence(String queryProtein) { final long startTime = System.currentTimeMillis(); String com = "SELECT * FROM ProteinRow;"; System.out.println("Command: " + com); @@ -136,13 +163,13 @@ public class CassandraReader { List rows = results.all(); System.out.println("Query time is " + (queryTime - startTime) + " msec"); System.out.println(" rows analysed, " + rows.size()); - List res = new ArrayList(); + List res = new ArrayList(); 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; } @@ -182,9 +209,38 @@ public class CassandraReader { } /* + * getting ip by counter + */ + public Map 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 rows = results.all(); + System.out.println("Query time is " + (queryTime - startTime) + " msec"); + System.out.println(" rows analysed, " + rows.size()); + Map res = new HashMap(); + 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); @@ -199,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();