import compbio.cassandra.DataBase;
public class StatisticsProt {
- private final static long MILLISECONDS_PER_DAY = 1000L * 60 * 60 * 24;
+// private final static long MILLISECONDS_PER_DAY = 1000L * 60 * 60 * 24;
private CassandraCreate cc = new CassandraCreate();
private ArrayList<DataBase> query;
private static long currentDate = 0;
/* query: the period from date1 till date2 */
public List<DataBase> readDetails(String date1, String date2) {
+
if (!isThisDateValid(date1) || !isThisDateValid(date2)) {
System.out.println("Wrong date: point 1");
return null;
}
SetDateRange();
-
long dateStart = DateParsing(date1);
long dateEnd = DateParsing(date2);
+ if ((dateStart < earlestDate && dateEnd < earlestDate) || (dateStart > currentDate && dateEnd > currentDate)
+ || dateStart > dateEnd)
+ return null;
if (dateStart < earlestDate)
dateStart = earlestDate;
- if (dateStart > currentDate)
- dateStart = currentDate - MILLISECONDS_PER_DAY;
- if (dateEnd < earlestDate)
- dateStart = earlestDate + MILLISECONDS_PER_DAY;
if (dateEnd > currentDate)
dateStart = currentDate;
System.out.println("StatisticsProt.readDetails: earlestDate = " + earlestDate + ", currentDate = " + currentDate);
System.out.println("StatisticsProt.readDetails: Start date " + date1 + ": int representation = " + dateStart);
System.out.println("StatisticsProt.readDetails: End date " + date2 + ": int representation = " + dateEnd);
-
+ Calendar start = Calendar.getInstance();
+ start.setTime(new Date(dateStart));
+ Calendar end = Calendar.getInstance();
+ end.setTime(new Date(dateEnd));
query = new ArrayList<DataBase>();
int day = 0;
- while (dateStart <= dateEnd) {
+ for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
SliceQuery<Long, String, String> result = HFactory.createSliceQuery(cc.GetKeyspace(), LongSerializer.get(),
StringSerializer.get(), StringSerializer.get());
result.setColumnFamily("ProteinData");
- result.setKey(dateStart);
+ result.setKey(date.getTime());
result.setRange(null, null, false, Integer.MAX_VALUE);
QueryResult<ColumnSlice<String, String>> columnSlice = result.execute();
++day;
- System.out.print("Day " + day + ": dataStart = " + dateStart + ": ");
+ System.out.print("Day " + day + ": dataStart = " + date + ": ");
if (!columnSlice.get().getColumns().isEmpty()) {
- DataBase db = new DataBase(DateFormat(dateStart), columnSlice.get().getColumns().size());
+ DataBase db = new DataBase(DateFormat(date.getTime()), columnSlice.get().getColumns().size());
query.add(db);
System.out.println("data exist");
} else {
System.out.println("no data");
}
- dateStart += MILLISECONDS_PER_DAY;
+ // dateStart += MILLISECONDS_PER_DAY;
}
System.out.println("StatisticsProt.readLength: total number of dates = " + query.size());
return query;
return null;
}
SetDateRange();
-
long dateStart = DateParsing(date1);
long dateEnd = DateParsing(date2);
+ if ((dateStart < earlestDate && dateEnd < earlestDate) || (dateStart > currentDate && dateEnd > currentDate)
+ || dateStart > dateEnd)
+ return null;
if (dateStart < earlestDate)
dateStart = earlestDate;
- if (dateStart > currentDate)
- dateStart = currentDate - MILLISECONDS_PER_DAY;
- if (dateEnd < earlestDate)
- dateStart = earlestDate + MILLISECONDS_PER_DAY;
if (dateEnd > currentDate)
dateStart = currentDate;
System.out.println("StatisticsProt.readLength: earlestDate = " + earlestDate + ", currentDate = " + currentDate);
System.out.println("StatisticsProt.readLength: Start date is " + date1 + ": int representation = " + dateStart);
System.out.println("StatisticsProt.readLength: End date is " + date2 + ": int representation = " + dateEnd);
-
+ Calendar start = Calendar.getInstance();
+ start.setTime(new Date(dateStart));
+ Calendar end = Calendar.getInstance();
+ end.setTime(new Date(dateEnd));
query = new ArrayList<DataBase>();
List<Integer> totalTime = new ArrayList<Integer>();
for (int i = 0; i < 4; i++)
totalTime.add(i, 0);
- while (dateStart <= dateEnd) {
+ for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
List<Integer> timeResult = new ArrayList<Integer>();
SliceQuery<Long, String, String> result = HFactory.createSliceQuery(cc.GetKeyspace(), LongSerializer.get(),
StringSerializer.get(), StringSerializer.get());
result.setColumnFamily("ProteinData");
- result.setKey(dateStart);
+ result.setKey(date.getTime());
result.setRange(null, null, false, Integer.MAX_VALUE);
QueryResult<ColumnSlice<String, String>> columnSlice = result.execute();
List<HColumn<String, String>> col = columnSlice.get().getColumns();
totalTime.set(i, totalTime.get(i) + timeResult.get(i));
DataBase db = new DataBase();
db.setTimeRez(timeResult);
- db.setDate(DateFormat(dateStart));
+ db.setDate(DateFormat(date.getTime()));
query.add(db);
}
- dateStart += MILLISECONDS_PER_DAY;
+ // dateStart += MILLISECONDS_PER_DAY;
}
DataBase db = new DataBase();
db.setTimeTotalExec(totalTime);
++npred;
}
}
- if (npred >= counter) {
+ if (npred > counter) {
DataBase db = new DataBase();
db.setProt(last_key);
db.setTotalId(npred);