Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom-dependency-tree.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ai.elimu:webapp:war:2.6.32-SNAPSHOT
ai.elimu:webapp:war:2.6.34-SNAPSHOT
+- ai.elimu:model:jar:model-2.0.97:compile
| \- com.google.code.gson:gson:jar:2.13.0:compile
| \- com.google.errorprone:error_prone_annotations:jar:2.37.0:compile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,38 @@ public String handleRequest(@PathVariable Long studentId, Model model) {
}
model.addAttribute("wordAssessmentEventCorrectCountList", wordAssessmentEventCorrectCountList);
model.addAttribute("wordAssessmentEventIncorrectCountList", wordAssessmentEventIncorrectCountList);

// Prepare chart data - Reading speed (words per minute)
List<Double> readingSpeedAvgList = new ArrayList<>();
if (!wordAssessmentEvents.isEmpty()) {
Map<String, Integer> eventCountByWeekMap = new HashMap<>();
Map<String, Long> timeSpentMsSumByWeekMap = new HashMap<>();
for (WordAssessmentEvent event : wordAssessmentEvents) {
String eventWeek = simpleDateFormat.format(event.getTimestamp().getTime());
if (event.getMasteryScore() >= 0.5) {
eventCountByWeekMap.put(eventWeek, eventCountByWeekMap.getOrDefault(eventWeek, 0) + 1);
timeSpentMsSumByWeekMap.put(eventWeek, eventCountByWeekMap.getOrDefault(eventWeek, 0) + event.getTimeSpentMs());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the time sum calculation bug.

Line 156 incorrectly uses eventCountByWeekMap.getOrDefault(eventWeek, 0) instead of the time sum map.

Apply this diff to fix the bug:

-          timeSpentMsSumByWeekMap.put(eventWeek, eventCountByWeekMap.getOrDefault(eventWeek, 0) + event.getTimeSpentMs());
+          timeSpentMsSumByWeekMap.put(eventWeek, timeSpentMsSumByWeekMap.getOrDefault(eventWeek, 0L) + event.getTimeSpentMs());
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
timeSpentMsSumByWeekMap.put(eventWeek, eventCountByWeekMap.getOrDefault(eventWeek, 0) + event.getTimeSpentMs());
timeSpentMsSumByWeekMap.put(
eventWeek,
- eventCountByWeekMap.getOrDefault(eventWeek, 0) + event.getTimeSpentMs()
+ timeSpentMsSumByWeekMap.getOrDefault(eventWeek, 0L) + event.getTimeSpentMs()
);
🤖 Prompt for AI Agents
In src/main/java/ai/elimu/web/analytics/students/StudentController.java at line
156, the code incorrectly sums time spent by using eventCountByWeekMap instead
of timeSpentMsSumByWeekMap. Fix this by replacing
eventCountByWeekMap.getOrDefault(eventWeek, 0) with
timeSpentMsSumByWeekMap.getOrDefault(eventWeek, 0) to correctly accumulate the
total time spent per week.

}
}
week = (Calendar) calendar6MonthsAgo.clone();
while (!week.after(calendarNow)) {
String weekAsString = simpleDateFormat.format(week.getTime());
Integer wordsReadCount = eventCountByWeekMap.getOrDefault(weekAsString, 0);
log.info("wordsReadCount: " + wordsReadCount);
Long timeSpentMsSum = timeSpentMsSumByWeekMap.getOrDefault(weekAsString, 0L);
log.info("timeSpentMsSum: " + timeSpentMsSum);
Double timeSpentInMinutes = (double) (timeSpentMsSum / 1_000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Correct the milliseconds to minutes conversion.

Line 166 incorrectly converts milliseconds to minutes by dividing by 1,000. The correct conversion should divide by 60,000 (1000ms × 60s = 60,000ms per minute).

Apply this diff to fix the conversion:

-        Double timeSpentInMinutes = (double) (timeSpentMsSum / 1_000);
+        Double timeSpentInMinutes = (double) timeSpentMsSum / 60_000.0;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Double timeSpentInMinutes = (double) (timeSpentMsSum / 1_000);
- Double timeSpentInMinutes = (double) (timeSpentMsSum / 1_000);
+ Double timeSpentInMinutes = (double) timeSpentMsSum / 60_000.0;
🤖 Prompt for AI Agents
In src/main/java/ai/elimu/web/analytics/students/StudentController.java at line
166, the conversion from milliseconds to minutes is incorrect because it divides
by 1,000 instead of 60,000. Fix this by changing the divisor from 1,000 to
60,000 to correctly convert milliseconds to minutes.

log.info("timeSpentInMinutes: " + timeSpentInMinutes);
Double wordsPerMinute = 0.00;
if (timeSpentInMinutes > 0) {
wordsPerMinute = wordsReadCount / timeSpentInMinutes;
log.info("wordsPerMinute: " + wordsPerMinute);
}
readingSpeedAvgList.add(wordsPerMinute);
week.add(Calendar.WEEK_OF_YEAR, 1);
}
}
model.addAttribute("readingSpeedAvgList", readingSpeedAvgList);

// Prepare chart data - WordLearningEvents
List<WordLearningEvent> wordLearningEvents = wordLearningEventDao.readAll(student.getAndroidId());
Expand Down
28 changes: 28 additions & 0 deletions src/main/webapp/WEB-INF/jsp/analytics/students/id.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,34 @@

<h5 style="margin-top: 1em;">🔤 Words</h5>
<div class="card-panel">
<h5>Reading speed (correct words per minute)</h5>
<canvas id="readingSpeedChart"></canvas>
<script>
const readingSpeedLabels = [
<c:forEach var="week" items="${weekList}">'${week}',</c:forEach>
];
const readingSpeedData = {
labels: readingSpeedLabels,
datasets: [{
data: <c:out value="${readingSpeedAvgList}" />,
label: 'cwpm',
backgroundColor: 'rgba(100,181,246, 0.5)', // #64b5f6 blue lighten-2
borderColor: 'rgba(100,181,246, 0.5)', // #64b5f6 blue lighten-2
tension: 0.5,
fill: true
}]
};
const readingSpeedConfig = {
type: 'line',
data: readingSpeedData,
options: {}
};
var readingSpeedCtx = document.getElementById('readingSpeedChart');
new Chart(readingSpeedCtx, readingSpeedConfig);
</script>

<div class="divider" style="margin: 2em 0;"></div>

<a id="exportWordAssessmentEventsToCsvButton" class="right btn waves-effect waves-light grey-text white"
href="<spring:url value='/analytics/students/${student.id}/word-assessment-events.csv' />">
Export to CSV<i class="material-icons right">vertical_align_bottom</i>
Expand Down