X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=server%2Fcompbio%2Fstatistic%2FCassandraRequester.java;h=1e2d00b1bebd83a3a968ab755b24a5915e06f396;hb=58c9b97523e2273a316a947d977ca7ddd8b1356a;hp=f4c4c18fa37105fc947a86d0a3e9580efc866784;hpb=16c02499a4eadc9d54c88bdb4402403823a86bd2;p=proteocache.git diff --git a/server/compbio/statistic/CassandraRequester.java b/server/compbio/statistic/CassandraRequester.java index f4c4c18..1e2d00b 100755 --- a/server/compbio/statistic/CassandraRequester.java +++ b/server/compbio/statistic/CassandraRequester.java @@ -5,19 +5,25 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; -import java.util.Iterator; +import java.util.HashMap; import java.util.List; import java.util.Map; -import compbio.cassandra.AnnotatedProteinSequenceBean; +import compbio.beans.DateBean; +import compbio.beans.JobBean; +import compbio.beans.ProteinBean; +import compbio.beans.Total; +import compbio.beans.TotalByCounterBean; +import compbio.beans.TotalJobsStatisticBean; +import compbio.beans.UserBean; import compbio.cassandra.CassandraNativeConnector; -import compbio.cassandra.CassandraReader; +import compbio.cassandra.CassandraReaderOld; import compbio.cassandra.DataBase; -import compbio.cassandra.Pair; -import compbio.cassandra.StructureJobLog; +import compbio.engine.JobStatus; +import compbio.engine.Pair; public class CassandraRequester { - private CassandraReader db = new CassandraReader(); + private CassandraReaderOld db = new CassandraReaderOld(); private ArrayList query; private static long currentDate = 0; private static long earlestDate = 0; @@ -34,8 +40,8 @@ public class CassandraRequester { if (null == date2) { date1 = "2100/1/1"; } - if (!isThisDateValid(date1,formatYYMMDD) || !isThisDateValid(date2,formatYYMMDD)) { - System.out.println("Wrong date: point 3"); + if (!isThisDateValid(date1, formatYYMMDD) || !isThisDateValid(date2, formatYYMMDD)) { + System.out.println("CassandraRequester.extractExecutionTime: wrong format for date1 " + date1 + "or date2 " + date2); return null; } SetDateRange(); @@ -106,140 +112,135 @@ public class CassandraRequester { query.add(db); } - DataBase db = new DataBase(); - db.setTimeTotalExec(totalTime); - query.add(db); - System.out.println("StatisticsProt.readLength: total number of dates = " + query.size()); + /* + * ???? Very strange code... DataBase db = new DataBase(); + * db.setTimeTotalExec(totalTime); query.add(db); + */ return query; } - + /* - * query: total number of jobs for the period from date1 till date2 + * query: total number of jobs for the period from date1 till date2 */ - public List 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("Wrong date: point 3"); - return null; - } + 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; } + */ 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(); end.setTime(new Date(dateEnd)); - query = new ArrayList(); + 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 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()); } - System.out.println("StatisticsProt.readLength: total number of dates = " + query.size()); + query.setWholeTotal(wholeTotal); return query; } /* * query: jobs and sequence at date */ - public List readJobByDay (String date) { - System.out.println(date); - if (null == date) { - return null; - } + public DateBean readJobByDay(String date, JobStatus status) { if (!isThisDateValid(date, formatDDMMYY)) { - System.out.println("Wrong date: point 3"); + System.out.println("CassandraRequester.readJobByDay: Wrong date format for " + date); return null; } SetDateRange(); long day = DateParsing(date, formatDDMMYY); - System.out.println(day); if (day < earlestDate || day > currentDate) - return null; - List> res = db.ReadProteinData(day); - if (res == null) return null; - query = new ArrayList(); - for (Pair entry : res) { - DataBase bean = new DataBase(); - bean.setDate(date); - bean.setId(entry.getElement0()); - bean.setProt(entry.getElement1()); - query.add(bean); + + if (status == JobStatus.OK) { + return db.ReadProteinData(day, date); } - System.out.println("StatisticsProt.readLength: total number of dates = " + query.size()); - return query; + return db.ReadFailedJobs(day, date, status); } - - /* + /* * query: protein sequence - * */ - public List readProteins(String protIn, String flag) { - query = new ArrayList(); - List res; - if (flag.equals("whole")) - res = db.ReadWholeSequence(protIn); - else - res = db.ReadPartOfSequence(protIn); - if (res == null) + */ + public List readProteins(String protIn, String searchtype) { + List result; + if (searchtype.equals("whole")) + result = db.ReadWholeSequence(protIn); + else + result = db.ReadPartOfSequence(protIn); + if (result == null) return null; - for (AnnotatedProteinSequenceBean entry : res) { - DataBase db = new DataBase(); - db.setProt(entry.getSequence()); - db.setPredictions(entry); - db.setId(entry.getJobid()); - if (flag.equals("part")) { - db.setSubProt(CreateSubprot (entry.getSequence(), protIn)); + + if (searchtype.equals("partial")) { + for (ProteinBean entry : result) { + entry.setSubProt(CreateSubprot(entry.getSequence(), protIn)); + } + } + return result; + } + + /* + * query: protein feature + */ + + public Map readProteinsPrediction(String feature, int percent) { + Map results = db.ReadProtein(); + if (results == null) + return null; + Map query = new HashMap(); + for (Map.Entry entry : results.entrySet()) { + String prediction = entry.getValue(); + String protein = entry.getKey(); + if (prediction.replaceAll("[^" + feature + "]", "").length() > prediction.length() * percent / 100 && !protein.equals("")) { + query.put(protein, prediction); } - query.add(db); } return query; } - - /* + /* * query protein sequences with number of jobs */ - public List readProteinByCounter(int minimalcounter) { - query = new ArrayList(); + public List readProteinByCounter(int minimalcounter) { + List query = new ArrayList(); Map map = db.ReadProteinSequenceByCounter(); + if (map == null) + return null; for (Map.Entry 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); } } return query; } - - /* + + /* * query ip with number of jobs */ - public List readIpByCounter(Integer minimalcounter) { - query = new ArrayList(); + public List readIpByCounter(Integer minimalcounter) { + List query = new ArrayList(); Map map = db.ReadIpByCounter(); if (minimalcounter == null) minimalcounter = 0; @@ -247,57 +248,42 @@ public class CassandraRequester { return null; for (Map.Entry 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); } } return query; } + /* * 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 readIp(String ip) { + public UserBean readIp(String ip) { if (ip == null) return null; - List> res = db.ReadIpWithJobs(ip); - // System.out.println(res.size()); - if (res == null) + Map res = db.ReadIpWithJobs(ip); + if (res == null) return null; - query = new ArrayList(); - for (Pair entry : res) { - System.out.println("ip " + ip); - System.out.println("id " + entry.getElement0()); - DataBase bean = new DataBase(); - bean.setIp(ip); - bean.setId(entry.getElement0()); - bean.setProt(entry.getElement1()); - query.add(bean); - } - System.out.println(query.size()); + UserBean query = new UserBean(ip); + query.setMainInfo(res); return query; } - + /* * create list of parts of protein sequence; */ - private static List CreateSubprot (String protein, String subprot) { + private static List CreateSubprot(String protein, String subprot) { List sub = new ArrayList(); String subStr = protein; while (subStr.length() > 0 && subStr.contains(subprot)) { @@ -311,6 +297,7 @@ public class CassandraRequester { sub.add(subStr); return sub; } + /* * convert String date into long date (miliseconds since the epoch start) */ @@ -319,7 +306,7 @@ public class CassandraRequester { return 0; } long dateWorkSt = 0; - + try { dateWorkSt = formatter.parse(datInput).getTime(); } catch (ParseException e) { @@ -340,17 +327,16 @@ public class CassandraRequester { */ private static void SetDateRange() { Calendar cal = Calendar.getInstance(); - currentDate = DateParsing(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH), formatYYMMDD); + currentDate = DateParsing(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH), + formatYYMMDD); if (0 == earlestDate) { CassandraRequester cr = new CassandraRequester(); earlestDate = cr.earliestDate(); - System.out.println("Set earlest Date = " + earlestDate); } } public boolean isThisDateValid(String dateToValidate, SimpleDateFormat sdf) { if (dateToValidate == null || dateToValidate.equals("")) { - System.out.println("Undefined date"); return false; } try { @@ -371,5 +357,23 @@ public class CassandraRequester { earlestDate = CassandraNativeConnector.getEarliestDateInDB(); 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 ""; + } + }