I need to count the points of a chart for a duration picked by an user.
My chart is about logs, we need to know how many users are connected for every specified minutes while a specific duration. We don't want to use too many queries, so I work essentially with lists.
Dates are stored in String format as "yyyy-MM-dd HH:mm:ss".
My code works but is really too long to load:
old=ofy().load().type(Log.class).filter("site in",selectedSites).filter("license in",ofy().load().type(License.class).filter("name", name)).filter("date_out >=",datemin).filter("date_out <=",datemax).list();
Duration duration = new Duration(firstIn, lastDateOut); //Duration between two dates choosen by the user
int dimension=(int) ((duration.getStandardMinutes())/divideBy); //Number of abscissa points in the chart
DateTime[] dates=new DateTime[dimension+1]; //Init of the dates
int[] counts=new int[dimension+1]; //Init of the count table (count of logged users at the date
DateTime transfert=firstIn; //First date
for(int i=0;i<=dimension;i++){
counts[i]=0;
dates[i]=transfert.minusSeconds(transfert.getSecondOfMinute());
transfert=transfert.plusMinutes(divideBy);
for(Log log:old){
if((StaticMethods.toDateTime(log.getDate_in()).minusSeconds(StaticMethods.toDateTime(log.getDate_in()).getSecondOfMinute()).equals(dates[i]))
||((StaticMethods.toDateTime(log.getDate_in()).minusSeconds(StaticMethods.toDateTime(log.getDate_in()).getSecondOfMinute()).isBefore(dates[i]))
&&(StaticMethods.toDateTime(log.getDate_out()).minusSeconds(StaticMethods.toDateTime(log.getDate_out()).getSecondOfMinute()).isAfter(dates[i])))
||(StaticMethods.toDateTime(log.getDate_out()).minusSeconds(StaticMethods.toDateTime(log.getDate_out()).getSecondOfMinute()).equals(dates[i]))
){
counts[i]++;
}
}
GraphData nw=new GraphData(dates[i].toDate(), counts[i]);
}
I want to know if there is a possible less loading time (have read this and I need to know if there's similar way for approximate values).