Skip to content

fix: prevent number format exception for number learning events#2308

Merged
jo-elimu merged 1 commit intomainfrom
2307-numberformatexception-in-numberlearningeventimportscheduler
Jul 22, 2025
Merged

fix: prevent number format exception for number learning events#2308
jo-elimu merged 1 commit intomainfrom
2307-numberformatexception-in-numberlearningeventimportscheduler

Conversation

@jo-elimu
Copy link
Copy Markdown
Member

Issue Number

Purpose

Technical Details

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 Jul 22, 2025
@jo-elimu jo-elimu requested a review from a team as a code owner July 22, 2025 10:02
@jo-elimu jo-elimu requested review from AshishBagdane, alexander-kuruvilla and eymaal and removed request for a team July 22, 2025 10:02
@jo-elimu jo-elimu linked an issue Jul 22, 2025 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 22, 2025

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 16.93%. Comparing base (bc6f7e8) to head (01f8876).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...i/elimu/util/csv/CsvAnalyticsExtractionHelper.java 0.00% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2308      +/-   ##
============================================
+ Coverage     16.48%   16.93%   +0.44%     
- Complexity      453      455       +2     
============================================
  Files           260      260              
  Lines          7711     7713       +2     
  Branches        892      894       +2     
============================================
+ Hits           1271     1306      +35     
+ Misses         6366     6325      -41     
- Partials         74       82       +8     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

Null and blank value checks were added to the extraction logic for NumberLearningEvent fields in the CSV analytics helper, preventing parsing errors when CSV fields are empty. A new unit test was introduced to verify correct handling of missing numberSymbol and numberId fields in CSV input. The project version was incremented.

Changes

File(s) Change Summary
pom-dependency-tree.txt Updated main artifact version from 2.6.103-SNAPSHOT to 2.6.105-SNAPSHOT.
src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java Added null/blank checks before setting numberSymbol and numberId fields during NumberLearningEvent extraction.
src/test/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelperTest.java Added test for extracting NumberLearningEvent from CSV with missing numberSymbol and numberId fields.

Sequence Diagram(s)

sequenceDiagram
    participant Test as CsvAnalyticsExtractionHelperTest
    participant Helper as CsvAnalyticsExtractionHelper
    participant CSV as CSV File

    Test->>Helper: extractNumberLearningEvents(CSV)
    Helper->>CSV: Read next record
    alt number_symbol or number_id is blank
        Helper-->>Helper: Skip setting numberSymbol/numberId
    else
        Helper-->>Helper: Parse and set numberSymbol/numberId
    end
    Helper-->>Test: Return extracted NumberLearningEvent(s)
Loading

Estimated code review effort

2 (~15 minutes)

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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
Copy Markdown
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

🧹 Nitpick comments (1)
src/test/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelperTest.java (1)

245-245: Update or remove outdated TODO comment.

The TODO comment "// TODO: number learning events" should be updated or removed since the test method testExtractNumberLearningEvents_v4000028() was just added above, providing coverage for number learning events.

Apply this diff to remove the outdated TODO:

-    // TODO: number learning events
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32f21e5 and 01f8876.

⛔ Files ignored due to path filters (1)
  • src/test/resources/ai/elimu/util/csv/5b7c682a12ecbe2e_4000028_number-learning-events_2025-07-04.csv is excluded by !**/*.csv, !**/*.csv
📒 Files selected for processing (3)
  • pom-dependency-tree.txt (1 hunks)
  • src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java (1 hunks)
  • src/test/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelperTest.java (2 hunks)
🧠 Learnings (4)
📓 Common learnings
Learnt from: jo-elimu
PR: elimu-ai/webapp#2237
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:287-288
Timestamp: 2025-06-09T06:52:22.910Z
Learning: VideoLearningEvents in CsvAnalyticsExtractionHelper never used the "time" column name and always use "timestamp", unlike other event types (LetterSoundLearningEvent, WordAssessmentEvent, WordLearningEvent, StoryBookLearningEvent) which need conditional logic to handle both "time" (for versions < 3.4.0) and "timestamp" (for versions >= 3.4.0) column names. This is because VideoLearningEvents were introduced after the schema change.
Learnt from: jo-elimu
PR: elimu-ai/webapp#2269
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:80-88
Timestamp: 2025-06-20T05:28:00.962Z
Learning: In CsvAnalyticsExtractionHelper.java, the CSV columns for research_experiment and experiment_group contain integer values (0 or 1) that need to be mapped to enum ordinals by adding 1 to the CSV value (0 maps to ordinal 1, 1 maps to ordinal 2).
pom-dependency-tree.txt (1)

