private SiteActivity getDataForMonth(Calendar cal_) { Calendar cal = (Calendar) cal_.clone(); int desiredMonth = cal.get(Calendar.MONTH); for (int i = siteActivity.size() - 1; i >= 0; i--) { SiteActivity sa = siteActivity.get(i); cal.setTime(sa.getDate()); int thisMonth = cal.get(Calendar.MONTH); if (desiredMonth == thisMonth) { // System.out.println("SummaryActivityChartDataImpl.getDataForMonth: // "+(cal.getTime().toGMTString()) +" matches "+sa.getDate().toGMTString()+" => // "+sa.getCount()); return sa; } } return null; }
private void fillBarChartData() { if (viewType == null || chartType == null || siteActivity == null) return; // set first and last day data int timeSlots = 0; // fill arrays if (StatsManager.VIEW_WEEK.equals(viewType)) { timeSlots = 7; } else if (StatsManager.VIEW_MONTH.equals(viewType)) { timeSlots = 30; } else if (StatsManager.VIEW_YEAR.equals(viewType)) { timeSlots = 12; } // fill with data, backwards Calendar cal = Calendar.getInstance(); activity = new long[timeSlots]; for (int i = timeSlots - 1; i >= 0; i--) { SiteActivity sa = null; // System.out.println("SummaryActivityChartDataImpl.fillData: i="+i+" // date="+cal.getTime().toGMTString()); if (StatsManager.VIEW_YEAR.equals(viewType)) sa = getDataForMonth(cal); else sa = getDataForDay(cal); if (sa == null) { activity[i] = 0; } else { activity[i] = sa.getCount(); } if (i > 0) { if (StatsManager.VIEW_WEEK.equals(viewType) || StatsManager.VIEW_MONTH.equals(viewType)) { cal.add(Calendar.DATE, -1); } else if (StatsManager.VIEW_YEAR.equals(viewType)) { cal.add(Calendar.MONTH, -1); } } } firstDay = cal.getTime(); // System.out.println("SummaryActivityChartDataImpl.firstDay: "+firstDay.toGMTString()); }