diff --git a/src/main/java/ai/elimu/web/analytics/VideoLearningEventListController.java b/src/main/java/ai/elimu/web/analytics/VideoLearningEventListController.java index 1e8264566..92e7bd99f 100644 --- a/src/main/java/ai/elimu/web/analytics/VideoLearningEventListController.java +++ b/src/main/java/ai/elimu/web/analytics/VideoLearningEventListController.java @@ -34,39 +34,46 @@ public String handleRequest(Model model) { logger.info("handleRequest"); List videoLearningEvents = videoLearningEventDao.readAllOrderedByTimestamp(OrderDirection.DESC); + logger.info("videoLearningEvents.size(): " + videoLearningEvents.size()); for (VideoLearningEvent videoLearningEvent : videoLearningEvents) { videoLearningEvent.setAndroidId(AnalyticsHelper.redactAndroidId(videoLearningEvent.getAndroidId())); } - model.addAttribute("videoLearningEvents", videoLearningEvents); + + model.addAttribute("videoLearningEventCount", videoLearningEvents.size()); + if (videoLearningEvents.size() <= 100) { + model.addAttribute("videoLearningEvents", videoLearningEvents); + } else { + model.addAttribute("videoLearningEvents", videoLearningEvents.subList(0, 100)); + } // Prepare chart data - List monthList = new ArrayList<>(); + List weekList = new ArrayList<>(); List eventCountList = new ArrayList<>(); if (!videoLearningEvents.isEmpty()) { - // Group event count by month (e.g. "Aug-2024", "Sep-2024") + // Group event count by week (e.g. "32-2024", "37-2024") Map eventCountByMonthMap = new HashMap<>(); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM-yyyy"); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("ww-yyyy"); for (VideoLearningEvent event : videoLearningEvents) { String eventMonth = simpleDateFormat.format(event.getTimestamp().getTime()); eventCountByMonthMap.put(eventMonth, eventCountByMonthMap.getOrDefault(eventMonth, 0) + 1); } - // Iterate each month from 4 years ago until now - Calendar calendar4YearsAgo = Calendar.getInstance(); - calendar4YearsAgo.add(Calendar.YEAR, -4); + // Iterate each week from 6 months ago until now + Calendar calendar6MonthsAgo = Calendar.getInstance(); + calendar6MonthsAgo.add(Calendar.MONTH, -6); // 26 weeks Calendar calendarNow = Calendar.getInstance(); - Calendar month = calendar4YearsAgo; - while (!month.after(calendarNow)) { - String monthAsString = simpleDateFormat.format(month.getTime()); - monthList.add(monthAsString); + Calendar week = calendar6MonthsAgo; + while (!week.after(calendarNow)) { + String weekAsString = simpleDateFormat.format(week.getTime()); + weekList.add(weekAsString); - eventCountList.add(eventCountByMonthMap.getOrDefault(monthAsString, 0)); + eventCountList.add(eventCountByMonthMap.getOrDefault(weekAsString, 0)); - // Increase the date by 1 month - month.add(Calendar.MONTH, 1); + // Increase the date by 1 week + week.add(Calendar.WEEK_OF_YEAR, 1); } } - model.addAttribute("monthList", monthList); + model.addAttribute("weekList", weekList); model.addAttribute("eventCountList", eventCountList); return "analytics/video-learning-event/list"; diff --git a/src/main/webapp/WEB-INF/jsp/analytics/video-learning-event/list.jsp b/src/main/webapp/WEB-INF/jsp/analytics/video-learning-event/list.jsp index f81c5584d..440689de8 100644 --- a/src/main/webapp/WEB-INF/jsp/analytics/video-learning-event/list.jsp +++ b/src/main/webapp/WEB-INF/jsp/analytics/video-learning-event/list.jsp @@ -1,5 +1,5 @@ - VideoLearningEvents (${fn:length(videoLearningEvents)}) + VideoLearningEvents (${videoLearningEventCount}) @@ -9,7 +9,7 @@