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

Show sample for each Level type on ROBOT report #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

anitacaron
Copy link
Collaborator

@anitacaron anitacaron commented Oct 10, 2024

Fixes #133

Preview using CDAO as example

Screenshot 2024-10-10 at 18 03 55

Summary by CodeRabbit

  • Bug Fixes

    • Disabled the logic for evaluating and processing robot report files in the dashboard, ensuring smoother operations without unnecessary processing.
  • New Features

    • Enhanced report processing with improved sampling mechanisms based on error levels.
    • Updated HTML output to reflect filtered report data.
  • Chores

    • Commented out logging and post-processing commands in the dashboard configuration for streamlined file handling.

@anitacaron anitacaron self-assigned this Oct 10, 2024
@anitacaron
Copy link
Collaborator Author

@coderabbitai full review

Copy link

coderabbitai bot commented Oct 14, 2024

✅ Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes involve modifications to the Makefile, util/create_report_html.py, and util/dashboard_config.py. The Makefile disables a target related to processing robot report files. Enhancements in create_report_html.py improve report processing with a sampling mechanism based on error levels, and updates the HTML output and error handling. In dashboard_config.py, logging and command execution for post-processing dashboard files are commented out, disabling that functionality.

Changes

File Change Summary
Makefile Commented out target truncate_reports_for_github, disabling report processing logic.
util/create_report_html.py Enhanced main function with a sampling mechanism for error levels, updated HTML output, and error handling.
util/dashboard_config.py Commented out logging and command execution for post-processing dashboard files.

Assessment against linked issues

