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

Visualize chapter count, paragraph count, word count per reading level #24

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

jo-elimu
Copy link
Member

@jo-elimu jo-elimu commented Sep 12, 2024

Which issue does this PR address?

#21

Summary by CodeRabbit

  • New Features

    • Introduced exploratory data analysis (EDA) capabilities for storybooks, including visualizations of reading levels and various attributes.
    • Added a new metric for average word length in storybooks, enhancing text analysis.
    • Integrated Matplotlib for improved data visualization features.
  • Documentation

    • Added a README file with visualizations for text metrics such as chapter count and word count.
  • Bug Fixes

    • Improved commit process to include PNG files generated during data preparation.
  • Tests

    • Enhanced testing coverage for the new average word length functionality.

@jo-elimu jo-elimu self-assigned this Sep 12, 2024
@jo-elimu jo-elimu requested a review from a team as a code owner September 12, 2024 05:56
@jo-elimu jo-elimu linked an issue Sep 12, 2024 that may be closed by this pull request
1 task
Copy link

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes involve modifications to multiple files within the project, primarily enhancing data processing and visualization capabilities. Key updates include the addition of a new column for average word length in the data preprocessing script, the introduction of exploratory data analysis (EDA) functionalities, and the inclusion of PNG files in the Git commit process. A new utility function for calculating average word length is also added, along with corresponding tests to ensure its accuracy. Additionally, a README file is created to document visualizations related to text metrics, and a new dependency for Matplotlib is introduced.

Changes

File Change Summary
.github/workflows/pmml-nightly.yml Added git add step1_prepare/*.png to include PNG files in the commit process.
pmml/run_all_steps.py Added import statement for step1_prepare.step1_4_eda, incorporating EDA into the processing pipeline.
pmml/step1_prepare/README.md Introduced documentation for data visualizations related to text metrics.
pmml/step1_prepare/step1_2_preprocess_data.py Added avg_word_length column to storybooks_dataframe, calculating average word length.
pmml/step1_prepare/step1_4_eda.py Created script for EDA, generating scatter plots and histograms for storybook attributes.
pmml/utils/chapters_utils.py Added get_avg_word_length function to calculate average word length from chapter data.
pmml/utils/test_chapters_utils.py Added tests for get_avg_word_length function to cover edge cases.
pmml/requirements.txt Added new dependency matplotlib==3.8.2 for data visualization capabilities.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7154433 and 6ea7a38.

Files selected for processing (1)
  • pmml/requirements.txt (1 hunks)
Additional comments not posted (1)
pmml/requirements.txt (1)

1-1: LGTM!

The addition of the Matplotlib dependency aligns with the PR objectives of implementing a visualization feature. Pinning the version to 3.8.2 is a good practice to ensure reproducibility and avoid potential issues with future updates. The existing dependencies remain unchanged, indicating that the addition of Matplotlib does not introduce any conflicts or require updates to the existing dependencies.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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

@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: 6

Outside diff range and nitpick comments (1)
pmml/step1_prepare/step1_4_eda.py (1)

6-7: Consider using a configuration file or command-line argument for the CSV file path.

Instead of hardcoding the CSV file path, consider using a configuration file or command-line argument to make the script more flexible and reusable.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4c90ed4 and 7154433.

Files ignored due to path filters (9)
  • pmml/step1_prepare/step1_2_storybooks.csv is excluded by !**/*.csv
  • pmml/step1_prepare/step1_4_avg_word_length_hist.png is excluded by !**/*.png
  • pmml/step1_prepare/step1_4_avg_word_length_scatter.png is excluded by !**/*.png
  • pmml/step1_prepare/step1_4_chapter_count_hist.png is excluded by !**/*.png
  • pmml/step1_prepare/step1_4_chapter_count_scatter.png is excluded by !**/*.png
  • pmml/step1_prepare/step1_4_paragraph_count_hist.png is excluded by !**/*.png
  • pmml/step1_prepare/step1_4_paragraph_count_scatter.png is excluded by !**/*.png
  • pmml/step1_prepare/step1_4_word_count_hist.png is excluded by !**/*.png
  • pmml/step1_prepare/step1_4_word_count_scatter.png is excluded by !**/*.png
Files selected for processing (7)
  • .github/workflows/pmml-nightly.yml (1 hunks)
  • pmml/run_all_steps.py (1 hunks)
  • pmml/step1_prepare/README.md (1 hunks)
  • pmml/step1_prepare/step1_2_preprocess_data.py (2 hunks)
  • pmml/step1_prepare/step1_4_eda.py (1 hunks)
  • pmml/utils/chapters_utils.py (2 hunks)
  • pmml/utils/test_chapters_utils.py (1 hunks)
Additional context used
Markdownlint
pmml/step1_prepare/README.md

5-5: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


7-7: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


11-11: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


13-13: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


17-17: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


19-19: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


23-23: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


25-25: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

Ruff
pmml/run_all_steps.py

9-9: step1_prepare.step1_4_eda imported but unused

Remove unused import: step1_prepare.step1_4_eda

(F401)

