From 2d0c3af83988ff2a68d789efb4ccf2ff3c65a88a Mon Sep 17 00:00:00 2001 From: Natasha Sherstneva Date: Tue, 21 Jan 2014 14:08:38 +0000 Subject: [PATCH] fixed Execution time report --- conf/Proteocache.properties | 6 +- datadb/compbio/beans/ExecutionTimeBean.java | 40 ++++++++++ datadb/compbio/beans/TotalExecutionTime.java | 83 ++++++++++++++++++++ .../compbio/cassandra/CassandraNewTableWriter.java | 5 +- .../cassandra/readers/ExecutionTimeReader.java | 82 +++++++++++++++++++ server/compbio/controllers/JobController.java | 60 +++++++++----- webapp/view/reports/TimeExecution.jsp | 78 ++++++++---------- 7 files changed, 283 insertions(+), 71 deletions(-) create mode 100644 datadb/compbio/beans/ExecutionTimeBean.java create mode 100644 datadb/compbio/beans/TotalExecutionTime.java create mode 100644 datadb/compbio/cassandra/readers/ExecutionTimeReader.java diff --git a/conf/Proteocache.properties b/conf/Proteocache.properties index 6ce13ed..edb54ad 100644 --- a/conf/Proteocache.properties +++ b/conf/Proteocache.properties @@ -1,9 +1,9 @@ ################################################################################# # Cassandra host or IP # test server is 10.0.115.190 -#cassandra.host=localhost +cassandra.host=localhost #cassandra.host=gjb-www-1.cluster.lifesci.dundee.ac.uk -cassandra.host=c6100-1.cluster.lifesci.dundee.ac.uk +#cassandra.host=c6100-1.cluster.lifesci.dundee.ac.uk cassandra.newtables.update=false cassandra.version.update=false @@ -11,7 +11,7 @@ cassandra.version.update=false ################################################################################# # Jpred sources # real Jpred web-server -cassandra.jpred.web.update=true +cassandra.jpred.web.update=false cassandra.jpred.web.inidelay=0 cassandra.jpred.web.updaterate=30 diff --git a/datadb/compbio/beans/ExecutionTimeBean.java b/datadb/compbio/beans/ExecutionTimeBean.java new file mode 100644 index 0000000..1b2f85e --- /dev/null +++ b/datadb/compbio/beans/ExecutionTimeBean.java @@ -0,0 +1,40 @@ +package compbio.beans; + +import java.util.LinkedHashMap; +import java.util.Map; + + /** + * bean for a report of execution time statistics. + * + * @param dateTotal + * Map where String - a date, Total - total info for + * jobs with period of execution time + * @param wholeTotal + * total sum for each parameter from dateTotal + */ + public class ExecutionTimeBean { + private Map dateTotal; + private TotalExecutionTime wholeTotal; + + public ExecutionTimeBean() { + this.dateTotal = new LinkedHashMap(); + } + + public void setDateTotal(String dat, TotalExecutionTime tot) { + if (this.dateTotal == null) + dateTotal = new LinkedHashMap(); + dateTotal.put(dat, tot); + } + + public Map getDateTotal() { + return dateTotal; + } + + public void setWholeTotal(TotalExecutionTime tot) { + this.wholeTotal = tot; + } + + public TotalExecutionTime getWholeTotal() { + return wholeTotal; + } +} diff --git a/datadb/compbio/beans/TotalExecutionTime.java b/datadb/compbio/beans/TotalExecutionTime.java new file mode 100644 index 0000000..6de9d97 --- /dev/null +++ b/datadb/compbio/beans/TotalExecutionTime.java @@ -0,0 +1,83 @@ +package compbio.beans; + + /** + * bean is stored Total for a ExecutionTimeBean. + * + * @param total + * total number of jobs for a day + * @param total0_30s + * number of jobs with execution time 0 - 30 s for a date + * @param total30_60s + * number of jobs with execution time 30 - 60 s for a date + * @param total1_2m + * number of jobs with execution time 1-2 min for a date + * @param total2_10m + * number of jobs with execution time 2 - 10 min for a date + * @param total10m + * number of jobs with execution time more then 10 min for a date + */ + public class TotalExecutionTime { + private long total; + private long total0_30s; + private long total30_60s; + private long total1_2m; + private long total2_10m; + private long total10m; + + public TotalExecutionTime(long total, long total0_30s, long total30_60s, long total1_2m, long total2_10m, long total10m) { + this.total = total; + this.total0_30s = total0_30s; + this.total30_60s = total30_60s; + this.total1_2m = total1_2m; + this.total2_10m = total2_10m; + this.total10m = total10m; + } + + public void setTotal(long tot) { + this.total = tot; + } + + public long getTotal() { + return total; + } + + public void setTotal0_30s(long tot) { + this.total0_30s = tot; + } + + public long getTotal0_30s() { + return total0_30s; + } + + public void setTotal30_60s(long tot) { + this.total30_60s = tot; + } + + public long getTotal30_60s() { + return total30_60s; + } + + public void setTotal1_2m(long tot) { + this.total1_2m = tot; + } + + public long getTotal1_2m() { + return total1_2m; + } + + public void setTotal2_10m(long tot) { + this.total2_10m = tot; + } + + public long getTotal2_10m() { + return total2_10m; + } + + public void setTotal10m(long tot) { + this.total10m = tot; + } + + public long getTotal10m() { + return total10m; + } +} diff --git a/datadb/compbio/cassandra/CassandraNewTableWriter.java b/datadb/compbio/cassandra/CassandraNewTableWriter.java index 4ee10c8..b4e9746 100644 --- a/datadb/compbio/cassandra/CassandraNewTableWriter.java +++ b/datadb/compbio/cassandra/CassandraNewTableWriter.java @@ -59,7 +59,7 @@ public class CassandraNewTableWriter { Calendar endcal = Calendar.getInstance(); long endTime = endcal.getTime().getTime(); for (Date date = runnicCal.getTime(); date.getTime() < endTime; runnicCal.add(Calendar.DATE, 1), date = runnicCal.getTime()) { - try { + try { String com = "SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + date.getTime() + ";"; System.out.println(com); ResultSet results = session.execute(com); @@ -67,11 +67,12 @@ public class CassandraNewTableWriter { continue; List rows = results.all(); System.out.println(rows.size()); + int k=0; for (Row r : rows) { session.execute("UPDATE ProteinLog SET ProgramName = 'Jpred', ProgramVersion = '3.0.1' WHERE JobID = '" + r.getString("JobID") + "';"); session.execute("UPDATE JpredArchive SET ProgramName = 'Jpred', ProgramVersion = '3.0.1' WHERE JobID = '" - + r.getString("JobID") + "';"); + + r.getString("JobID") + "';"); } } catch (QueryExecutionException e) { e.printStackTrace(); diff --git a/datadb/compbio/cassandra/readers/ExecutionTimeReader.java b/datadb/compbio/cassandra/readers/ExecutionTimeReader.java new file mode 100644 index 0000000..6bd17eb --- /dev/null +++ b/datadb/compbio/cassandra/readers/ExecutionTimeReader.java @@ -0,0 +1,82 @@ +package compbio.cassandra.readers; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; + +import compbio.beans.ExecutionTimeBean; +import compbio.beans.Total; +import compbio.beans.TotalExecutionTime; +import compbio.beans.TotalJobsStatisticBean; +import compbio.cassandra.DataBase; +import compbio.cassandra.DateFormatter; +import compbio.cassandra.Pair; + +public class ExecutionTimeReader extends CassandraReader { + + public ExecutionTimeReader() { + super(); + } + + /** + * query: execution time statistics for the period from date1 till date2 + * + * @param dateStart + * the first date in the period + * @param dateEnd + * the last date in the period + * + * @return TotalJobsStatisticBean to the controller + * JobController + **/ + public ExecutionTimeBean query(long dateStart, long dateEnd) { + Calendar start = Calendar.getInstance(); + start.setTime(new Date(dateStart)); + Calendar end = Calendar.getInstance(); + end.setTime(new Date(dateEnd)); + ExecutionTimeBean query = new ExecutionTimeBean(); + TotalExecutionTime wholeTotal = new TotalExecutionTime(0, 0, 0, 0, 0, 0); + + for (Date date = end.getTime(); !end.before(start); end.add(Calendar.DATE, -1), date = end.getTime()) { + ResultSet results = CassandraQuery("SELECT ExecTime FROM ProteinData WHERE jobtime = " + date.getTime() + ";"); + if (results == null) + return null; + if (results.isExhausted()) + continue; + List rows = results.all(); + TotalExecutionTime currentTotal = new TotalExecutionTime(0, 0, 0, 0, 0, 0); + for (Row r : rows) { + long timeExec = r.getInt("ExecTime")/1000; + if (timeExec <= 30) + currentTotal.setTotal0_30s(currentTotal.getTotal0_30s() + 1); + else if (timeExec > 30 && timeExec <= 60) + currentTotal.setTotal30_60s(currentTotal.getTotal30_60s() + 1); + else if (timeExec > 60 && timeExec <= 120) + currentTotal.setTotal1_2m(currentTotal.getTotal1_2m() + 1); + else if (timeExec > 120 && timeExec <= 600) + currentTotal.setTotal2_10m(currentTotal.getTotal2_10m() + 1); + else + currentTotal.setTotal10m(currentTotal.getTotal10m() + 1); + + } + currentTotal.setTotal(currentTotal.getTotal0_30s() + currentTotal.getTotal30_60s() + currentTotal.getTotal1_2m() + + currentTotal.getTotal2_10m() + currentTotal.getTotal10m()); + query.setDateTotal(DateFormatter.DateLongToString(date.getTime(), DateFormatter.getFormatDDMMYY()), currentTotal); + wholeTotal.setTotal(currentTotal.getTotal() + wholeTotal.getTotal()); + wholeTotal.setTotal0_30s(currentTotal.getTotal0_30s() + wholeTotal.getTotal0_30s()); + wholeTotal.setTotal30_60s(currentTotal.getTotal30_60s() + wholeTotal.getTotal30_60s()); + wholeTotal.setTotal1_2m(currentTotal.getTotal1_2m() + wholeTotal.getTotal1_2m()); + wholeTotal.setTotal2_10m(currentTotal.getTotal2_10m() + wholeTotal.getTotal2_10m()); + wholeTotal.setTotal10m(currentTotal.getTotal10m() + wholeTotal.getTotal10m()); + } + query.setWholeTotal(wholeTotal); + return query; + + } +} diff --git a/server/compbio/controllers/JobController.java b/server/compbio/controllers/JobController.java index 9987bd5..9fdc128 100644 --- a/server/compbio/controllers/JobController.java +++ b/server/compbio/controllers/JobController.java @@ -16,7 +16,14 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import compbio.statistic.CassandraRequester; +import compbio.beans.ExecutionTimeBean; +import compbio.beans.Total; +import compbio.beans.TotalExecutionTime; +import compbio.beans.TotalJobsStatisticBean; import compbio.cassandra.DataBase; +import compbio.cassandra.DateFormatter; +import compbio.cassandra.readers.CassandraReader; +import compbio.cassandra.readers.ExecutionTimeReader; import compbio.cassandra.readers.JobReader; import compbio.engine.archive.ArchivedJob; @@ -81,36 +88,51 @@ public class JobController extends BasicController { @RequestParam(value = "option", required = false) String option, Map model) { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); - - CassandraRequester sp = new CassandraRequester(); + Calendar loccal = Calendar.getInstance(); + ExecutionTimeReader reader = new ExecutionTimeReader(); if (option.equals("AllDates,off")) { - Calendar cal = Calendar.getInstance(); - date1 = DateFormatYYMMDD(sp.earliestDate()); - date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); + date1 = theEaerlistDate; + date2 = theCurrentDate; + } + + // dates in string format + String trimmeddate1 = date1.replaceAll("\\s", ""); + String trimmeddate2 = date2.replaceAll("\\s", ""); + // dates in long format + long longDate1 = DateFormatter.DateParsing(date1, formaterYYMMDD); + long longDate2 = DateFormatter.DateParsing(date2, formaterYYMMDD); + String error = DateChecking(trimmeddate1, trimmeddate2, longDate1, longDate2); + if (error != null) { + model.put("error", error); + model.put("date1", date1); + model.put("date2", date2); + return "query/JobTimeExecution"; } + + if (longDate1 < CassandraReader.earliestDate()) + longDate1 = CassandraReader.earliestDate(); + if (longDate2 > loccal.getTimeInMillis()) + longDate2 = loccal.getTimeInMillis(); + + date1 = DateFormatter.DateLongToString(longDate1, formaterYYMMDD); + date2 = DateFormatter.DateLongToString(longDate2, formaterYYMMDD); model.put("date1", date1); model.put("date2", date2); model.put("option", option); - List res = sp.extractExecutionTime(date1, date2); + ExecutionTimeBean res = reader.query(longDate1, longDate2);; model.put("result", res); + Map results = res.getDateTotal(); String csvline = ""; - if (0 < res.size()) { + if (0 < res.getDateTotal().size()) { csvline = "\'Date\',\'Total\',\'0-30 sec\',\'30-60 sec\',\'1-2 min\',\'2-10 min\',\'more 10 min\'%0A"; - for (DataBase entry : res) { - List counts = entry.getTimeRez(); - int total = 0; - for (int i = 0; i < counts.size(); ++i) { - total += counts.get(i); - } - csvline += "\'" + entry.getDate() + "\',\'" + total; - for (int i = 0; i < counts.size(); ++i) { - csvline += "\',\'" + counts.get(i); - } - csvline += "\'%0A"; + for (Map.Entry entry : results.entrySet()) { + csvline += "\'" + entry.getKey() + "\',\'" + entry.getValue().getTotal() + "\',\'" + entry.getValue().getTotal0_30s() + "\',\'" + + entry.getValue().getTotal30_60s() + "\',\'" + entry.getValue().getTotal1_2m() + "\',\'" + + entry.getValue().getTotal2_10m() + "\',\'" + entry.getValue().getTotal10m() + "\'%0A"; } } model.put("csvfile", csvline); - model.put("ndays", res.size() - 1); + model.put("ndays", res.getDateTotal().size() - 1); final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); return "/reports/TimeExecution"; diff --git a/webapp/view/reports/TimeExecution.jsp b/webapp/view/reports/TimeExecution.jsp index 2411b12..face3d7 100644 --- a/webapp/view/reports/TimeExecution.jsp +++ b/webapp/view/reports/TimeExecution.jsp @@ -38,21 +38,14 @@
- - - - - - - - - - - -

There are ${sum} jobs in total

- - - + + +

No jobs for this period

+
+ +
+
+ @@ -64,43 +57,34 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - + - - - - - - - - - + + + + + + + + - - - +
Date Total
Total numbers:${alldaytotal}${total}
Total:${total.total}${total.total0_30s}${total.total30_60s}${total.total1_2m}${total.total2_10m}${total.total10m}
${res.date}${daytotal}${time}${res.key}${value.total}${value.total0_30s}${value.total30_60s}${value.total1_2m}${value.total2_10m}${value.total10m}
+
+ + -- 1.7.10.2