Learnt from: jo-elimu
PR: elimu-ai/webapp#0
File: :0-0
Timestamp: 2025-05-03T08:01:30.217Z
Learning: The elimu-ai/webapp repository has a dependency on ai.elimu:model (version 2.0.97) that provides shared model classes and enums. The Language enum should be imported from ai.elimu.model.v2.enums.Language instead of creating local duplicates.

src/test/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelperTest.java (4)

Learnt from: jo-elimu
PR: #2269
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:80-88
Timestamp: 2025-06-20T05:28:00.962Z
Learning: In CsvAnalyticsExtractionHelper.java, the CSV columns for research_experiment and experiment_group contain integer values (0 or 1) that need to be mapped to enum ordinals by adding 1 to the CSV value (0 maps to ordinal 1, 1 maps to ordinal 2).

Learnt from: jo-elimu
PR: #2237
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:287-288
Timestamp: 2025-06-09T06:52:22.910Z
Learning: VideoLearningEvents in CsvAnalyticsExtractionHelper never used the "time" column name and always use "timestamp", unlike other event types (LetterSoundLearningEvent, WordAssessmentEvent, WordLearningEvent, StoryBookLearningEvent) which need conditional logic to handle both "time" (for versions < 3.4.0) and "timestamp" (for versions >= 3.4.0) column names. This is because VideoLearningEvents were introduced after the schema change.

Learnt from: venkatesh2k3
PR: #1682
File: src/main/java/ai/elimu/dao/LetterSoundContributionEventDao.java:13-13
Timestamp: 2024-07-06T17:37:44.413Z
Learning: In the LetterSoundContributionEventDao.java file, the method signatures should use LetterSoundContributionEvent instead of LetterSoundCorrespondenceContributionEvent to maintain consistency with the renaming of entities.

Learnt from: jo-elimu
PR: elimu-ai/webapp#0
File: :0-0
Timestamp: 2025-05-03T08:01:30.217Z
Learning: The elimu-ai/webapp repository has a dependency on ai.elimu:model (version 2.0.97) that provides shared model classes and enums. The Language enum should be imported from ai.elimu.model.v2.enums.Language instead of creating local duplicates.

src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java (3)

Learnt from: jo-elimu
PR: #2237
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:287-288
Timestamp: 2025-06-09T06:52:22.910Z
Learning: VideoLearningEvents in CsvAnalyticsExtractionHelper never used the "time" column name and always use "timestamp", unlike other event types (LetterSoundLearningEvent, WordAssessmentEvent, WordLearningEvent, StoryBookLearningEvent) which need conditional logic to handle both "time" (for versions < 3.4.0) and "timestamp" (for versions >= 3.4.0) column names. This is because VideoLearningEvents were introduced after the schema change.

Learnt from: jo-elimu
PR: #2269
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:80-88
Timestamp: 2025-06-20T05:28:00.962Z
Learning: In CsvAnalyticsExtractionHelper.java, the CSV columns for research_experiment and experiment_group contain integer values (0 or 1) that need to be mapped to enum ordinals by adding 1 to the CSV value (0 maps to ordinal 1, 1 maps to ordinal 2).

Learnt from: jo-elimu
PR: #2284
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:242-245
Timestamp: 2025-06-25T07:56:10.189Z
Learning: In Apache Commons CSV, the CSVRecord.isSet(String name) method returns true only if the column exists AND the value is not null. This means it already handles both column existence and non-null value validation, making it safe to use for conditional field processing without additional empty/blank checks.

🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: jo-elimu
PR: elimu-ai/webapp#2237
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:287-288
Timestamp: 2025-06-09T06:52:22.910Z
Learning: VideoLearningEvents in CsvAnalyticsExtractionHelper never used the "time" column name and always use "timestamp", unlike other event types (LetterSoundLearningEvent, WordAssessmentEvent, WordLearningEvent, StoryBookLearningEvent) which need conditional logic to handle both "time" (for versions < 3.4.0) and "timestamp" (for versions >= 3.4.0) column names. This is because VideoLearningEvents were introduced after the schema change.
Learnt from: jo-elimu
PR: elimu-ai/webapp#2269
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:80-88
Timestamp: 2025-06-20T05:28:00.962Z
Learning: In CsvAnalyticsExtractionHelper.java, the CSV columns for research_experiment and experiment_group contain integer values (0 or 1) that need to be mapped to enum ordinals by adding 1 to the CSV value (0 maps to ordinal 1, 1 maps to ordinal 2).
pom-dependency-tree.txt (1)

Learnt from: jo-elimu
PR: elimu-ai/webapp#0
File: :0-0
Timestamp: 2025-05-03T08:01:30.217Z
Learning: The elimu-ai/webapp repository has a dependency on ai.elimu:model (version 2.0.97) that provides shared model classes and enums. The Language enum should be imported from ai.elimu.model.v2.enums.Language instead of creating local duplicates.

