@@ -60,6 +60,21 @@ public String handleRequest(@PathVariable Long studentId, Model model) {
6060 model .addAttribute ("numeracySkills" , NumeracySkill .values ());
6161
6262
63+ // Generate a list of weeks from 6 months ago until now
64+ List <String > weekList = new ArrayList <>();
65+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("yyyy-ww" );
66+ Calendar calendar6MonthsAgo = Calendar .getInstance ();
67+ calendar6MonthsAgo .add (Calendar .MONTH , -6 );
68+ Calendar calendarNow = Calendar .getInstance ();
69+ Calendar week = calendar6MonthsAgo ;
70+ while (!week .after (calendarNow )) {
71+ String weekAsString = simpleDateFormat .format (week .getTime ());
72+ weekList .add (weekAsString );
73+ week .add (Calendar .WEEK_OF_YEAR , 1 );
74+ }
75+ model .addAttribute ("weekList" , weekList );
76+
77+
6378 List <LetterSoundAssessmentEvent > letterSoundAssessmentEvents = letterSoundAssessmentEventDao .readAll (student .getAndroidId ());
6479 model .addAttribute ("letterSoundAssessmentEvents" , letterSoundAssessmentEvents );
6580
@@ -69,99 +84,69 @@ public String handleRequest(@PathVariable Long studentId, Model model) {
6984
7085 // Prepare chart data - WordLearningEvents
7186 List <WordLearningEvent > wordLearningEvents = wordLearningEventDao .readAll (student .getAndroidId ());
72- List <String > wordMonthList = new ArrayList <>();
7387 List <Integer > wordEventCountList = new ArrayList <>();
7488 if (!wordLearningEvents .isEmpty ()) {
75- // Group event count by month (e.g. "Aug-2024", "Sep-2024")
76- Map <String , Integer > eventCountByMonthMap = new HashMap <>();
77- SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("MMM-yyyy" );
89+ // Group event count by week (e.g. "2024-09", "2024-26")
90+ Map <String , Integer > eventCountByWeekMap = new HashMap <>();
7891 for (WordLearningEvent event : wordLearningEvents ) {
79- String eventMonth = simpleDateFormat .format (event .getTimestamp ().getTime ());
80- eventCountByMonthMap .put (eventMonth , eventCountByMonthMap .getOrDefault (eventMonth , 0 ) + 1 );
92+ String eventWeek = simpleDateFormat .format (event .getTimestamp ().getTime ());
93+ eventCountByWeekMap .put (eventWeek , eventCountByWeekMap .getOrDefault (eventWeek , 0 ) + 1 );
8194 }
8295
83- // Iterate each month from 4 years ago until now
84- Calendar calendar4YearsAgo = Calendar .getInstance ();
85- calendar4YearsAgo .add (Calendar .YEAR , -4 );
86- Calendar calendarNow = Calendar .getInstance ();
87- Calendar month = calendar4YearsAgo ;
88- while (!month .after (calendarNow )) {
89- String monthAsString = simpleDateFormat .format (month .getTime ());
90- wordMonthList .add (monthAsString );
91-
92- wordEventCountList .add (eventCountByMonthMap .getOrDefault (monthAsString , 0 ));
93-
94- // Increase the date by 1 month
95- month .add (Calendar .MONTH , 1 );
96+ // Iterate each week from 6 months ago until now
97+ week = calendar6MonthsAgo ;
98+ while (!week .after (calendarNow )) {
99+ String weekAsString = simpleDateFormat .format (week .getTime ());
100+ wordEventCountList .add (eventCountByWeekMap .getOrDefault (weekAsString , 0 ));
101+ week .add (Calendar .WEEK_OF_YEAR , 1 );
96102 }
97103 }
98- model .addAttribute ("wordMonthList" , wordMonthList );
99104 model .addAttribute ("wordEventCountList" , wordEventCountList );
100105 model .addAttribute ("wordLearningEvents" , wordLearningEvents );
101106
102107
103108 // Prepare chart data - StoryBookLearningEvents
104109 List <StoryBookLearningEvent > storyBookLearningEvents = storyBookLearningEventDao .readAll (student .getAndroidId ());
105- List <String > storyBookMonthList = new ArrayList <>();
106110 List <Integer > storyBookEventCountList = new ArrayList <>();
107111 if (!storyBookLearningEvents .isEmpty ()) {
108- // Group event count by month (e.g. "Aug-2024", "Sep-2024")
109- Map <String , Integer > eventCountByMonthMap = new HashMap <>();
110- SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("MMM-yyyy" );
112+ // Group event count by week (e.g. "2024-09", "2024-26")
113+ Map <String , Integer > eventCountByWeekMap = new HashMap <>();
111114 for (StoryBookLearningEvent event : storyBookLearningEvents ) {
112- String eventMonth = simpleDateFormat .format (event .getTimestamp ().getTime ());
113- eventCountByMonthMap .put (eventMonth , eventCountByMonthMap .getOrDefault (eventMonth , 0 ) + 1 );
115+ String eventWeek = simpleDateFormat .format (event .getTimestamp ().getTime ());
116+ eventCountByWeekMap .put (eventWeek , eventCountByWeekMap .getOrDefault (eventWeek , 0 ) + 1 );
114117 }
115118
116- // Iterate each month from 4 years ago until now
117- Calendar calendar4YearsAgo = Calendar .getInstance ();
118- calendar4YearsAgo .add (Calendar .YEAR , -4 );
119- Calendar calendarNow = Calendar .getInstance ();
120- Calendar month = calendar4YearsAgo ;
121- while (!month .after (calendarNow )) {
122- String monthAsString = simpleDateFormat .format (month .getTime ());
123- storyBookMonthList .add (monthAsString );
124-
125- storyBookEventCountList .add (eventCountByMonthMap .getOrDefault (monthAsString , 0 ));
126-
127- // Increase the date by 1 month
128- month .add (Calendar .MONTH , 1 );
119+ // Iterate each week from 6 months ago until now
120+ week = calendar6MonthsAgo ;
121+ while (!week .after (calendarNow )) {
122+ String weekAsString = simpleDateFormat .format (week .getTime ());
123+ storyBookEventCountList .add (eventCountByWeekMap .getOrDefault (weekAsString , 0 ));
124+ week .add (Calendar .WEEK_OF_YEAR , 1 );
129125 }
130126 }
131- model .addAttribute ("storyBookMonthList" , storyBookMonthList );
132127 model .addAttribute ("storyBookEventCountList" , storyBookEventCountList );
133128 model .addAttribute ("storyBookLearningEvents" , storyBookLearningEvents );
134129
135130
136131 // Prepare chart data - VideoLearningEvents
137132 List <VideoLearningEvent > videoLearningEvents = videoLearningEventDao .readAll (student .getAndroidId ());
138- List <String > videoMonthList = new ArrayList <>();
139133 List <Integer > videoEventCountList = new ArrayList <>();
140134 if (!videoLearningEvents .isEmpty ()) {
141- // Group event count by month (e.g. "Aug-2024", "Sep-2024")
142- Map <String , Integer > eventCountByMonthMap = new HashMap <>();
143- SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("MMM-yyyy" );
135+ // Group event count by week (e.g. "2024-09", "2024-26")
136+ Map <String , Integer > eventCountByWeekMap = new HashMap <>();
144137 for (VideoLearningEvent event : videoLearningEvents ) {
145- String eventMonth = simpleDateFormat .format (event .getTimestamp ().getTime ());
146- eventCountByMonthMap .put (eventMonth , eventCountByMonthMap .getOrDefault (eventMonth , 0 ) + 1 );
138+ String eventWeek = simpleDateFormat .format (event .getTimestamp ().getTime ());
139+ eventCountByWeekMap .put (eventWeek , eventCountByWeekMap .getOrDefault (eventWeek , 0 ) + 1 );
147140 }
148141
149- // Iterate each month from 4 years ago until now
150- Calendar calendar4YearsAgo = Calendar .getInstance ();
151- calendar4YearsAgo .add (Calendar .YEAR , -4 );
152- Calendar calendarNow = Calendar .getInstance ();
153- Calendar month = calendar4YearsAgo ;
154- while (!month .after (calendarNow )) {
155- String monthAsString = simpleDateFormat .format (month .getTime ());
156- videoMonthList .add (monthAsString );
157-
158- videoEventCountList .add (eventCountByMonthMap .getOrDefault (monthAsString , 0 ));
159-
160- // Increase the date by 1 month
161- month .add (Calendar .MONTH , 1 );
142+ // Iterate each week from 6 months ago until now
143+ week = calendar6MonthsAgo ;
144+ while (!week .after (calendarNow )) {
145+ String weekAsString = simpleDateFormat .format (week .getTime ());
146+ videoEventCountList .add (eventCountByWeekMap .getOrDefault (weekAsString , 0 ));
147+ week .add (Calendar .WEEK_OF_YEAR , 1 );
162148 }
163149 }
164- model .addAttribute ("videoMonthList" , videoMonthList );
165150 model .addAttribute ("videoEventCountList" , videoEventCountList );
166151 model .addAttribute ("videoLearningEvents" , videoLearningEvents );
167152
0 commit comments