Merge branch 'DAO'
[proteocache.git] / server / compbio / statistic / CassandraRequester.java
index 0d2ffc0..ca59844 100755 (executable)
@@ -112,9 +112,11 @@ public class CassandraRequester {
                        query.add(db);
                }
 
+               /* ???? Very strange code...
                DataBase db = new DataBase();
                db.setTimeTotalExec(totalTime);
                query.add(db);
+               */
                return query;
        }
 
@@ -122,25 +124,21 @@ public class CassandraRequester {
         * query: total number of jobs for the period from date1 till date2
        */ 
        public TotalJobsStatisticBean countJobs(String date1, String date2) {
-       /*      if (null == date1) {
-                       date1 = "1970/1/1";
-               }
-               if (null == date2) {
-                       date1 = "2100/1/1";
-               }
-               if (!isThisDateValid(date1, formatYYMMDD) || !isThisDateValid(date2, formatYYMMDD)) {
-                       System.out.println("CassandraRequester.countJobs: wrong format for date1 " + date1 + "or date2 " + date2);
-                       return null;
-               }*/
+               /*
+                * if (null == date1) { date1 = "1970/1/1"; } if (null == date2) { date1
+                * = "2100/1/1"; } if (!isThisDateValid(date1, formatYYMMDD) ||
+                * !isThisDateValid(date2, formatYYMMDD)) { System.out.println(
+                * "CassandraRequester.countJobs: wrong format for date1 " + date1 +
+                * "or date2 " + date2); return null; }
+                */
                SetDateRange();
                long dateStart = DateParsing(date1, formatYYMMDD);
                long dateEnd = DateParsing(date2, formatYYMMDD);
-/*             if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd)
-                       return null;
-               if (dateStart < earlestDate)
-                       dateStart = earlestDate;
-               if (dateEnd > currentDate)
-                       dateStart = currentDate;*/
+               /*
+                * if (dateEnd < earlestDate || dateStart > currentDate || dateStart >
+                * dateEnd) return null; if (dateStart < earlestDate) dateStart =
+                * earlestDate; if (dateEnd > currentDate) dateStart = currentDate;
+                */
                Calendar start = Calendar.getInstance();
                start.setTime(new Date(dateStart));
                Calendar end = Calendar.getInstance();
@@ -174,7 +172,7 @@ public class CassandraRequester {
                long day = DateParsing(date, formatDDMMYY);
                if (day < earlestDate || day > currentDate)
                        return null;
-               
+
                if (status == JobStatus.OK) {
                        return db.ReadProteinData(day, date);
                }
@@ -200,21 +198,22 @@ public class CassandraRequester {
                }
                return result;
        }
-       
+
        /*
         * query: protein feature
         */
        public Map<String, String> readProteinsPrediction(String feature, int percent) {
-               Map<String, String> result = db.ReadProtein();;
+               Map<String, String> result = db.ReadProtein();
+               ;
                if (result == null)
                        return null;
                Map<String, String> query = new HashMap<String, String>();
                for (Map.Entry<String, String> entry : result.entrySet()) {
-                       String pred = entry.getValue();                 
-                       if (pred.replaceAll("[^"+feature+"]", "").length() > pred.length() * percent / 100 && (!entry.getKey().equals(""))) {
-                       //      if (!entry.getKey().equals(""))
-                                       query.put(entry.getKey(), pred);
-                       }       
+                       String pred = entry.getValue();
+                       if (pred.replaceAll("[^" + feature + "]", "").length() > pred.length() * percent / 100 && (!entry.getKey().equals(""))) {
+                               // if (!entry.getKey().equals(""))
+                               query.put(entry.getKey(), pred);
+                       }
                }
                return query;
        }
@@ -360,4 +359,22 @@ public class CassandraRequester {
                return earlestDate;
        }
 
+       /**
+        * prepares an example of either job id or IP for the DB
+        * 
+        * @param exampletype
+        *            defines which example you need (an existing job from the DB -
+        *            jobid, an IP - "ip")
+        * @return a string representation of the requested example, if the example
+        *         type is not known empty string is returned
+        */
+       public String getExample(String exampletype) {
+               if (exampletype.equals("jobid")) {
+                       return "jp_NzBOJKo";
+               } else if (exampletype.equals("ip")) {
+                       return "127.0.0.1";
+               }
+               return "";
+       }
+
 }