-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
Codecov Report
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
|
cvat/apps/analytics_report/report/primary_metrics/annotation_speed.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Maria Khrustaleva <maya17grd@gmail.com>
@azhavoro |
WalkthroughEnhancements to the project's analytics involve refining annotation speed metric calculations. Notably, adjustments in Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
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
: Initializeprevious_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
: Accumulateprevious_count
correctly by summing up the values from previous entries.
129-129
: Appending the difference in object count todata_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.
There was a problem hiding this 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
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 inupgrade_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
isFalse
andNone
is returned. Consider returning the original report or explicitly handling this case.
42-48
: The migration setup in theMigration
class looks correct and well-defined.
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() |
There was a problem hiding this comment.
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.
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() |
There was a problem hiding this 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
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
There was a problem hiding this 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
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
The migration looks good to me. |
There was a problem hiding this 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
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
Motivation and context
How has this been tested?
Checklist
develop
branch(cvat-canvas,
cvat-core,
cvat-data and
cvat-ui)
License
Feel free to contact the maintainers if that's a concern.
Summary by CodeRabbit
get_track_count
to calculate the difference in object count based on the previous count rather than the last entry count.upgrade_report(report)
function for upgrading report statistics.forwards_func(apps, schema_editor)
function for processing analytics reports.Migration
class with dependencies and operations for the migration.