From 8a0caa40d0fa288a0ad23f6af2aab1b0de0d50cd Mon Sep 17 00:00:00 2001 From: Natasha Sherstneva Date: Mon, 25 Nov 2013 10:41:17 +0000 Subject: [PATCH 1/1] PROT-7 fixed reports jobs by a day --- WEB-INF/web.xml | 22 +++++ conf/Proteocache.properties | 2 +- datadb/compbio/cassandra/CassandraReader.java | 30 ++++++- .../cassandra/StructureProteinPrediction.java | 10 +++ server/compbio/statistic/CassandraRequester.java | 85 ++++++++++++++------ website/ReportJobsByDate.jsp | 4 +- 6 files changed, 124 insertions(+), 29 deletions(-) diff --git a/WEB-INF/web.xml b/WEB-INF/web.xml index 3f4654f..1c53caf 100644 --- a/WEB-INF/web.xml +++ b/WEB-INF/web.xml @@ -47,11 +47,33 @@ ServletDeleteRecord compbio.listeners.ServletDeleteRecord + + + + ServletByJobSequence + ServletByJobSequence + compbio.listeners.ServletByJobSequence + + + + + ServletJobsByDay + ServletJobsByDay + compbio.listeners.ServletJobsByDay + ServletDeleteRecord /ServletDeleteRecord + + ServletByJobSequence + /ServletByJobSequence + + + ServletJobsByDay + /ServletJobsByDay + diff --git a/conf/Proteocache.properties b/conf/Proteocache.properties index a376e8c..5ab8858 100644 --- a/conf/Proteocache.properties +++ b/conf/Proteocache.properties @@ -3,7 +3,7 @@ # test server is 10.0.115.190 #cassandra.host=localhost #cassandra.host=10.31.0.97 -cassandra.host=gjb-www-1.cluster.lifesci.dundee.ac.uk +cassandra.host=localhost cassandra.newtables.update=false diff --git a/datadb/compbio/cassandra/CassandraReader.java b/datadb/compbio/cassandra/CassandraReader.java index 250c705..b527738 100644 --- a/datadb/compbio/cassandra/CassandraReader.java +++ b/datadb/compbio/cassandra/CassandraReader.java @@ -51,6 +51,30 @@ public class CassandraReader { } /* + * getting data from the db + */ + public List> ReadProteinData(long day) { + final long startTime = System.currentTimeMillis(); + String com = "SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + day + ";"; + 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"); + List> res = new ArrayList>(); + int c = 0; + for (Row r : rows) { + Pair pair = new Pair(r.getString("JobID"), r.getString("Protein")); + res.add(pair); + ++c; + } + final long endTime = System.currentTimeMillis(); + System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec"); + return res; + } + /* * getting data from the db JobDateInfo */ public List ReadDateTable(long queryDate) { @@ -89,6 +113,10 @@ public class CassandraReader { for (Row r : rows) { StructureProteinPrediction structure = new StructureProteinPrediction(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); ++c; } @@ -157,7 +185,7 @@ public class CassandraReader { } /* - * getting protein sequences by counter + * getting log info for jobid */ public StructureJobLog ReadJobLog(String jobid) { final long startTime = System.currentTimeMillis(); diff --git a/datadb/compbio/cassandra/StructureProteinPrediction.java b/datadb/compbio/cassandra/StructureProteinPrediction.java index 936a67a..0e392bf 100644 --- a/datadb/compbio/cassandra/StructureProteinPrediction.java +++ b/datadb/compbio/cassandra/StructureProteinPrediction.java @@ -5,6 +5,7 @@ import java.util.Map; public class StructureProteinPrediction { private String sequence; private String jobid; + private String jnetpred; private Map prediction; public StructureProteinPrediction (String seq, String id, Map pred) { @@ -13,6 +14,15 @@ public class StructureProteinPrediction { this.prediction = pred; } + + public void setJnetpred (String jnetpred) { + this.jnetpred = jnetpred; + } + + public String getJnetpred () { + return jnetpred; + } + public String getSequence () { return sequence; } diff --git a/server/compbio/statistic/CassandraRequester.java b/server/compbio/statistic/CassandraRequester.java index ec74c6f..afba67b 100755 --- a/server/compbio/statistic/CassandraRequester.java +++ b/server/compbio/statistic/CassandraRequester.java @@ -21,6 +21,8 @@ public class CassandraRequester { private ArrayList query; private static long currentDate = 0; private static long earlestDate = 0; + private final static SimpleDateFormat formatYYMMDD = new SimpleDateFormat("yyyy/MM/dd"); + private final static SimpleDateFormat formatDDMMYY = new SimpleDateFormat("dd/MM/yyyy"); /* * query: execution time for the period from date1 till date2 @@ -32,14 +34,14 @@ public class CassandraRequester { if (null == date2) { date1 = "2100/1/1"; } - if (!isThisDateValid(date1) || !isThisDateValid(date2)) { + if (!isThisDateValid(date1,formatYYMMDD) || !isThisDateValid(date2,formatYYMMDD)) { System.out.println("Wrong date: point 3"); return null; } SetDateRange(); int nbins = 5; - long dateStart = DateParsing(date1); - long dateEnd = DateParsing(date2); + long dateStart = DateParsing(date1, formatYYMMDD); + long dateEnd = DateParsing(date2, formatYYMMDD); if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd) return null; if (dateStart < earlestDate) @@ -121,13 +123,13 @@ public class CassandraRequester { if (null == date2) { date1 = "2100/1/1"; } - if (!isThisDateValid(date1) || !isThisDateValid(date2)) { + if (!isThisDateValid(date1, formatYYMMDD) || !isThisDateValid(date2, formatYYMMDD)) { System.out.println("Wrong date: point 3"); return null; } SetDateRange(); - long dateStart = DateParsing(date1); - long dateEnd = DateParsing(date2); + long dateStart = DateParsing(date1, formatYYMMDD); + long dateEnd = DateParsing(date2, formatYYMMDD); if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd) return null; if (dateStart < earlestDate) @@ -156,31 +158,62 @@ public class CassandraRequester { System.out.println("StatisticsProt.readLength: total number of dates = " + query.size()); return query; } + + /* + * query: jobs and sequence at date + */ + public List readJobByDay (String date) { + System.out.println(date); + if (null == date) { + return null; + } + if (!isThisDateValid(date, formatDDMMYY)) { + System.out.println("Wrong date: point 3"); + return null; + } + SetDateRange(); + long day = DateParsing(date, formatDDMMYY); + System.out.println(day); + if (day < earlestDate || day > currentDate) + return null; + List> res = db.ReadProteinData(day); + if (res == null) + return null; + query = new ArrayList(); + for (Pair entry : res) { + DataBase bean = new DataBase(); + bean.setDate(date); + bean.setId(entry.getElement0()); + bean.setProt(entry.getElement1()); + query.add(bean); + } + System.out.println("StatisticsProt.readLength: total number of dates = " + query.size()); + return query; + } /* * query: protein sequence * */ public List readProteins(String protIn, String flag) { + if (protIn == null) + return null; + System.out.println(protIn.length()); query = new ArrayList(); List res; if (flag.equals("whole")) res = db.ReadWholeSequence(protIn); else - res = db.ReadPartOfSequence(protIn); + res = (protIn.length() > 0) ? db.ReadPartOfSequence(protIn) : null; if (res == null) return null; for (StructureProteinPrediction entry : res) { - Map pred = entry.getPrediction(); - Iterator it = pred.entrySet().iterator(); - while (it.hasNext()) { - DataBase db = new DataBase(); - db.setProt(entry.getSequence()); - Map.Entry pairs = (Map.Entry)it.next(); - db.setId(entry.getJobid()); - db.setJpred(pairs.getValue().toString()); + DataBase bean = new DataBase(); + bean.setProt(entry.getSequence()); + bean.setId(entry.getJobid()); + bean.setJpred(entry.getJnetpred()); if (flag.equals("part")) - db.setSubProt(CreateSubprot (entry.getSequence(), protIn)); - query.add(db); - } + bean.setSubProt(CreateSubprot (entry.getSequence(), protIn)); + query.add(bean); + } return query; } @@ -206,13 +239,16 @@ public class CassandraRequester { * query jobs log info */ public DataBase readJobLog(String jobid) { - // query = new ArrayList(); + if (jobid == null) + return null; StructureJobLog res = db.ReadJobLog(jobid); + if (res == null) + return null; DataBase query = new DataBase(); query.setLogInfo(res); - // query.setres); return query; } + /* * create list of parts of protein sequence; */ @@ -233,12 +269,12 @@ public class CassandraRequester { /* * convert String date into long date (miliseconds since the epoch start) */ - private static long DateParsing(String datInput) { + private static long DateParsing(String datInput, SimpleDateFormat formatter) { if (datInput == null) { return 0; } long dateWorkSt = 0; - SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); + try { dateWorkSt = formatter.parse(datInput).getTime(); } catch (ParseException e) { @@ -259,7 +295,7 @@ public class CassandraRequester { */ private static void SetDateRange() { Calendar cal = Calendar.getInstance(); - currentDate = DateParsing(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH)); + currentDate = DateParsing(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH), formatYYMMDD); if (0 == earlestDate) { CassandraRequester cr = new CassandraRequester(); earlestDate = cr.earliestDate(); @@ -267,12 +303,11 @@ public class CassandraRequester { } } - public boolean isThisDateValid(String dateToValidate) { + public boolean isThisDateValid(String dateToValidate, SimpleDateFormat sdf) { if (dateToValidate == null || dateToValidate.equals("")) { System.out.println("Undefined date"); return false; } - SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); try { // if not valid, this will throw ParseException sdf.setLenient(false); diff --git a/website/ReportJobsByDate.jsp b/website/ReportJobsByDate.jsp index f531446..8ced12c 100644 --- a/website/ReportJobsByDate.jsp +++ b/website/ReportJobsByDate.jsp @@ -69,10 +69,10 @@ - + ${res.date} ${res.total} - ${res.totalOK} + ${res.totalOK} ${res.totalStopped} ${res.totalError} ${res.totalTimeOut} -- 1.7.10.2