src/test/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelperTest.java (4)

Learnt from: jo-elimu
PR: #2269
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:80-88
Timestamp: 2025-06-20T05:28:00.962Z
Learning: In CsvAnalyticsExtractionHelper.java, the CSV columns for research_experiment and experiment_group contain integer values (0 or 1) that need to be mapped to enum ordinals by adding 1 to the CSV value (0 maps to ordinal 1, 1 maps to ordinal 2).

Learnt from: jo-elimu
PR: #2237
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:287-288
Timestamp: 2025-06-09T06:52:22.910Z
Learning: VideoLearningEvents in CsvAnalyticsExtractionHelper never used the "time" column name and always use "timestamp", unlike other event types (LetterSoundLearningEvent, WordAssessmentEvent, WordLearningEvent, StoryBookLearningEvent) which need conditional logic to handle both "time" (for versions < 3.4.0) and "timestamp" (for versions >= 3.4.0) column names. This is because VideoLearningEvents were introduced after the schema change.

Learnt from: venkatesh2k3
PR: #1682
File: src/main/java/ai/elimu/dao/LetterSoundContributionEventDao.java:13-13
Timestamp: 2024-07-06T17:37:44.413Z
Learning: In the LetterSoundContributionEventDao.java file, the method signatures should use LetterSoundContributionEvent instead of LetterSoundCorrespondenceContributionEvent to maintain consistency with the renaming of entities.

Learnt from: jo-elimu
PR: elimu-ai/webapp#0
File: :0-0
Timestamp: 2025-05-03T08:01:30.217Z
Learning: The elimu-ai/webapp repository has a dependency on ai.elimu:model (version 2.0.97) that provides shared model classes and enums. The Language enum should be imported from ai.elimu.model.v2.enums.Language instead of creating local duplicates.

src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java (3)

Learnt from: jo-elimu
PR: #2237
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:287-288
Timestamp: 2025-06-09T06:52:22.910Z
Learning: VideoLearningEvents in CsvAnalyticsExtractionHelper never used the "time" column name and always use "timestamp", unlike other event types (LetterSoundLearningEvent, WordAssessmentEvent, WordLearningEvent, StoryBookLearningEvent) which need conditional logic to handle both "time" (for versions < 3.4.0) and "timestamp" (for versions >= 3.4.0) column names. This is because VideoLearningEvents were introduced after the schema change.

Learnt from: jo-elimu
PR: #2269
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:80-88
Timestamp: 2025-06-20T05:28:00.962Z
Learning: In CsvAnalyticsExtractionHelper.java, the CSV columns for research_experiment and experiment_group contain integer values (0 or 1) that need to be mapped to enum ordinals by adding 1 to the CSV value (0 maps to ordinal 1, 1 maps to ordinal 2).

Learnt from: jo-elimu
PR: #2284
File: src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java:242-245
Timestamp: 2025-06-25T07:56:10.189Z
Learning: In Apache Commons CSV, the CSVRecord.isSet(String name) method returns true only if the column exists AND the value is not null. This means it already handles both column existence and non-null value validation, making it safe to use for conditional field processing without additional empty/blank checks.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: build (macos-latest, 17)
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (ubuntu-latest, 17)
  • GitHub Check: build (macos-latest, 21)
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: test_rest
🔇 Additional comments (4)
src/main/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelper.java (1)

341-349: LGTM! Proper null/blank validation added for optional fields.

The addition of StringUtils.isNotBlank() checks before parsing and setting numberSymbol and numberId correctly prevents NumberFormatException when these CSV fields contain empty or null values. This implementation is consistent with the existing pattern used for other optional fields throughout the file.

pom-dependency-tree.txt (1)

1-1: Appropriate version increment for bug fix.

The version increment from 2.6.103-SNAPSHOT to 2.6.105-SNAPSHOT is appropriate for this bug fix addressing the number format exception issue.

src/test/java/ai/elimu/util/csv/CsvAnalyticsExtractionHelperTest.java (2)

20-20: LGTM! Import added for the new test.

The import for NumberLearningEvent is correctly added to support the new test method.


193-216: Excellent test coverage for the bug fix.

This test method comprehensively validates the fix by:

  • Testing extraction from a CSV file with blank numberSymbol and numberId fields
  • Asserting that these fields remain null when blank (preventing the original NumberFormatException)
  • Validating that all other fields are correctly extracted

The test correctly demonstrates that the extraction logic now handles missing optional fields gracefully.

@jo-elimu jo-elimu merged commit 47cf322 into main Jul 22, 2025
19 of 20 checks passed
@jo-elimu jo-elimu deleted the 2307-numberformatexception-in-numberlearningeventimportscheduler branch July 22, 2025 10:36
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.

NumberFormatException in NumberLearningEventImportScheduler

1 participant