X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=server%2Fcompbio%2Fstatistic%2FStatisticsProt.java;h=05375c094c7640ce53f343110b900c1d3de4fc84;hb=1835d87d090291da1db317c27c7463191bfb54c4;hp=4ee29172fc04a2fa133bc302e5a5c7ef0aa07ec2;hpb=bd49ca1a637c5eb6d5f5db420dcd8b22cbb52f59;p=proteocache.git diff --git a/server/compbio/statistic/StatisticsProt.java b/server/compbio/statistic/StatisticsProt.java index 4ee2917..05375c0 100755 --- a/server/compbio/statistic/StatisticsProt.java +++ b/server/compbio/statistic/StatisticsProt.java @@ -9,29 +9,20 @@ import java.util.Date; import java.util.Iterator; import java.util.List; -import me.prettyprint.cassandra.serializers.LongSerializer; -import me.prettyprint.cassandra.serializers.StringSerializer; -import me.prettyprint.hector.api.beans.ColumnSlice; -import me.prettyprint.hector.api.beans.HColumn; -import me.prettyprint.hector.api.beans.OrderedRows; -import me.prettyprint.hector.api.beans.Row; -import me.prettyprint.hector.api.factory.HFactory; -import me.prettyprint.hector.api.query.QueryResult; -import me.prettyprint.hector.api.query.RangeSlicesQuery; -import me.prettyprint.hector.api.query.SliceQuery; -import compbio.cassandra.CassandraCreate; +import compbio.cassandra.CassandraNativeConnector; import compbio.cassandra.DataBase; public class StatisticsProt { -// private final static long MILLISECONDS_PER_DAY = 1000L * 60 * 60 * 24; - private CassandraCreate cc = new CassandraCreate(); + private CassandraNativeConnector cc = new CassandraNativeConnector(); private ArrayList 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 readDetails(String date1, String date2) { - + if (!isThisDateValid(date1) || !isThisDateValid(date2)) { System.out.println("Wrong date: point 1"); return null; @@ -39,8 +30,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; @@ -55,6 +45,7 @@ public class StatisticsProt { end.setTime(new Date(dateEnd)); query = new ArrayList(); int day = 0; + /* for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) { SliceQuery result = HFactory.createSliceQuery(cc.GetKeyspace(), LongSerializer.get(), StringSerializer.get(), StringSerializer.get()); @@ -71,25 +62,25 @@ 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; } /* * query: execution time for the period from date1 till date2 - */ + * */ public List 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,8 +95,9 @@ public class StatisticsProt { end.setTime(new Date(dateEnd)); query = new ArrayList(); List totalTime = new ArrayList(); - 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 timeResult = new ArrayList(); SliceQuery result = HFactory.createSliceQuery(cc.GetKeyspace(), LongSerializer.get(), @@ -117,30 +109,33 @@ public class StatisticsProt { List> col = columnSlice.get().getColumns(); if (!col.isEmpty()) { Iterator> 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); query.add(db); @@ -148,9 +143,12 @@ public class StatisticsProt { return query; } - /* query: protein sequence */ + /* + * query: protein sequence + * */ public List readProteins(String protIn) { query = new ArrayList(); + /* SliceQuery result = HFactory.createSliceQuery(cc.GetKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get()); result.setColumnFamily("ProteinRow"); @@ -169,17 +167,21 @@ public class StatisticsProt { query.add(db); } } + */ return query; } - // query by a protein sequence + /* + * query by a protein sequence + * */ public List readProtID(int counter) { query = new ArrayList(); - int row_count = 100000000; + int row_count = 100; + /* RangeSlicesQuery result = HFactory.createRangeSlicesQuery(cc.GetKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get()); result.setColumnFamily("ProteinRow"); - result.setRange(null, null, false, Integer.MAX_VALUE); + result.setRange(null, null, false, 100); result.setRowCount(row_count); String last_key = null; while (true) { @@ -191,13 +193,14 @@ public class StatisticsProt { Row row = rowsIterator.next(); last_key = row.getKey(); List> clms = row.getColumnSlice().getColumns(); - int npred = 0; - for (HColumn cln : clms) { - String name = cln.getName(); - if (name.matches("(.*)jnetpred")) { - ++npred; - } - } + //int npred = 0; + //for (HColumn cln : clms) { + // String name = cln.getName(); + // if (name.matches("(.*)jnetpred")) { + // ++npred; + // } + //} + int npred = clms.size(); if (npred > counter) { DataBase db = new DataBase(); db.setProt(last_key); @@ -207,14 +210,17 @@ public class StatisticsProt { } if (rows.getCount() < row_count) break; - } + }*/ return query; } - // query by a part of sequence + /* + * query by a part of sequence + * */ public List readPart(String protIn) { int row_count = 10000; query = new ArrayList(); + /* RangeSlicesQuery result = HFactory.createRangeSlicesQuery(cc.GetKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get()); result.setColumnFamily("ProteinRow"); @@ -259,10 +265,13 @@ public class StatisticsProt { if (rows.getCount() < row_count) break; } + */ 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,7 +319,11 @@ public class StatisticsProt { return dateString; } + /* + * ??? + */ public long CountID(String id) { + /* SliceQuery sliceQuery = HFactory.createSliceQuery(cc.GetKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get()); sliceQuery.setColumnFamily("ProteinLog").setKey(id).setRange("", "", false, 100); @@ -321,8 +334,15 @@ public class StatisticsProt { long datBeginLong = TimeConvert(datBegin); long datEndLong = TimeConvert(datEnd); return (datEndLong - datBeginLong) / 1000; + */ + return 0; } + /* + * 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,10 +370,13 @@ public class StatisticsProt { return true; } - // find the earliest date + /* + * find the earliest date in the database + */ public long earliestDate() { ArrayList dateSort = new ArrayList(); int row_count = 10000; + /* RangeSlicesQuery result = HFactory.createRangeSlicesQuery(cc.GetKeyspace(), LongSerializer.get(), StringSerializer.get(), StringSerializer.get()); result.setColumnFamily("ProteinData"); @@ -372,7 +395,7 @@ public class StatisticsProt { } if (rows.getCount() < row_count) break; - } + }*/ Collections.sort(dateSort); return dateSort.get(0); }