fixed Execution Time Statistics report
authorNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 23 Jan 2014 10:57:45 +0000 (10:57 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 23 Jan 2014 10:57:45 +0000 (10:57 +0000)
conf/Proteocache.properties
datadb/compbio/cassandra/CassandraNativeConnector.java
datadb/compbio/cassandra/readers/ExecutionTimeReader.java
engine/compbio/engine/ExecutionInterval.java [new file with mode: 0644]
server/compbio/controllers/DailyStatisticsController.java
server/compbio/controllers/JobController.java
webapp/view/reports/TimeExecution.jsp

index edb54ad..24307b7 100644 (file)
@@ -11,7 +11,7 @@ cassandra.version.update=false
 #################################################################################
 # Jpred sources
 # real Jpred web-server
-cassandra.jpred.web.update=false
+cassandra.jpred.web.update=true
 cassandra.jpred.web.inidelay=0
 cassandra.jpred.web.updaterate=30
 
index 3360ad1..bb807c1 100644 (file)
@@ -115,7 +115,6 @@ public class CassandraNativeConnector {
         */
        public static long getEarliestDateInDB() {
                String com = "SELECT * FROM MainParameters WHERE Name = 'EarliestJobDate';";
-               System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
 
                if (!results.isExhausted()) {
index 6bd17eb..bca4666 100644 (file)
@@ -1,8 +1,5 @@
 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;
@@ -10,11 +7,9 @@ import java.util.List;
 import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.Row;
 
+import compbio.beans.DateBean;
 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;
 
@@ -77,6 +72,32 @@ public class ExecutionTimeReader extends CassandraReader {
                        }
                        query.setWholeTotal(wholeTotal);
                        return query;                                                                                                                                   
-                       
                }
+                       
+                       /**
+                        * query: jobs and sequence at a date with current execution time interval
+                        * 
+                        * @param day
+                        *            the date in long format
+                        * @param date
+                        *            the date in String format
+                        * 
+                        * @param interval
+                        *           buttom and top bounds of the interval Pair<buttom, top>
+                        * @return DateBean to the controller JobController
+                        **/
+                       public DateBean readJobByDay(long day, String date, Pair<Integer,Integer> interval) {
+                               DateBean res = new DateBean(date);
+                               ResultSet results = CassandraQuery("SELECT * FROM ProteinData WHERE jobtime = " + day + ";");
+                               if (results == null || results.isExhausted())
+                                       return null;
+                               List<Row> rows = results.all();
+                               for (Row r : rows) {
+                                       if (interval.getElement0() <= r.getInt("ExecTime")/1000  && r.getInt("ExecTime")/1000 < interval.getElement1())
+                                                       res.setJobidAndSeq(r.getString("JobID"), r.getString("Protein"));
+                       
+                                       }                       
+                               return res;
+                       }       
+               
 }
diff --git a/engine/compbio/engine/ExecutionInterval.java b/engine/compbio/engine/ExecutionInterval.java
new file mode 100644 (file)
index 0000000..9b0bcee
--- /dev/null
@@ -0,0 +1,44 @@
+package compbio.engine;
+
+import compbio.cassandra.Pair;
+
+
+/**
+ * List of all possible execution time intervals for statistics
+ * 
+ */
+public enum ExecutionInterval {
+               ZERO_THIRTY_SEC, THIRTY_SIXTY_SEC, ONE_TWO_MIN, TWO_TEN_MIN, MORE_THEN_TEN_MIN;
+               
+               public static ExecutionInterval getExecutionInterval(String interval) {
+                       interval = interval.trim().toLowerCase();
+                       for (ExecutionInterval execInterval : ExecutionInterval.values()) {
+                               if (execInterval.toString().equalsIgnoreCase(interval)) {
+                                       return execInterval;
+                               }
+                       }
+                       return null;
+               }
+               
+               public static Pair<Integer, Integer> getBoundsInterval(String interval) {
+                       ExecutionInterval execInterval = getExecutionInterval(interval);
+                       if (execInterval != null)
+                               switch (execInterval) {
+                   case ZERO_THIRTY_SEC:
+                       return  Pair.createPair(0, 30);
+                   case THIRTY_SIXTY_SEC:
+                       return Pair.createPair(30, 60);
+                   case ONE_TWO_MIN:
+                       return Pair.createPair(60, 120);
+                   case TWO_TEN_MIN:
+                       return Pair.createPair(120, 600);
+                   case MORE_THEN_TEN_MIN:
+                       return Pair.createPair(120, Integer.MAX_VALUE);
+                   default:
+                       return null;
+                       }
+                       return null;
+               }
+
+               
+}
index 322f74e..5d183f9 100644 (file)
@@ -151,9 +151,9 @@ public class DailyStatisticsController extends BasicController {
                        thetime = formaterDDMMYY.parse(realdate).getTime();
                }
 
-               if (null == JobStatus.getJobStatus(status)) {
+               if (null == JobStatus.getJobStatus(status)) 
                        return "support/Notimplemented";
-               }
+
 
                DailyStatisticsReader reader = new DailyStatisticsReader();
                // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
index 9fdc128..ff834bd 100644 (file)
@@ -3,6 +3,7 @@ package compbio.controllers;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import compbio.statistic.CassandraRequester;
+import compbio.beans.DateBean;
 import compbio.beans.ExecutionTimeBean;
 import compbio.beans.Total;
 import compbio.beans.TotalExecutionTime;
@@ -23,8 +25,11 @@ import compbio.beans.TotalJobsStatisticBean;
 import compbio.cassandra.DataBase;
 import compbio.cassandra.DateFormatter;
 import compbio.cassandra.readers.CassandraReader;
+import compbio.cassandra.readers.DailyStatisticsReader;
 import compbio.cassandra.readers.ExecutionTimeReader;
 import compbio.cassandra.readers.JobReader;
+import compbio.engine.ExecutionInterval;
+import compbio.engine.JobStatus;
 import compbio.engine.archive.ArchivedJob;
 
 /**
@@ -137,6 +142,54 @@ public class JobController extends BasicController {
                model.put("timeExecution", (endTime - startTime));
                return "/reports/TimeExecution";
        }
+       
+       /**
+        * form a report page for job statistics for one day only.
+        * 
+        * @param model
+        *            MVC model object
+        * @param date
+        *            date for the report
+        * @param status
+        * 
+        * @return link to the report JSP page
+        */
+       @RequestMapping(value = "/stat/jobsoneday/executionTime", method = RequestMethod.GET)
+       public String findJobsInOneDay(@RequestParam("date") String date, @RequestParam("interval") String interval, Map<String, Object> model)
+                       throws ParseException {
+               model.put("username", getPrincipalName());
+               final long startTime = System.currentTimeMillis();
+
+               String realdate;
+               long thetime = 0;
+               try {
+                       thetime = formaterYYMMDD.parse(date).getTime();
+                       if (thetime < 0) {
+                               realdate = date;
+                       } else {
+                               realdate = formaterDDMMYY.format(new Date(thetime));
+                       }
+               } catch (ParseException e) {
+                       realdate = date;
+                       thetime = formaterDDMMYY.parse(realdate).getTime();
+               }
+
+               if (null == ExecutionInterval.getExecutionInterval(interval)) 
+                       return "support/Notimplemented";
+
+
+               ExecutionTimeReader reader = new ExecutionTimeReader();
+               // IMPORTANT: input should be suppied in the format: DD/MM/YYYY
+               DateBean r = reader.readJobByDay(thetime, realdate, ExecutionInterval.getBoundsInterval(interval));
+               model.put("results", r);
+               if (r != null)
+                       model.put("njobs", r.getJobidAndSeq().size());
+               model.put("date", realdate);
+               model.put("status", interval);
+               final long endTime = System.currentTimeMillis();
+               model.put("timeExecution", (endTime - startTime));
+               return "reports/JobStatisticsOneDay";
+       }
 
        /**
         * form a query page for a job. The servlet should no be visible to users at
index face3d7..dbf654c 100644 (file)
@@ -10,6 +10,7 @@
 <body>
        <div class="container">
                <jsp:include page="../fragments/mainmenu.jsp" />
+               <spring:url value="/stat/jobsoneday/executionTime" var="oneday_query" />
                <spring:url value="/stat/exectime/results?date1=${date1}&date2=${date2}&option=${option}" var="the_query" />
 
        <!-- reload and CSV buttons -->
                                                                <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>
+                                                               <td style="text-align: right">
+                                                                       <c:choose>
+                                                                               <c:when test="${value.total0_30s == 0}">0</c:when>
+                                                                               <c:otherwise><a href="${oneday_query}?date=${res.key}&interval=ZERO_THIRTY_SEC">${value.total0_30s}</a></c:otherwise>
+                                                                       </c:choose>
+                                                               </td>
+                                                               <td style="text-align: right">
+                                                                       <c:choose>
+                                                                               <c:when test="${value.total0_30s == 0}">0</c:when>
+                                                                               <c:otherwise><a href="${oneday_query}?date=${res.key}&interval=THIRTY_SIXTY_SEC">${value.total30_60s}</a></c:otherwise>
+                                                                       </c:choose>
+                                                               </td>
+                                                               <td style="text-align: right">
+                                                                       <c:choose>
+                                                                               <c:when test="${value.total0_30s == 0}">0</c:when>
+                                                                               <c:otherwise><a href="${oneday_query}?date=${res.key}&interval=ONE_TWO_MIN">${value.total1_2m}</a></c:otherwise>
+                                                                       </c:choose>
+                                                               </td>
+                                                               <td style="text-align: right">
+                                                                       <c:choose>
+                                                                               <c:when test="${value.total0_30s == 0}">0</c:when>
+                                                                               <c:otherwise><a href="${oneday_query}?date=${res.key}&interval=TWO_TEN_MIN">${value.total2_10m}</a></c:otherwise>
+                                                                       </c:choose>
+                                                               </td>
+                                                               <td style="text-align: right">
+                                                                       <c:choose>
+                                                                               <c:when test="${value.total0_30s == 0}">0</c:when>
+                                                                               <c:otherwise><a href="${oneday_query}?date=${res.key}&interval=MORE_THEN_TEN_MIN">${value.total10m}</a></c:otherwise>
+                                                                       </c:choose>
+                                                               </td>
                                                        </tr>
                                                </c:forEach>
                        </tbody>