Skip to content

refactor(task): calculate frequency of words, letter-sounds, letters, sounds#2305

Merged
jo-elimu merged 4 commits intomainfrom
2192-letter-frequency-missing-for-thai-vowels
Jul 21, 2025
Merged

refactor(task): calculate frequency of words, letter-sounds, letters, sounds#2305
jo-elimu merged 4 commits intomainfrom
2192-letter-frequency-missing-for-thai-vowels

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 21, 2025
@jo-elimu jo-elimu requested a review from a team as a code owner July 21, 2025 06:40
@jo-elimu jo-elimu requested review from SnehaHS65, Souvik-Cyclic and jpatel3 and removed request for a team July 21, 2025 06:40
@jo-elimu jo-elimu linked an issue Jul 21, 2025 that may be closed by this pull request
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

The changes revise scheduled execution times for letter and sound usage count schedulers, refactor frequency calculation logic in letter, letter-sound, sound, and word usage count schedulers to simplify frequency accumulation and update usage counts directly by entity IDs, and correct a comment in the word list controller. No public API signatures were modified.

Changes

File(s) Change Summary
src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java Changed scheduled execution time from 06:15 to 06:10 daily; revised frequency calculation to count letter-sound occurrences without weighting; removed debug logs and unused imports; added class-level comment.
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java Changed scheduled execution time from 06:15 to 06:20 daily; replaced StoryBook-based frequency calculation with iteration over LetterSounds and Letters; changed frequency map key type to Letter ID; removed related imports and logging.
src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java Refactored word usage count calculation to iterate directly over StoryBookParagraphs and count Word entity occurrences by ID; simplified update logic; removed unused imports and adjusted logging.
src/main/java/ai/elimu/tasks/SoundUsageCountScheduler.java Simplified class-level Javadoc; renamed frequency map variable; removed logging; preserved frequency accumulation and update logic.
src/main/java/ai/elimu/web/content/word/WordListController.java Corrected comment to state extraction of word frequency distribution instead of letter frequency; no logic changes.
pom-dependency-tree.txt Updated project artifact version from 2.6.101-SNAPSHOT to 2.6.102-SNAPSHOT; no other dependency changes.

Estimated code review effort

3 (90–240 minutes)


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d4ec60 and 348011d.

📒 Files selected for processing (3)
  • src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (2 hunks)
  • src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (2 hunks)
  • src/main/java/ai/elimu/tasks/SoundUsageCountScheduler.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java
  • src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java
  • src/main/java/ai/elimu/tasks/SoundUsageCountScheduler.java
✨ 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1ff3c and 1e71882.