Additional comments not posted (9)
.github/workflows/pmml-nightly.yml (1)

33-33: LGTM!

The addition of git add step1_prepare/*.png in the "Git Commit" step is a valid change that aligns with the PR objective and the AI-generated summary. Staging the PNG files from the step1_prepare directory ensures they are included in the nightly build commit, which is necessary for the visualization feature.

pmml/step1_prepare/step1_4_eda.py (2)

10-18: LGTM!

The scatter plots are generated correctly using the appropriate DataFrame columns, and the plots are saved as PNG files with meaningful file names.


20-32: LGTM!

The histograms are generated correctly using the appropriate DataFrame columns and reading levels, and the plots are saved as PNG files with meaningful file names. The legend is also added correctly to distinguish between the different reading levels.

pmml/step1_prepare/step1_2_preprocess_data.py (4)

19-19: LGTM!

The addition of the new column avg_word_length to the storybooks_dataframe and initializing it to 0 is appropriate. The actual values for this column will be populated later in the script.


33-35: LGTM!

The average word length is correctly calculated using the chapters_utils.get_avg_word_length utility function and the result is appropriately stored in the avg_word_length column of the storybooks_dataframe at the corresponding index.


39-39: LGTM!

Including the avg_word_length column in the list of columns to keep when dropping unnecessary columns from the storybooks_dataframe is necessary to ensure that it is part of the resulting dataset.


Line range hint 1-52: Excellent work!

The changes made to the step1_2_preprocess_data.py script are well-structured and enhance the data processing capabilities by introducing a new metric: the average word length of chapters in the storybooks. The script follows a logical flow and handles missing values, converts the reading level to a number, and correctly writes the resulting dataframe to a CSV file.

The addition of the avg_word_length column provides valuable insights into the text structure of the storybooks and will be useful for further analysis. The usage of the chapters_utils.get_avg_word_length utility function is appropriate and the calculated values are correctly stored in the corresponding column and index of the dataframe.

Overall, the changes are consistent with the summary of changes and improve the functionality of the script. Great job!

pmml/utils/test_chapters_utils.py (2)

84-91: LGTM!

The test function test_get_avg_word_length_when_no_paragraphs is well-implemented and covers an important edge case scenario where the JSON input contains chapters without any paragraphs. Asserting that the expected output is 0 ensures that the get_avg_word_length function correctly handles the absence of text.


93-100: LGTM!

The test function test_get_avg_word_length_when_single_paragraphs is well-implemented and covers a common scenario where the JSON input contains chapters with a single paragraph each. By calculating the average word length across these paragraphs and asserting the expected result, it ensures that the get_avg_word_length function correctly processes the text and returns the accurate average word length.

pmml/step1_prepare/README.md Show resolved Hide resolved
pmml/step1_prepare/README.md Show resolved Hide resolved
pmml/step1_prepare/README.md Show resolved Hide resolved
pmml/step1_prepare/README.md Show resolved Hide resolved
@@ -6,6 +6,7 @@
import step1_prepare.step1_1_download_data
import step1_prepare.step1_2_preprocess_data
import step1_prepare.step1_3_split_data
import step1_prepare.step1_4_eda
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Unused Import Detected: Review the necessity of step1_prepare.step1_4_eda

The module step1_prepare.step1_4_eda is imported in pmml/run_all_steps.py but is not used anywhere else in the codebase. This suggests that the import might be unnecessary. Please review whether this module should be integrated into the codebase or if the import can be safely removed to avoid maintenance overhead.

  • File: pmml/run_all_steps.py
  • Line: 9
Analysis chain

Verify the usage of the imported module.

The import statement for step1_prepare.step1_4_eda is syntactically correct. Based on the provided context, this import is intentional and aims to introduce exploratory data analysis (EDA) functionalities, which aligns with the objectives of enhancing the data processing and visualization capabilities.

To verify the correctness and effectiveness of the imported module, I recommend reviewing the implementation of step1_prepare.step1_4_eda and ensuring that it is being used appropriately within the codebase to achieve the desired EDA functionalities. Consider running the following script to check for the usage of the imported module:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the imported module `step1_prepare.step1_4_eda`.

# Test: Search for the usage of the module. Expect: At least one occurrence.
rg --type python -w $'step1_4_eda'

Length of output: 64


Script:

#!/bin/bash
# Description: Verify the usage of the imported module `step1_prepare.step1_4_eda`.

# Test: Search for the usage of the module. Expect: At least one occurrence.
rg --glob '*.py' -w 'step1_4_eda'

Length of output: 88

Tools
Ruff

9-9: step1_prepare.step1_4_eda imported but unused

Remove unused import: step1_prepare.step1_4_eda

(F401)

pmml/utils/chapters_utils.py Outdated Show resolved Hide resolved
@jo-elimu jo-elimu merged commit 4ac0027 into main Sep 12, 2024
6 checks passed
@jo-elimu jo-elimu deleted the 21-perform-exploratory-data-analysis-eda branch September 12, 2024 06:02
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.

Perform Exploratory Data Analysis (EDA)
1 participant