fixed Execution time report
authorNatasha Sherstneva <n.shertneva@gmail.com>
Tue, 21 Jan 2014 14:08:38 +0000 (14:08 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Tue, 21 Jan 2014 14:08:38 +0000 (14:08 +0000)
conf/Proteocache.properties
datadb/compbio/beans/ExecutionTimeBean.java [new file with mode: 0644]
datadb/compbio/beans/TotalExecutionTime.java [new file with mode: 0644]
datadb/compbio/cassandra/CassandraNewTableWriter.java
datadb/compbio/cassandra/readers/ExecutionTimeReader.java [new file with mode: 0644]
server/compbio/controllers/JobController.java
webapp/view/reports/TimeExecution.jsp

index 6ce13ed..edb54ad 100644 (file)
@@ -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 (file)
index 0000000..1b2f85e
--- /dev/null
@@ -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<String, TotalExecutionTime> 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<String, TotalExecutionTime> dateTotal;
+               private TotalExecutionTime wholeTotal;
+
+               public ExecutionTimeBean() {
+                       this.dateTotal = new LinkedHashMap<String, TotalExecutionTime>();
+               }
+
+               public void setDateTotal(String dat, TotalExecutionTime tot) {
+                       if (this.dateTotal == null)
+                               dateTotal = new LinkedHashMap<String, TotalExecutionTime>();
+                       dateTotal.put(dat, tot);
+               }
+
+               public Map<String, TotalExecutionTime> 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 (file)
index 0000000..6de9d97
--- /dev/null
@@ -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;
+               }
+}
index 4ee10c8..b4e9746 100644 (file)
@@ -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<Row> 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 (file)
index 0000000..6bd17eb
--- /dev/null
@@ -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<Row> 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;                                                                                                                                   
+                       
+               }
+}
index 9987bd5..9fdc128 100644 (file)
@@ -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<String, Object> 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<DataBase> res = sp.extractExecutionTime(date1, date2);
+               ExecutionTimeBean res = reader.query(longDate1, longDate2);;
                model.put("result", res);
+               Map<String, TotalExecutionTime> 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<Integer> 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<String, TotalExecutionTime> 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";
index 2411b12..face3d7 100644 (file)
        </div>
        
        <div class="panel-body">
-               <c:set var="sum" value="0" />
-               <c:forEach items="${result}" var="res" varStatus="loop">
-                       <c:choose>
-                               <c:when test="${loop.last}">
-                                       <c:forEach items="${res.timeTotalExec}" var="total">
-                                               <c:set var="sum" value="${sum + total}" />
-                                       </c:forEach>
-                               </c:when>
-                       </c:choose>
-               </c:forEach>
-
-               <p>There are ${sum} jobs in total</p>
-
-               <table class="table table-striped table-hover table-bordered">
-                       <thead>
+               <c:choose>
+                       <c:when test="${result == null}">
+                               <p>No jobs for this period</p>
+                       </c:when>
+               <c:otherwise>
+                       <div class="table-responsive">
+                       <table class="table table-striped table-hover table-bordered">
+                               <thead>
                                <tr>
                                        <th style="text-align: center; width: 150px">Date</th>
                                        <th style="text-align: center; width: 150px">Total</th>
                                </tr>
                        </thead>
                        <tbody>
-                               <c:forEach items="${result}" var="res" varStatus="loop">
-                                       <c:choose>
-                                               <c:when test="${loop.last}">
-                                                       <tr style="font-weight: bolder;">
-                                                               <td style="text-align: right">Total numbers:</td>
-                                                               <c:set var="alldaytotal" value="0"/>
-                                                               <c:forEach items="${res.timeTotalExec}" var="total">
-                                                                       <c:set var="alldaytotal" value="${alldaytotal + total}"/>
-                                                               </c:forEach>
-                                                               <td style="text-align: right">${alldaytotal}</td>
-                                                               <c:forEach items="${res.timeTotalExec}" var="total">
-                                                                       <td style="text-align: right">${total}</td>
-                                                               </c:forEach>
-                                                       </tr>
-                                               </c:when>
-                                       </c:choose>
-                               </c:forEach>
+                               <tr style="font-weight: bolder;">
+                                                       <td style="text-align: center">Total:</td>
+                                                       <c:set var="total" value="${result.wholeTotal}"/>
+                                                       <td style="text-align: right">${total.total}</td>
+                                                       <td style="text-align: right">${total.total0_30s}</td>
+                                                       <td style="text-align: right">${total.total30_60s}</td>
+                                                       <td style="text-align: right">${total.total1_2m}</td>
+                                                       <td style="text-align: right">${total.total2_10m}</td>
+                                                       <td style="text-align: right">${total.total10m}</td>
+                               </tr>
 
-                               <c:forEach items="${result}" var="res" varStatus="loop">
-                                       <c:choose>
-                                               <c:when test="${not loop.last}">
+                               <c:forEach items="${result.dateTotal}" var="res">
                                                        <tr>
-                                                               <td style="text-align: center">${res.date}</td>
-                                                               <c:set var="daytotal" value="0"/>
-                                                               <c:forEach items="${res.timeRez}" var="time">
-                                                                       <c:set var="daytotal" value="${daytotal + time}"/>
-                                                               </c:forEach>
-                                                               <td style="text-align: right">${daytotal}</td>
-                                                               <c:forEach items="${res.timeRez}" var="time">
-                                                                       <td style="text-align: right">${time}</td>
-                                                               </c:forEach>
+                                                               <td style="text-align: center">${res.key}</td>
+                                                               <c:set var="value" value="${res.value}"/>
+                                                               <td style="text-align: right">${value.total}</td>
+                                                               <td style="text-align: right">${value.total0_30s}</td>
+                                                               <td style="text-align: right">${value.total30_60s}</td>
+                                                               <td style="text-align: right">${value.total1_2m}</td>
+                                                               <td style="text-align: right">${value.total2_10m}</td>
+                                                               <td style="text-align: right">${value.total10m}</td>
                                                        </tr>
-                                               </c:when>
-                                       </c:choose>
-                               </c:forEach>
+                                               </c:forEach>
                        </tbody>
                </table>
+               </div>
+               </c:otherwise>
+               </c:choose>
        </div>
        </div>