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

Fixed calculation of metrics for analytics reports #7144

Merged
merged 13 commits into from May 13, 2024
Merged

Conversation

azhavoro
Copy link
Contributor

@azhavoro azhavoro commented Nov 15, 2023

Motivation and context

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the accuracy of annotation speed metrics in analytics reports by adjusting how object count differences are calculated.
    • Adjusted functionality in get_track_count to calculate the difference in object count based on the previous count rather than the last entry count.
    • Added upgrade_report(report) function for upgrading report statistics.
    • Added forwards_func(apps, schema_editor) function for processing analytics reports.
    • Defined a Migration class with dependencies and operations for the migration.

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Merging #7144 (efb230d) into develop (9e605f4) will increase coverage by 0.00%.
Report is 1 commits behind head on develop.
The diff coverage is 9.09%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #7144   +/-   ##
========================================
  Coverage    83.45%   83.46%           
========================================
  Files          373      373           
  Lines        39739    39736    -3     
  Branches      3741     3741           
========================================
+ Hits         33163    33164    +1     
+ Misses        6576     6572    -4     
Components Coverage Δ
cvat-ui 79.24% <ø> (-0.01%) ⬇️
cvat-server 87.35% <9.09%> (+0.02%) ⬆️

azhavoro and others added 3 commits November 16, 2023 10:26
Co-authored-by: Maria Khrustaleva <maya17grd@gmail.com>
@bsekachev
Copy link
Member

@azhavoro
What is the status of the pull request? May we merge it?

Copy link
Contributor

coderabbitai bot commented May 10, 2024

Walkthrough

Enhancements to the project's analytics involve refining annotation speed metric calculations. Notably, adjustments in get_track_count of annotation_speed.py improve accuracy by considering previous counts for object differences and introduce new functions for report statistics upgrading and analytics report processing.

Changes

File Path Change Summary
changelog.d/20231117_132419_andrey_fix_analytics.md Fix for annotation speed metrics calculation in analytics reports.
cvat/apps/analytics_report/report/primary_metrics/annotation_speed.py Adjusted get_track_count to use previous count for object differences, added functions for report upgrading and processing.

Poem

🐇💻✨
In the land of code and wire,
A rabbit tweaked the numbers higher.
From past to present, counts align,
With every hop, the metrics shine.
🌟📊📈


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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 70ea131 and 4d73b85.
Files selected for processing (2)
  • changelog.d/20231117_132419_andrey_fix_analytics.md (1 hunks)
  • cvat/apps/analytics_report/report/primary_metrics/annotation_speed.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • changelog.d/20231117_132419_andrey_fix_analytics.md
Additional comments not posted (5)
cvat/apps/analytics_report/report/primary_metrics/annotation_speed.py (5)

112-112: Initialize previous_count to zero to handle cases where no previous data exists.


114-114: Ensure that the timestamp parsing and comparison are robust against potential timezone issues.


121-123: Accumulate previous_count correctly by summing up the values from previous entries.


129-129: Appending the difference in object count to data_series is a good approach for tracking changes over time.


129-129: Ensure the calculation of working time is accurate and consider edge cases where the time might span across days.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4d73b85 and f2a309d.
Files selected for processing (1)
  • cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py (1 hunks)
Additional comments not posted (2)
cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py (2)

5-21: Consider optimizing the nested loops and list operations in upgrade_report for better performance.

-            records_1 = list(reversed(statistic["data_series"]["object_count"]))
-            records_2 = records_1[1:]
-            for next, prev in zip(records_1, records_2):
+            for i in range(len(statistic["data_series"]["object_count"]) - 1, 0, -1):
+                statistic["data_series"]["object_count"][i]["value"] += statistic["data_series"]["object_count"][i-1]["value"]

Clarify the behavior when modified is False and None is returned. Consider returning the original report or explicitly handling this case.


42-48: The migration setup in the Migration class looks correct and well-defined.

Comment on lines 24 to 39
def forwards_func(apps, schema_editor):
AnalyticsReport = apps.get_model('analytics_report', 'AnalyticsReport')
reports = AnalyticsReport.objects.exclude(job_id=None).all()

objects_to_update = []
for report in reports:
try:
objects_to_update.append(upgrade_report(report))
except Exception:
# I do not expect exception to happen here
# but if it happened, let's just ignore the report
pass

objects_to_update = list(filter(lambda x: x is not None, objects_to_update))
AnalyticsReport.objects.bulk_update(objects_to_update, fields=['statistics'], batch_size=500)
AnalyticsReport.objects.filter(job_id=None).delete()
Copy link
Contributor

Choose a reason for hiding this comment

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

Add logging for exceptions in forwards_func to ensure transparency and easier debugging.

-            pass
+            logger.error(f"Failed to upgrade report: {report.id}", exc_info=True)

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.

Suggested change
def forwards_func(apps, schema_editor):
AnalyticsReport = apps.get_model('analytics_report', 'AnalyticsReport')
reports = AnalyticsReport.objects.exclude(job_id=None).all()
objects_to_update = []
for report in reports:
try:
objects_to_update.append(upgrade_report(report))
except Exception:
# I do not expect exception to happen here
# but if it happened, let's just ignore the report
pass
objects_to_update = list(filter(lambda x: x is not None, objects_to_update))
AnalyticsReport.objects.bulk_update(objects_to_update, fields=['statistics'], batch_size=500)
AnalyticsReport.objects.filter(job_id=None).delete()
def forwards_func(apps, schema_editor):
AnalyticsReport = apps.get_model('analytics_report', 'AnalyticsReport')
reports = AnalyticsReport.objects.exclude(job_id=None).all()
objects_to_update = []
for report in reports:
try:
objects_to_update.append(upgrade_report(report))
except Exception:
# I do not expect exception to happen here
# but if it happened, let's just ignore the report
logger.error(f"Failed to upgrade report: {report.id}", exc_info=True)
objects_to_update = list(filter(lambda x: x is not None, objects_to_update))
AnalyticsReport.objects.bulk_update(objects_to_update, fields=['statistics'], batch_size=500)
AnalyticsReport.objects.filter(job_id=None).delete()

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f2a309d and 96c8d94.
Files selected for processing (1)
  • cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 96c8d94 and e031c2b.
Files selected for processing (1)
  • cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py

@azhavoro
Copy link
Contributor Author

The migration looks good to me.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e031c2b and 2eb8ab3.
Files selected for processing (1)
  • cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • cvat/apps/analytics_report/migrations/0002_fix_annotation_speed.py

@bsekachev bsekachev merged commit f4ee3f9 into develop May 13, 2024
32 checks passed
@bsekachev bsekachev deleted the az/fix_analytics branch May 20, 2024 07:54
@cvat-bot cvat-bot bot mentioned this pull request May 21, 2024
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.

None yet

4 participants