Add comments and make Time execution report more granular
authorSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Wed, 30 Oct 2013 09:17:34 +0000 (09:17 +0000)
committerSasha Sherstnev <a.sherstnev@dundee.ac.uk>
Wed, 30 Oct 2013 09:17:34 +0000 (09:17 +0000)
server/compbio/statistic/StatisticsProt.java
website/ReportLength.jsp

index 4ee2917..c0150b7 100755 (executable)
@@ -23,15 +23,16 @@ import compbio.cassandra.CassandraCreate;
 import compbio.cassandra.DataBase;
 
 public class StatisticsProt {
-//     private final static long MILLISECONDS_PER_DAY = 1000L * 60 * 60 * 24;
        private CassandraCreate cc = new CassandraCreate();
        private ArrayList<DataBase> query;
        private static long currentDate = 0;
        private static long earlestDate = 0;
 
-       /* query: the period from date1 till date2 */
+       /* 
+        * query: the period from date1 till date2
+        * */
        public List<DataBase> readDetails(String date1, String date2) {
-       
+
                if (!isThisDateValid(date1) || !isThisDateValid(date2)) {
                        System.out.println("Wrong date: point 1");
                        return null;
@@ -39,8 +40,7 @@ public class StatisticsProt {
                SetDateRange();
                long dateStart = DateParsing(date1);
                long dateEnd = DateParsing(date2);
-               if ((dateStart < earlestDate && dateEnd < earlestDate) || (dateStart > currentDate && dateEnd > currentDate)
-                               || dateStart > dateEnd)
+               if ((dateStart < earlestDate && dateEnd < earlestDate) || (dateStart > currentDate && dateEnd > currentDate) || dateStart > dateEnd)
                        return null;
                if (dateStart < earlestDate)
                        dateStart = earlestDate;
@@ -71,7 +71,6 @@ public class StatisticsProt {
                        } else {
                                System.out.println("no data");
                        }
-               //      dateStart += MILLISECONDS_PER_DAY;
                }
                System.out.println("StatisticsProt.readLength: total number of dates = " + query.size());
                return query;
@@ -79,17 +78,17 @@ public class StatisticsProt {
 
        /*
         * query: execution time for the period from date1 till date2
-        */
+        * */
        public List<DataBase> readLength(String date1, String date2) {
                if (!isThisDateValid(date1) || !isThisDateValid(date2)) {
                        System.out.println("Wrong date: point 3");
                        return null;
                }
                SetDateRange();
+               int nbins = 5;
                long dateStart = DateParsing(date1);
                long dateEnd = DateParsing(date2);
-               if ((dateStart < earlestDate && dateEnd < earlestDate) || (dateStart > currentDate && dateEnd > currentDate)
-                               || dateStart > dateEnd)
+               if ((dateStart < earlestDate && dateEnd < earlestDate) || (dateStart > currentDate && dateEnd > currentDate) || dateStart > dateEnd)
                        return null;
                if (dateStart < earlestDate)
                        dateStart = earlestDate;
@@ -104,7 +103,7 @@ public class StatisticsProt {
                end.setTime(new Date(dateEnd));
                query = new ArrayList<DataBase>();
                List<Integer> totalTime = new ArrayList<Integer>();
-               for (int i = 0; i < 4; i++)
+               for (int i = 0; i < nbins; i++)
                        totalTime.add(i, 0);
                for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
                        List<Integer> timeResult = new ArrayList<Integer>();
@@ -117,29 +116,31 @@ public class StatisticsProt {
                        List<HColumn<String, String>> col = columnSlice.get().getColumns();
                        if (!col.isEmpty()) {
                                Iterator<HColumn<String, String>> itCol = col.iterator();
-                               for (int i = 0; i < 4; i++)
+                               for (int i = 0; i < nbins; i++)
                                        timeResult.add(i, 0);
+                               // split all jobs into nbins bins
                                while (itCol.hasNext()) {
                                        String id = itCol.next().getName();
                                        long lenResult = CountID(id);
-                                       if (lenResult <= 30) 
+                                       if (lenResult <= 30)
                                                timeResult.set(0, timeResult.get(0) + 1);
                                        else if (lenResult > 30 && lenResult <= 60)
                                                timeResult.set(1, timeResult.get(1) + 1);
                                        else if (lenResult > 60 && lenResult <= 120)
                                                timeResult.set(2, timeResult.get(2) + 1);
-                                       else {
+                                       else if (lenResult > 120 && lenResult <= 600)
                                                timeResult.set(3, timeResult.get(3) + 1);
+                                       else {
+                                               timeResult.set(4, timeResult.get(4) + 1);
                                        }
                                }
-                               for (int i = 0; i < 4; i++)
+                               for (int i = 0; i < nbins; i++)
                                        totalTime.set(i, totalTime.get(i) + timeResult.get(i));
                                DataBase db = new DataBase();
                                db.setTimeRez(timeResult);
                                db.setDate(DateFormat(date.getTime()));
                                query.add(db);
                        }
-       //              dateStart += MILLISECONDS_PER_DAY;
                }
                DataBase db = new DataBase();
                db.setTimeTotalExec(totalTime);
@@ -148,7 +149,9 @@ public class StatisticsProt {
                return query;
        }
 
-       /* query: protein sequence */
+       /* 
+        * query: protein sequence
+        * */
        public List<DataBase> readProteins(String protIn) {
                query = new ArrayList<DataBase>();
                SliceQuery<String, String, String> result = HFactory.createSliceQuery(cc.GetKeyspace(), StringSerializer.get(),
@@ -172,7 +175,9 @@ public class StatisticsProt {
                return query;
        }
 
-       // query by a protein sequence
+       /* 
+        * query by a protein sequence
+        * */
        public List<DataBase> readProtID(int counter) {
                query = new ArrayList<DataBase>();
                int row_count = 100000000;
@@ -211,7 +216,9 @@ public class StatisticsProt {
                return query;
        }
 
-       // query by a part of sequence
+       /* 
+        * query by a part of sequence
+        * */
        public List<DataBase> readPart(String protIn) {
                int row_count = 10000;
                query = new ArrayList<DataBase>();
@@ -262,7 +269,9 @@ public class StatisticsProt {
                return query;
        }
 
-       // convert String to Date
+       /* 
+        * convert String date into long date (miliseconds since the epoch start)
+        */
        private static long DateParsing(String datInput) {
                if (datInput == null) {
                        return 0;
@@ -277,7 +286,9 @@ public class StatisticsProt {
                return dateWorkSt;
        }
 
-       // convert String to Date
+       /*
+        * convert String date:time into long date:time (miliseconds since the epoch start)
+        */
        private static long TimeConvert(String datInput) {
                long dateWorkSt = 0;
                if (datInput == null) {
@@ -300,9 +311,7 @@ public class StatisticsProt {
        }
 
        /*
-        * private static String DateFormat1(long inDate) { SimpleDateFormat
-        * datformat = new SimpleDateFormat("yyyy/MM/dd:hh:mm:ss"); String
-        * dateString = datformat.format(new Date(inDate)); return dateString; }
+        * convert ???
         */
        public static String DateFormatYYMMDD(long indate) {
                SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
@@ -310,6 +319,9 @@ public class StatisticsProt {
                return dateString;
        }
 
+       /*
+        * ???
+        */
        public long CountID(String id) {
                SliceQuery<String, String, String> sliceQuery = HFactory.createSliceQuery(cc.GetKeyspace(), StringSerializer.get(),
                                StringSerializer.get(), StringSerializer.get());
@@ -323,6 +335,11 @@ public class StatisticsProt {
                return (datEndLong - datBeginLong) / 1000;
        }
 
+       /*
+        * set earlest date and current dates. 
+        * earlestDate is static and should be set at the 1st call
+        * currentDate should be re-calculated every time
+        */
        private static void SetDateRange() {
                if (0 == earlestDate) {
                        StatisticsProt sp = new StatisticsProt();
@@ -350,7 +367,9 @@ public class StatisticsProt {
                return true;
        }
 
-       // find the earliest date
+       /*
+        * find the earliest date in the database
+        */
        public long earliestDate() {
                ArrayList<Long> dateSort = new ArrayList<Long>();
                int row_count = 10000;
index ed85c88..cd4249d 100644 (file)
@@ -20,7 +20,8 @@
 <th style="text-align: centre;  width: 150px">less then 30 s</th>
 <th style="text-align: centre;  width: 150px">30 s - 60 s</th>
 <th style="text-align: centre;  width: 150px">1 min - 2 min</th>
-<th style="text-align: centre;  width: 150px">more then 2min</th>
+<th style="text-align: centre;  width: 150px">2 min - 10 min</th>
+<th style="text-align: centre;  width: 150px">more then 10 min</th>
 </tr>
 </thead>
 <tbody>