From 0e1f92db0e4043bfa93417481274b6461cdb09cd Mon Sep 17 00:00:00 2001 From: Sasha Sherstnev Date: Thu, 19 Dec 2013 14:08:24 +0000 Subject: [PATCH] Fix problems with the servlet based codes. The last revision in the branch. --- datadb/compbio/cassandra/DataBase.java | 163 ++++++++++++++++++++ .../controllers/DailyStatisticsController.java | 13 +- server/compbio/listeners/ServletJobsByDate.java | 20 ++- server/compbio/listeners/ServletTimeExecution.java | 13 +- server/compbio/statistic/CassandraRequester.java | 13 +- 5 files changed, 206 insertions(+), 16 deletions(-) create mode 100644 datadb/compbio/cassandra/DataBase.java diff --git a/datadb/compbio/cassandra/DataBase.java b/datadb/compbio/cassandra/DataBase.java new file mode 100644 index 0000000..57063ec --- /dev/null +++ b/datadb/compbio/cassandra/DataBase.java @@ -0,0 +1,163 @@ +package compbio.cassandra; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; + +public class DataBase { + private String date; + private int total; // total number of jobs + private int totalOK; // number of jobs with execution status OK + private int totalStopped; // number of jobs with execution status STOPPED + private int totalError; // number of jobs with execution status Jpred ERROR + private int totalTimeOut; // number of jobs with execution status TIMEOUT + private int totalJobs; + private int totalId; // total jobs for current protein sequence + private String id; + private String ip; + private String prot; // protein sequence + private String jpred; + private List timeRez; + private List timeTotalExec; + private JobBean logInfo; + private ProteinBean predictions; + + public DataBase() { + } + + public DataBase(String dat, int total) { + this.date = dat; + this.total = total; + } + + public void setDate(String dat) { + this.date = dat; + } + + public String getDate() { + if (null == date) + return "1/1/1970"; + return date; + } + + public void setTotal(int tot) { + this.total = tot; + } + + public int getTotal() { + return total; + } + + public void setTotalOK(int tot) { + this.totalOK = tot; + } + + public int getTotalOK() { + return totalOK; + } + + public void setTotalStopped(int tot) { + this.totalStopped = tot; + } + + public int getTotalStopped() { + return totalStopped; + } + + public void setTotalError(int tot) { + this.totalError = tot; + } + + public int getTotalError() { + return totalError; + } + + public void setTotalTimeOut(int tot) { + this.totalTimeOut = tot; + } + + public int getTotalTimeOut() { + return totalTimeOut; + } + + public void setTotalJobs(int totalJobs) { + this.totalJobs = totalJobs; + } + + public int getTotalJobs() { + return totalJobs; + } + + public void setTotalId(int totId) { + this.totalId = totId; + } + + public int getTotalId() { + return totalId; + } + + public void setProt(String prot) { + this.prot = prot; + } + + public String getProt() { + return prot; + } + + public void setJpred(String jpred) { + this.jpred = jpred; + } + + public String getJpred() { + return jpred; + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getIp() { + return ip; + } + + public void setTimeRez(List timeRez) { + this.timeRez = timeRez; + } + + public List getTimeRez() { + return timeRez; + } + + public void setTimeTotalExec(List timeTotalExec) { + this.timeTotalExec = timeTotalExec; + } + + public List getTimeTotalExec() { + return timeTotalExec; + } + + public void setLogInfo(JobBean logInfo){ + this.logInfo = logInfo; + } + + public JobBean getLogInfo() { + return logInfo; + } + + public void setPredictions(ProteinBean predictions){ + this.predictions = predictions; + } + + public ProteinBean getPredictions() { + return predictions; + } + +} diff --git a/server/compbio/controllers/DailyStatisticsController.java b/server/compbio/controllers/DailyStatisticsController.java index d6a0c1e..7659a76 100644 --- a/server/compbio/controllers/DailyStatisticsController.java +++ b/server/compbio/controllers/DailyStatisticsController.java @@ -15,7 +15,6 @@ import compbio.engine.JobStatus; import compbio.cassandra.DateBean; import compbio.cassandra.TotalJobsStatisticBean; import compbio.statistic.CassandraRequester; -import compbio.statistic.StatisticsProt; /** * @author Alexander Sherstnev @@ -47,7 +46,7 @@ public class DailyStatisticsController extends BasicController { CassandraRequester cr = new CassandraRequester(); if (option.equals("AllDates,off")) { Calendar cal = Calendar.getInstance(); - date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate()); + date1 = DateFormatYYMMDD(cr.earliestDate()); date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); } model.put("date1", date1); @@ -97,4 +96,14 @@ public class DailyStatisticsController extends BasicController { model.put("timeExecution", (endTime - startTime)); return "/reportJobStatisticsOneDay"; } + + /* + * convert ??? + */ + private String DateFormatYYMMDD(long indate) { + SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd"); + String dateString = datformat.format(new Date(indate)); + return dateString; + } + } diff --git a/server/compbio/listeners/ServletJobsByDate.java b/server/compbio/listeners/ServletJobsByDate.java index 8ae389f..142a067 100644 --- a/server/compbio/listeners/ServletJobsByDate.java +++ b/server/compbio/listeners/ServletJobsByDate.java @@ -1,7 +1,9 @@ package compbio.listeners; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Date; import java.util.List; import javax.servlet.RequestDispatcher; @@ -13,7 +15,6 @@ import javax.servlet.http.HttpServletResponse; import compbio.cassandra.DataBase; import compbio.statistic.CassandraRequester; -import compbio.statistic.StatisticsProt; @WebServlet("/ServletJobsByDate") public class ServletJobsByDate extends HttpServlet { @@ -30,16 +31,17 @@ public class ServletJobsByDate extends HttpServlet { CassandraRequester cr = new CassandraRequester(); if (null != request.getParameter("option")) { Calendar cal = Calendar.getInstance(); - date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate()); + date1 = DateFormatYYMMDD(cr.earliestDate()); date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); } request.setAttribute("data1", date1); request.setAttribute("data2", date2); -// List res = cr.countJobs(date1, date2); -// request.setAttribute("result", res); + // List res = cr.countJobs(date1, date2); + // request.setAttribute("result", res); final long endTime = System.currentTimeMillis(); request.setAttribute("timeExecution", (endTime - startTime)); -// System.out.println ("QueryServlet.doGet: total number of dates = " + res.size()); + // System.out.println ("QueryServlet.doGet: total number of dates = " + + // res.size()); request.setAttribute("flag", request.getParameter("option")); RequestDispatcher rd = request.getRequestDispatcher("/ReportJobsByDate.jsp"); rd.forward(request, response); @@ -49,4 +51,12 @@ public class ServletJobsByDate extends HttpServlet { doGet(request, response); } + /* + * convert ??? + */ + private String DateFormatYYMMDD(long indate) { + SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd"); + String dateString = datformat.format(new Date(indate)); + return dateString; + } } diff --git a/server/compbio/listeners/ServletTimeExecution.java b/server/compbio/listeners/ServletTimeExecution.java index c380604..46e1460 100644 --- a/server/compbio/listeners/ServletTimeExecution.java +++ b/server/compbio/listeners/ServletTimeExecution.java @@ -1,7 +1,9 @@ package compbio.listeners; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Date; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -10,7 +12,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import compbio.statistic.StatisticsProt; import compbio.statistic.CassandraRequester; /** @@ -31,7 +32,7 @@ public class ServletTimeExecution extends HttpServlet { CassandraRequester sp = new CassandraRequester(); if (null != request.getParameter("option")) { Calendar cal = Calendar.getInstance(); - date1 = StatisticsProt.DateFormatYYMMDD(sp.earliestDate()); + date1 = DateFormatYYMMDD(sp.earliestDate()); date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); } request.setAttribute("data1", date1); @@ -51,4 +52,12 @@ public class ServletTimeExecution extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } + /* + * convert ??? + */ + private String DateFormatYYMMDD(long indate) { + SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd"); + String dateString = datformat.format(new Date(indate)); + return dateString; + } } diff --git a/server/compbio/statistic/CassandraRequester.java b/server/compbio/statistic/CassandraRequester.java index f2336e7..3e5db8a 100755 --- a/server/compbio/statistic/CassandraRequester.java +++ b/server/compbio/statistic/CassandraRequester.java @@ -12,7 +12,7 @@ import java.util.Map; import compbio.cassandra.DateBean; import compbio.cassandra.ProteinBean; import compbio.cassandra.CassandraNativeConnector; -import compbio.cassandra.CassandraReader; +import compbio.cassandra.CassandraReaderOld; import compbio.cassandra.DataBase; import compbio.cassandra.Pair; import compbio.cassandra.JobBean; @@ -23,7 +23,7 @@ import compbio.cassandra.UserBean; import compbio.engine.JobStatus; 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; @@ -122,7 +122,7 @@ 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) { + /* if (null == date1) { date1 = "1970/1/1"; } if (null == date2) { @@ -131,17 +131,16 @@ public class CassandraRequester { 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) +/* if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd) return null; if (dateStart < earlestDate) dateStart = earlestDate; if (dateEnd > currentDate) - dateStart = currentDate; - + dateStart = currentDate;*/ Calendar start = Calendar.getInstance(); start.setTime(new Date(dateStart)); Calendar end = Calendar.getInstance(); -- 1.7.10.2