@@ -60,6 +60,21 @@ public String handleRequest(@PathVariable Long studentId, Model model) {
60
60
model .addAttribute ("numeracySkills" , NumeracySkill .values ());
61
61
62
62
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
+
63
78
List <LetterSoundAssessmentEvent > letterSoundAssessmentEvents = letterSoundAssessmentEventDao .readAll (student .getAndroidId ());
64
79
model .addAttribute ("letterSoundAssessmentEvents" , letterSoundAssessmentEvents );
65
80
@@ -69,99 +84,69 @@ public String handleRequest(@PathVariable Long studentId, Model model) {
69
84
70
85
// Prepare chart data - WordLearningEvents
71
86
List <WordLearningEvent > wordLearningEvents = wordLearningEventDao .readAll (student .getAndroidId ());
72
- List <String > wordMonthList = new ArrayList <>();
73
87
List <Integer > wordEventCountList = new ArrayList <>();
74
88
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 <>();
78
91
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 );
81
94
}
82
95
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 );
96
102
}
97
103
}
98
- model .addAttribute ("wordMonthList" , wordMonthList );
99
104
model .addAttribute ("wordEventCountList" , wordEventCountList );
100
105
model .addAttribute ("wordLearningEvents" , wordLearningEvents );
101
106
102
107
103
108
// Prepare chart data - StoryBookLearningEvents
104
109
List <StoryBookLearningEvent > storyBookLearningEvents = storyBookLearningEventDao .readAll (student .getAndroidId ());
105
- List <String > storyBookMonthList = new ArrayList <>();
106
110
List <Integer > storyBookEventCountList = new ArrayList <>();
107
111
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 <>();
111
114
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 );
114
117
}
115
118
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 );
129
125
}
130
126
}
131
- model .addAttribute ("storyBookMonthList" , storyBookMonthList );
132
127
model .addAttribute ("storyBookEventCountList" , storyBookEventCountList );
133
128
model .addAttribute ("storyBookLearningEvents" , storyBookLearningEvents );
134
129
135
130
136
131
// Prepare chart data - VideoLearningEvents
137
132
List <VideoLearningEvent > videoLearningEvents = videoLearningEventDao .readAll (student .getAndroidId ());
138
- List <String > videoMonthList = new ArrayList <>();
139
133
List <Integer > videoEventCountList = new ArrayList <>();
140
134
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 <>();
144
137
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 );
147
140
}
148
141
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 );
162
148
}
163
149
}
164
- model .addAttribute ("videoMonthList" , videoMonthList );
165
150
model .addAttribute ("videoEventCountList" , videoEventCountList );
166
151
model .addAttribute ("videoLearningEvents" , videoLearningEvents );
167
152
0 commit comments