Objective Addressed Explanation
Include all ERROR, increase rows to 1000, and strip out owlclassexpression hashcodes (#133)
Stratify the cut-off by shrinking large groups where necessary (#133) No implementation for stratifying cut-off.

Poem

In the garden where reports bloom bright,
We sample errors, a wondrous sight.
With lines truncated, the data flows,
A dashboard dance, where knowledge grows.
Hopping through code, with joy we play,
Celebrating changes, hip-hip-hooray! 🐇✨


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

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

🧹 Outside diff range and nitpick comments (1)
Makefile (1)

Line range hint 1-27: Overall impact on Makefile is minimal and aligned with objectives.

The removal of the truncate_reports_for_github target is the only change in this Makefile. This modification doesn't affect the execution of other targets or introduce any new dependencies. The overall structure for building and managing the dashboard remains intact.

Consider updating any documentation that might reference the removed truncate_reports_for_github target to reflect this change. This will help maintain consistency between the code and its documentation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ea99dd2 and 32c9dbb.

📒 Files selected for processing (3)
  • Makefile (1 hunks)
  • util/create_report_html.py (1 hunks)
  • util/dashboard_config.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
util/dashboard_config.py (1)

78-79: Verify the impact of disabling GitHub post-processing

The lines for post-processing files for GitHub have been commented out. This change may affect how the dashboard files are handled after their generation.

To ensure this change doesn't negatively impact the workflow, please run the following script:

This script will help identify any potential issues arising from the removal of this functionality. Please review the results to ensure that no critical GitHub-related processing is being overlooked.

Consider the following points:

  1. If this change is intentional, update any documentation that might reference the GitHub post-processing step.
  2. Ensure that any downstream processes or scripts that may have depended on this post-processing step are updated accordingly.
  3. If this is a temporary change for debugging or testing purposes, consider using a feature flag instead of commenting out the code to make it easier to re-enable in the future.
✅ Verification successful

Verified: Disabling GitHub post-processing has no adverse effects

The commented-out lines for post-processing files for GitHub in util/dashboard_config.py do not impact the current functionality:

  • The truncate_reports_for_github make target does not exist in the Makefile, indicating that this functionality is not in use.
  • Other GitHub-related references found are confined to comments and documentation, posing no risk to the workflow.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any references to the truncate_reports_for_github make target

# Test 1: Search for references to the make target in Python files
echo "Searching for references to truncate_reports_for_github in Python files:"
rg --type python "truncate_reports_for_github"

# Test 2: Check if the make target still exists in the Makefile
echo "Checking if the truncate_reports_for_github target exists in the Makefile:"
rg --type make "^truncate_reports_for_github:"

# Test 3: Look for any GitHub-related processing in other parts of the codebase
echo "Searching for other GitHub-related processing:"
rg --type python "github"

Length of output: 600


Script:

#!/bin/bash
# Description: Re-verify references to truncate_reports_for_github and GitHub-related processing

# Test 1: Search for references to the make target in Python files
echo "Searching for references to truncate_reports_for_github in Python files:"
rg "truncate_reports_for_github" -- '*.py'

# Test 2: Check if the truncate_reports_for_github target exists in the Makefile
echo "Checking if the truncate_reports_for_github target exists in the Makefile:"
rg "^truncate_reports_for_github:" Makefile

# Test 3: Look for any GitHub-related processing in other parts of the codebase
echo "Searching for other GitHub-related processing in Python files:"
rg "github" -- '*.py'

Length of output: 649


Script:

#!/bin/bash
# Description: Re-verify references to truncate_reports_for_github and GitHub-related processing

# Test 1: Search for references to the make target in Python files
echo "Searching for references to truncate_reports_for_github in Python files:"
rg "truncate_reports_for_github" --glob "*.py"

# Test 2: Check if the truncate_reports_for_github target exists in the Makefile
echo "Checking if the truncate_reports_for_github target exists in the Makefile:"
rg "^truncate_reports_for_github:" Makefile

# Test 3: Look for any GitHub-related processing in Python files
echo "Searching for other GitHub-related processing in Python files:"
rg "github" --glob "*.py"

Length of output: 8422


Script:

#!/bin/bash
# Description: Re-verify references to truncate_reports_for_github and GitHub-related processing

# Test 1: Search for references to the make target in Python files
echo "Searching for references to truncate_reports_for_github in Python files:"
rg "truncate_reports_for_github" --glob "*.py"

# Test 2: Check if the truncate_reports_for_github target exists in the Makefile
echo "Checking if the truncate_reports_for_github target exists in the Makefile:"
rg "^truncate_reports_for_github:" Makefile

# Test 3: Look for any GitHub-related processing in Python files
echo "Searching for other GitHub-related processing in Python files:"
rg "github" --glob "*.py"

Length of output: 8422

Comment on lines +21 to +27
# truncate_reports_for_github:
# $(eval REPORTS := $(wildcard dashboard/*/robot_report.tsv))
# for REP in $(REPORTS); do \
# touch $$REP; \
# cat $$REP | head -$(REPORT_LENGTH_LIMIT) > $$REP.tmp; \
# mv $$REP.tmp $$REP; \
# done
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Issue Detected: robot_report.tsv is empty.

The robot_report.tsv file located at the repository root has a size of 0 bytes, indicating that no robot reports are being generated. This affects the objective of displaying ERROR samples as intended by the PR.

  • Verify the process that generates robot_report.tsv to ensure it is functioning correctly.
🔗 Analysis chain

Approved: Removal of report truncation aligns with PR objectives.

Commenting out the truncate_reports_for_github target is in line with the PR objective to show more samples in the ROBOT report. This change will allow the full robot reports to be preserved, potentially showing all ERROR samples as requested in the linked issue #133.

Consider monitoring the impact on file sizes of the robot reports. If they become too large, you might need to implement a more selective sampling method. To verify the current file sizes, you can run:

This will help ensure that the removal of truncation doesn't lead to excessively large files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the size of robot report files
find dashboard -name "robot_report.tsv" -exec du -h {} +

Length of output: 103


Script:

#!/bin/bash
# Search for all robot_report.tsv files in the repository
find . -type f -name "robot_report.tsv"

Length of output: 58


Script:

#!/bin/bash
# Check the size of the robot_report.tsv file
du -h ./robot_report.tsv

Length of output: 47

Comment on lines +62 to +66
report_filtered = report.groupby(by="Level")[
["Level", "Rule Name", "Subject", "Property", "Value"]
].apply(
lambda x: x.sample(calculate_sample_size(x, rest))
).reset_index(drop=True)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure all required columns are present before selecting

When selecting columns ["Level", "Rule Name", "Subject", "Property", "Value"], ensure that these columns exist in the report DataFrame. If any of these columns are missing, it will raise a KeyError.

Consider adding a check for missing columns:

required_columns = ["Level", "Rule Name", "Subject", "Property", "Value"]
missing_columns = [col for col in required_columns if col not in report.columns]
if missing_columns:
    raise KeyError(f"Missing columns in report: {missing_columns}")

Comment on lines +75 to +76
except Exception as e:
print(e)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve exception handling and logging

Catching the broad Exception class is discouraged as it may catch unexpected exceptions and hinder debugging. Additionally, using print(e) is not ideal for error logging. Consider catching specific exceptions and using the logging module for better error reporting.

Proposed fix:

Import the logging module and configure it:

import logging

logging.basicConfig(level=logging.ERROR)

Update the exception handling:

- except Exception as e:
-     print(e)
+ except pd.errors.EmptyDataError as e:
+     logging.error(f"Empty data error: {e}")
+ except FileNotFoundError as e:
+     logging.error(f"File not found: {e}")
+ except Exception as e:
+     logging.error(f"An unexpected error occurred: {e}")

report_filtered = report.head(args.limitlines)

if len(report_filtered) > args.limitlines:
report_filtered.to_csv(args.report, sep="\t", index=False)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Cannot write to a file opened in read mode

At line 73, you're attempting to write to args.report, which was opened in read mode ('r'). This will raise an error. You need to open the file in write mode or write to a different output file.

Proposed fix:

Option 1: Open the report file in read-write mode

Modify the argument parser:

- parser.add_argument('report',
-                     type=argparse.FileType('r'),
-                     help='TSV report to convert to HTML')
+ parser.add_argument('report',
+                     type=argparse.FileType('r+'),
+                     help='TSV report to convert to HTML')

Option 2: Specify a separate output file for the filtered report

Add a new argument for the output report file:

- parser.add_argument('report',
-                     type=argparse.FileType('r'),
-                     help='TSV report to convert to HTML')
+ parser.add_argument('report_input',
+                     type=argparse.FileType('r'),
+                     help='TSV report to convert to HTML')
+ parser.add_argument('report_output',
+                     type=argparse.FileType('w'),
+                     help='Output filtered report TSV file')

Adjust the code accordingly:

- report_filtered.to_csv(args.report, sep="\t", index=False)
+ report_filtered.to_csv(args.report_output, sep="\t", index=False)

Committable suggestion was skipped due to low confidence.

Comment on lines +51 to +52
if error_count_level["ERROR"] < args.limitlines:
rest = args.limitlines - error_count_level["ERROR"]
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle KeyError when accessing 'ERROR' in error_count_level

Currently, the code assumes that 'ERROR' is always a key in error_count_level. If there are no entries with the level 'ERROR', this will raise a KeyError. To prevent this, consider using the get method with a default value.

Proposed fix:

- if error_count_level["ERROR"] < args.limitlines:
-     rest = args.limitlines - error_count_level["ERROR"]
+ error_count_error = error_count_level.get("ERROR", 0)
+ if error_count_error < args.limitlines:
+     rest = args.limitlines - error_count_error
📝 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
if error_count_level["ERROR"] < args.limitlines:
rest = args.limitlines - error_count_level["ERROR"]
error_count_error = error_count_level.get("ERROR", 0)
if error_count_error < args.limitlines:
rest = args.limitlines - error_count_error

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.

[ROBOT report] Show a sample of each rule type
1 participant