📒 Files selected for processing (4)
  • src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (1 hunks)
  • src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (1 hunks)
  • src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java (2 hunks)
  • src/main/java/ai/elimu/web/content/word/WordListController.java (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
src/main/java/ai/elimu/web/content/word/WordListController.java (2)

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.

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.

src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (1)

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.

src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java (1)

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.

src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (1)

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.

🔇 Additional comments (6)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (1)

38-38: LGTM - Well-coordinated scheduling adjustment

The schedule time change from 06:15 to 06:20 aligns well with the broader scheduling coordination across usage count tasks (Words at 06:00, Letter Sounds at 06:10, Letters at 06:20), which helps prevent resource contention and ensures proper execution order.

src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (1)

28-28: LGTM - Coordinated scheduling improvement

The schedule time change from 06:15 to 06:10 is part of the well-planned scheduling coordination that sequences usage count calculations appropriately.

src/main/java/ai/elimu/web/content/word/WordListController.java (1)

53-53: LGTM - Accurate comment correction

The comment correction from "letter frequency distribution" to "word frequency distribution" accurately reflects what the code actually does, improving documentation clarity.

src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java (3)

7-7: LGTM - Good simplification by removing unused imports

The removal of unused imports (StoryBook-related classes, Language, ConfigHelper, WordFrequencyHelper) reflects the cleaner refactored approach.

Also applies to: 13-13


18-18: LGTM - Accurate documentation update

The comment correctly describes the new approach of iterating directly over storybook paragraphs rather than the previous hierarchical traversal.


52-55: LGTM - Simplified update logic

The direct update approach using the frequency map is much cleaner than the previous implementation, eliminating the need to re-fetch Word entities by text.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 21, 2025

Codecov Report

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

Project coverage is 16.54%. Comparing base (d61950f) to head (348011d).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...java/ai/elimu/tasks/LetterUsageCountScheduler.java 0.00% 7 Missing ⚠️
...n/java/ai/elimu/tasks/WordUsageCountScheduler.java 0.00% 7 Missing ⚠️
.../java/ai/elimu/tasks/SoundUsageCountScheduler.java 0.00% 6 Missing ⚠️
...ai/elimu/tasks/LetterSoundUsageCountScheduler.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2305      +/-   ##
============================================
- Coverage     16.56%   16.54%   -0.02%     
+ Complexity      455      452       -3     
============================================
  Files           258      258              
  Lines          7740     7687      -53     
  Branches        899      892       -7     
============================================
- Hits           1282     1272      -10     
+ Misses         6385     6341      -44     
- Partials         73       74       +1     

☔ 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.

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e71882 and 491e511.

📒 Files selected for processing (4)
  • src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (2 hunks)
  • src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (3 hunks)
  • src/main/java/ai/elimu/tasks/SoundUsageCountScheduler.java (3 hunks)
  • src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/main/java/ai/elimu/tasks/SoundUsageCountScheduler.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java
  • src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: venkatesh2k3
PR: elimu-ai/webapp#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.
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (1)

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.

🪛 GitHub Actions: Maven Build
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java

[error] 61-61: Compilation error: incompatible types: java.lang.String cannot be converted to java.lang.Long


[error] 66-66: Compilation error: incompatible types: java.lang.Long cannot be converted to java.lang.String

🪛 GitHub Actions: Maven Regression Tests (eng.elimu.ai)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java

[error] 61-61: Compilation error: incompatible types: java.lang.String cannot be converted to java.lang.Long


[error] 66-66: Compilation error: incompatible types: java.lang.Long cannot be converted to java.lang.String

🪛 GitHub Actions: Maven Regression Tests (tgl.elimu.ai)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java

[error] 61-61: Compilation error: incompatible types: java.lang.String cannot be converted to java.lang.Long


[error] 66-66: Compilation error: incompatible types: java.lang.Long cannot be converted to java.lang.String

🪛 GitHub Actions: Maven Regression Tests (hin.elimu.ai)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java

[error] 61-61: Compilation error: incompatible types: java.lang.String cannot be converted to java.lang.Long


[error] 66-66: Compilation error: incompatible types: java.lang.Long cannot be converted to java.lang.String

🪛 GitHub Actions: Maven Regression Tests (localhost)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java

[error] 61-61: Compilation error: incompatible types: java.lang.String cannot be converted to java.lang.Long


[error] 66-66: Compilation error: incompatible types: java.lang.Long cannot be converted to java.lang.String

🪛 GitHub Actions: Maven Regression Tests (tha.elimu.ai)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java

[error] 61-61: Compilation error: incompatible types: java.lang.String cannot be converted to java.lang.Long


[error] 66-66: Compilation error: incompatible types: java.lang.Long cannot be converted to java.lang.String

⏰ 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). (1)
  • GitHub Check: test_rest
🔇 Additional comments (1)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (1)

37-37: Scheduling time adjustment looks good

The cron expression and comment are correctly updated to reflect the new execution time.

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 (2)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (2)

35-37: Use Map#merge for tighter counting

You can shave a few lines and avoid the explicit getOrDefault by relying on merge:

-        frequencyMap.put(letter.getId(), frequencyMap.getOrDefault(letter.getId(), 0) + 1);
+        frequencyMap.merge(letter.getId(), 1, Integer::sum);

Minor, but keeps the intent crystal-clear.


41-45: Avoid unnecessary DB writes

letterDao.update(letter) is executed for every Letter, even when the usageCount hasn’t changed.
That can trigger redundant UPDATEs, extra version bumps, and cache invalidations.

for (Letter letter : letterDao.readAll()) {
    int newCount = frequencyMap.getOrDefault(letter.getId(), 0);
    if (letter.getUsageCount() != newCount) {
        letter.setUsageCount(newCount);
        letterDao.update(letter);
    }
}

Optionally wrap the loop in a single transaction or use a bulk update query for further savings.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 491e511 and 1d4ec60.

📒 Files selected for processing (4)
  • pom-dependency-tree.txt (1 hunks)
  • src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java (2 hunks)
  • src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (2 hunks)
  • src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pom-dependency-tree.txt
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/java/ai/elimu/tasks/WordUsageCountScheduler.java
  • src/main/java/ai/elimu/tasks/LetterSoundUsageCountScheduler.java
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: venkatesh2k3
PR: elimu-ai/webapp#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.
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (1)

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.

⏰ 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). (10)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: build (windows-latest, 21)
  • GitHub Check: test_rest
  • GitHub Check: build (windows-latest, 17)
  • GitHub Check: build (ubuntu-latest, 17)
  • GitHub Check: test_rest
  • GitHub Check: test_rest
  • GitHub Check: build (ubuntu-latest, 21)
  • GitHub Check: test_rest
🔇 Additional comments (1)
src/main/java/ai/elimu/tasks/LetterUsageCountScheduler.java (1)

31-32: Past type-mismatch fixed – looks good

Switching the frequency map to Map<Long, Integer> finally aligns the key type with letter.getId(), eliminating the compilation error noted in prior reviews.

@jo-elimu jo-elimu merged commit 50c5ccd into main Jul 21, 2025
19 of 20 checks passed
@jo-elimu jo-elimu deleted the 2192-letter-frequency-missing-for-thai-vowels branch July 21, 2025 07:29
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.

Letter frequency missing for Thai vowels

1 participant