Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): add video learning events to dashboard #1923

Merged
merged 4 commits into from
Oct 30, 2024

Conversation

jo-elimu
Copy link
Member

@jo-elimu jo-elimu commented Oct 26, 2024

Issue Number

Purpose

  • To make video learning events available for download and visualization.

Technical Details

  • Fetches video learning events from the database, and lists them in a UI.

Testing Instructions

Screenshots


Format Checks

Note

Files in PRs are automatically checked for format violations with mvn spotless:check.

If this PR contains files with format violations, run mvn spotless:apply to fix them.

@jo-elimu jo-elimu self-assigned this Oct 26, 2024
@jo-elimu jo-elimu requested a review from a team as a code owner October 26, 2024 04:13
@jo-elimu jo-elimu linked an issue Oct 26, 2024 that may be closed by this pull request
6 tasks
Copy link

codecov bot commented Oct 26, 2024

Codecov Report

Attention: Patch coverage is 8.69565% with 63 lines in your changes missing coverage. Please review.

Project coverage is 15.90%. Comparing base (55112e6) to head (d514186).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...alytics/VideoLearningEventCsvExportController.java 5.55% 34 Missing ⚠️
...eb/analytics/VideoLearningEventListController.java 6.66% 28 Missing ⚠️
...i/elimu/web/analytics/MainAnalyticsController.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1923      +/-   ##
============================================
- Coverage     15.97%   15.90%   -0.08%     
- Complexity      478      481       +3     
============================================
  Files           254      256       +2     
  Lines          7798     7866      +68     
  Branches        816      821       +5     
============================================
+ Hits           1246     1251       +5     
- Misses         6502     6565      +63     
  Partials         50       50              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

coderabbitai bot commented Oct 26, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes in this pull request involve the addition of a new "Videos" link in the navigation menu of the layout.jsp file and a new card for video learning events in the main.jsp file. The link directs users to a list of video learning events, and the card includes a title, an icon, and a link to view the list, maintaining consistency with existing content on the analytics page. Additionally, new controllers for handling video learning event data and exporting it as CSV are introduced, along with a new JSP for listing these events.

Changes

File Path Change Summary
src/main/webapp/WEB-INF/jsp/analytics/layout.jsp Added a new list item for "Videos" in the navigation menu linking to /analytics/video-learning-event/list.
src/main/webapp/WEB-INF/jsp/analytics/main.jsp Introduced a new card for video learning events with a title and link to the list of video learning events.
src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java Updated extractVideoLearningEvents method to use UTC for timestamp handling in Calendar instantiation.
src/main/java/ai/elimu/util/AnalyticsHelper.java Added a method redactAndroidId to redact portions of an Android ID.
src/main/java/ai/elimu/web/analytics/MainAnalyticsController.java Added VideoLearningEventDao and a model attribute for video learning event count.
src/main/java/ai/elimu/web/analytics/VideoLearningEventCsvExportController.java Introduced a controller for exporting video learning events as CSV.
src/main/java/ai/elimu/web/analytics/VideoLearningEventListController.java Introduced a controller for listing video learning events, processing and preparing data for display.
src/main/webapp/WEB-INF/jsp/analytics/video-learning-event/list.jsp Added a new JSP for displaying a list of video learning events with chart visualization and export option.
src/main/webapp/static/css/styles.css Added CSS rule for styling code elements.
src/test/java/ai/elimu/util/AnalyticsHelperTest.java Added test method for redactAndroidId functionality.

Assessment against linked issues

Objective Addressed Explanation
Update analytics dashboard (#1894) The analytics dashboard was not updated as required.

Possibly related PRs

  • feat(analytics): add video learning events to dashboard #1923: This PR adds a new link for "Videos" in the navigation menu of layout.jsp and introduces a card for video learning events in main.jsp, directly related to the changes made in the main PR that also adds a "Videos" link in layout.jsp and a card in main.jsp.
  • feat(entity): video learning event #1911: This PR introduces the VideoLearningEvent class, which is relevant as the main PR adds a link and card for video learning events, indicating a connection to the underlying data structure.
  • feat(rest): video learning events #1904: This PR implements a REST controller for video learning events, which aligns with the main PR's focus on enhancing the user interface for accessing video learning events.
  • Include additional data during data collection #1914: This PR adds an additionalData field to the LearningEvent class, which may be relevant as the main PR enhances the analytics dashboard for video learning events, potentially utilizing this additional data.
  • feat: scheduled task for importing video learning events #1921: This PR introduces a scheduled task for importing video learning events, which supports the main PR's focus on video learning events by ensuring that the data is regularly updated and available for display in the analytics dashboard.

Suggested reviewers

  • tomaszsmy
  • vuriaval
  • Souvik-Cyclic
  • alexander-kuruvilla
  • nya-elimu

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 81eb6af and f3810d8.

📒 Files selected for processing (2)
  • src/main/webapp/WEB-INF/jsp/analytics/layout.jsp (1 hunks)
  • src/main/webapp/WEB-INF/jsp/analytics/main.jsp (1 hunks)
🔇 Additional comments (2)
src/main/webapp/WEB-INF/jsp/analytics/main.jsp (1)

44-53: LGTM! Card structure follows existing patterns.

The new video learning events card maintains consistency with other cards in terms of layout, styling, and positioning.

src/main/webapp/WEB-INF/jsp/analytics/layout.jsp (1)

56-56: LGTM! Navigation structure is well-implemented.

The implementation:

  • Follows the existing pattern for learning events
  • Uses appropriate Material Icon
  • Maintains consistent URL structure
  • Properly placed in the learning events section

src/main/webapp/WEB-INF/jsp/analytics/main.jsp Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 26, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java (3)

142-142: Good use of UTC timezone, but needs consistent application.

Using UTC for timestamp storage is the correct approach. However, the getStoryBookLearningEventsFromCsvBackup method still uses the system default timezone. Consider updating it for consistency.

Apply this change to the getStoryBookLearningEventsFromCsvBackup method as well:

-                Calendar timestamp = Calendar.getInstance();
+                Calendar timestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

Line range hint 165-167: Improve error handling for CSV parsing.

The current error handling only logs the exception and continues execution, which could lead to silent failures. Consider:

  1. Propagating the IOException to allow proper error handling by the caller
  2. Adding validation for the returned list size

Here's a suggested improvement:

-    } catch (IOException ex) {
-        logger.error(ex);
-    }
+    } catch (IOException ex) {
+        logger.error("Failed to parse CSV file: " + csvFilePath, ex);
+        throw new RuntimeException("Failed to process video learning events", ex);
+    }

