create DateBean, UserBean, TotalBean
[proteocache.git] / server / compbio / statistic / CassandraRequester.java
index d82543a..c150d9d 100755 (executable)
@@ -9,12 +9,17 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import compbio.cassandra.DateBean;
 import compbio.cassandra.ProteinBean;
 import compbio.cassandra.CassandraNativeConnector;
 import compbio.cassandra.CassandraReader;
 import compbio.cassandra.DataBase;
 import compbio.cassandra.Pair;
-import compbio.cassandra.StructureJobLog;
+import compbio.cassandra.JobBean;
+import compbio.cassandra.Total;
+import compbio.cassandra.TotalByCounterBean;
+import compbio.cassandra.TotalJobsStatisticBean;
+import compbio.cassandra.UserBean;
 
 public class CassandraRequester {
        private CassandraReader db = new CassandraReader();
@@ -115,7 +120,7 @@ public class CassandraRequester {
        /*
         * query: total number of jobs  for the period from date1 till date2
         */
-       public List<DataBase> countJobs(String date1, String date2) {
+       public TotalJobsStatisticBean countJobs(String date1, String date2) {
                if (null == date1) {
                        date1 = "1970/1/1";
                }
@@ -140,30 +145,27 @@ public class CassandraRequester {
                start.setTime(new Date(dateStart));
                Calendar end = Calendar.getInstance();
                end.setTime(new Date(dateEnd));
-               query = new ArrayList<DataBase>();
+               TotalJobsStatisticBean query = new TotalJobsStatisticBean();
+               Total wholeTotal = new Total(0,0,0,0,0);
                for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
-                       List<Long> res = db.ReadDateTable(date.getTime());
+                       Total res = db.ReadDateTable(date.getTime());
                        if (res == null)
                                continue;
-                       DataBase bean = new DataBase();
-                       bean.setTotal((int)(long)res.get(0));
-                       bean.setTotalOK((int)(long)res.get(1));
-                       bean.setTotalStopped((int)(long)res.get(2));
-                       bean.setTotalError((int)(long)res.get(3));
-                       bean.setTotalTimeOut((int)(long)res.get(4));
-                       bean.setDate(DateFormat(date.getTime()));
-                       query.add(bean);
+                       query.setDateTotal(DateFormat(date.getTime()), res);
+                       wholeTotal.setTotal(res.getTotal() + wholeTotal.getTotal());
+                       wholeTotal.setTotalOK(res.getTotalOK() + wholeTotal.getTotalOK());
+                       wholeTotal.setTotalStopped(res.getTotalStopped() + wholeTotal.getTotalStopped());
+                       wholeTotal.setTotalError(res.getTotalError() + wholeTotal.getTotalError());
+                       wholeTotal.setTotalTimeOut(res.getTotalTimeOut() + wholeTotal.getTotalTimeOut());
                }
+               query.setWholeTotal(wholeTotal);
                return query;
        }
 
        /*
         * query: jobs and sequence at date
         */
-       public List<DataBase> readJobByDay (String date) {
-               if (null == date) {
-                       return null;
-               }
+       public DateBean readJobByDay (String date) {
                if (!isThisDateValid(date, formatDDMMYY)) {
                        System.out.println("CassandraRequester.readJobByDay: Wrong date format for " + date);
                        return null;
@@ -172,24 +174,13 @@ public class CassandraRequester {
                long day = DateParsing(date, formatDDMMYY);
                if (day < earlestDate || day > currentDate)
                        return null;    
-               List<Pair<String, String>>      res = db.ReadProteinData(day);
-               if (res == null)
-                       return null;
-               query = new ArrayList<DataBase>();
-               for (Pair<String, String> entry : res) {                
-                       DataBase bean = new DataBase();
-                       bean.setDate(date);
-                       bean.setId(entry.getElement0());
-                       bean.setProt(entry.getElement1());
-                       query.add(bean);
-               }
-               return query;
+               return db.ReadProteinData(day, date);
        }
 
 
        /* 
         * query: protein sequence
-        * */
+        **/
        public List<ProteinBean> readProteins(String protIn, String flag) {
                List<ProteinBean> result;
                if (flag.equals("whole")) 
@@ -211,14 +202,16 @@ public class CassandraRequester {
        /* 
         * query protein sequences with number of jobs
         */
-       public List<DataBase> readProteinByCounter(int minimalcounter) {
-               query = new ArrayList<DataBase>();
+       public List<TotalByCounterBean> readProteinByCounter(int minimalcounter) {              
+               List<TotalByCounterBean> query = new ArrayList<TotalByCounterBean>();
                Map<String, Integer> map = db.ReadProteinSequenceByCounter();
+               if (map == null)
+                       return null;
                for (Map.Entry<String, Integer> entry : map.entrySet()) {
-                       if (entry.getValue() > minimalcounter && entry.getKey().length() > 0) {
-                               DataBase bean = new DataBase();
-                               bean.setTotalId(entry.getValue());
-                               bean.setProt(entry.getKey());
+                       if (entry.getValue() > minimalcounter) {
+                               TotalByCounterBean bean = new TotalByCounterBean();
+                               bean.setTotaljobs(entry.getValue());
+                               bean.setName(entry.getKey());
                                query.add(bean);
                        }
                }
@@ -228,8 +221,8 @@ public class CassandraRequester {
        /* 
         * query ip with number of jobs
         */
-       public List<DataBase> readIpByCounter(Integer minimalcounter) {
-               query = new ArrayList<DataBase>();
+       public List<TotalByCounterBean> readIpByCounter(Integer minimalcounter) {
+               List<TotalByCounterBean> query = new ArrayList<TotalByCounterBean>();
                Map<String, Integer> map = db.ReadIpByCounter();
                if (minimalcounter == null)
                        minimalcounter = 0;
@@ -237,9 +230,9 @@ public class CassandraRequester {
                        return null;
                for (Map.Entry<String, Integer> entry : map.entrySet()) {
                        if (entry.getValue() > minimalcounter) {
-                               DataBase bean = new DataBase();
-                               bean.setTotalId(entry.getValue());
-                               bean.setIp(entry.getKey());
+                               TotalByCounterBean bean = new TotalByCounterBean();
+                               bean.setTotaljobs(entry.getValue());
+                               bean.setName(entry.getKey());
                                query.add(bean);
                        }
                }
@@ -248,35 +241,24 @@ public class CassandraRequester {
        /*
         * query jobs log info
         */
-       public DataBase readJobLog(String jobid) {
+       public JobBean readJobLog(String jobid) {
                if (jobid == null)
                        return null;
-               StructureJobLog res = db.ReadJobLog(jobid);
-               if (res == null)
-                       return null;
-               DataBase query = new DataBase();
-               query.setLogInfo(res);
-               return query;
+               return db.ReadJobLog(jobid);
        }
        
        
        /*
         * query jobs by ipStructureJobLog
         */
-       public List<DataBase> readIp(String ip) {
+       public UserBean readIp(String ip) {
                if (ip == null)
                        return null;
-               List<Pair<String, String>> res = db.ReadIpWithJobs(ip);
+               Map<String, String[]> res = db.ReadIpWithJobs(ip);
                if (res == null) 
                        return null;
-               query = new ArrayList<DataBase>();
-               for (Pair<String, String> entry : res) {
-                       DataBase bean = new DataBase();
-                       bean.setIp(ip);
-                       bean.setId(entry.getElement0());
-                       bean.setProt(entry.getElement1());
-                       query.add(bean);
-               }
+               UserBean query = new UserBean(ip);
+               query.setMainInfo(res);
                return query;
        }