Line range hint 93-95: Ensure consistent resource management.

The getStoryBookLearningEventsFromCsvBackup method doesn't close the CSVParser, unlike the extractVideoLearningEvents method. This could lead to resource leaks.

Add proper resource cleanup:

-        } catch (IOException ex) {
-            logger.error(ex);
-        }
+        } catch (IOException ex) {
+            logger.error("Failed to parse CSV file: " + csvFilePath, ex);
+            throw new RuntimeException("Failed to process storybook learning events", ex);
+        } finally {
+            if (csvParser != null) {
+                try {
+                    csvParser.close();
+                } catch (IOException e) {
+                    logger.error("Failed to close CSV parser", e);
+                }
+            }
+        }

Alternatively, use try-with-resources for both methods:

try (Reader reader = Files.newBufferedReader(csvFilePath);
     CSVParser csvParser = new CSVParser(reader, csvFormat)) {
    // Existing parsing logic
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f3810d8 and 8916fc0.

📒 Files selected for processing (1)
  • src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java (2 hunks)
🔇 Additional comments (1)
src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java (1)

142-144: Verify timezone handling in the analytics dashboard.

The change to UTC timezone storage might affect how timestamps are displayed in the analytics dashboard.

Let's verify the timestamp handling in the related JSP files:

✅ Verification successful

Based on the gathered information, I can now provide the final response:

The timezone change to UTC storage is safe and won't affect analytics display.

The analytics views are using simple date formatting patterns ("yyyy-MM-dd" and "yyyy-MM-dd HH:mm:ss") without explicit timezone handling, which means they'll use the server's default timezone for display. The controllers use basic SimpleDateFormat for aggregating monthly statistics, which also adapts to the server's timezone automatically. Since the timestamps are properly stored in UTC, they will be correctly converted to the server's timezone when displayed.

  • JSP files use <fmt:formatDate> which automatically handles timezone conversion
  • Analytics controllers (WordLearningEventListController and StoryBookLearningEventListController) use timezone-agnostic formatting
  • No explicit timezone conversions are needed in the display layer
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for timestamp formatting in analytics-related JSP files
fd -e jsp -x rg -l "timestamp|Calendar|Date|format" {} \;

# Search for any timezone-related configuration
fd . -e xml -e properties -e java -x rg -l "timezone|TimeZone" {} \;

Length of output: 2017


Script:

#!/bin/bash
# Let's check the timestamp handling in analytics JSP files
rg -A 5 "timestamp|Calendar|Date|format" ./src/main/webapp/WEB-INF/jsp/analytics/word-learning-event/list.jsp ./src/main/webapp/WEB-INF/jsp/analytics/storybook-learning-event/list.jsp ./src/main/webapp/WEB-INF/jsp/analytics/letter-learning-event/list.jsp

# Check for any timezone-specific formatting or display logic in Java files
ast-grep --pattern 'class $_ {
  $$$
  format($$$) {
    $$$
  }
  $$$
}'

# Check for any date/time formatting utilities
rg -l "SimpleDateFormat|DateTimeFormatter|format.*time" --type java

Length of output: 5625


Script:

#!/bin/bash
# Let's check the timestamp handling in the analytics controllers
rg -A 5 "timestamp|Calendar|Date|format" src/main/java/ai/elimu/web/analytics/StoryBookLearningEventListController.java src/main/java/ai/elimu/web/analytics/WordLearningEventListController.java

# Check if there's any timezone conversion or handling in these controllers
rg "TimeZone|ZoneId|timezone" src/main/java/ai/elimu/web/analytics/

# Check for any global date/time formatting configuration
fd . -e xml -e properties -x rg "format.*date|timezone|TimeZone" {} \;

Length of output: 8022

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 30, 2024
@nya-elimu nya-elimu merged commit 00818e2 into main Oct 30, 2024
12 of 14 checks passed
@nya-elimu nya-elimu deleted the 1894-update-analytics-dashboard branch October 30, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add VideoLearningEvent
2 participants