Skip to content

Commit

Permalink
Add comment count and percentage to info command
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Apr 21, 2022
1 parent c5bb1ec commit 7aa3bf2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 14 additions & 0 deletions api/slack/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def user_transcription_quality_info(user: BlossomUser) -> Dict:
check_ratio = check_count / gamma if gamma > 0 else 0
checks = f"{check_count} ({check_ratio:.1%} of transcriptions)"

# The comments for the given user
user_comments_pending = user_checks.filter(status=check_status.COMMENT_PENDING)
user_comments_resolved = user_checks.filter(status=check_status.COMMENT_RESOLVED)
user_comments_unfixed = user_checks.filter(status=check_status.COMMENT_UNFIXED)
comments_count = (
user_comments_pending.count()
+ user_comments_resolved.count()
+ user_comments_unfixed.count()
)
comments_ratio = comments_count / check_count if check_count > 0 else 0
comments = f"{comments_count} ({comments_ratio:.1%} of checks)"

# The warnings for the given user
user_warnings_pending = user_checks.filter(status=check_status.WARNING_PENDING)
user_warnings_resolved = user_checks.filter(status=check_status.WARNING_RESOLVED)
Expand All @@ -102,11 +114,13 @@ def user_transcription_quality_info(user: BlossomUser) -> Dict:
warnings_ratio = warnings_count / check_count if check_count > 0 else 0
warnings = f"{warnings_count} ({warnings_ratio:.1%} of checks)"

# Watch status
watch_status = user.transcription_check_reason(ignore_low_activity=True)

return {
"Checks": checks,
"Warnings": warnings,
"Comments": comments,
"Watch status": watch_status,
}

Expand Down
24 changes: 15 additions & 9 deletions api/tests/slack/commands/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_user_info_text_new_user(client: Client) -> None:
*Transcription Quality*:
- Checks: 0 (0.0% of transcriptions)
- Warnings: 0 (0.0% of checks)
- Comments: 0 (0.0% of checks)
- Watch status: Automatic (100.0%)
*Debug Info*:
Expand Down Expand Up @@ -64,14 +65,14 @@ def test_user_info_text_old_user(client: Client) -> None:
)

tr_data = [
(datetime(2020, 7, 3, tzinfo=pytz.UTC), True, False),
(datetime(2020, 7, 7, tzinfo=pytz.UTC), False, False),
(datetime(2020, 7, 9, tzinfo=pytz.UTC), False, False),
(datetime(2021, 4, 10, tzinfo=pytz.UTC), True, True),
(datetime(2021, 4, 12, tzinfo=pytz.UTC), False, False),
(datetime(2020, 7, 3, tzinfo=pytz.UTC), True, True, False),
(datetime(2020, 7, 7, tzinfo=pytz.UTC), False, False, False),
(datetime(2020, 7, 9, tzinfo=pytz.UTC), False, False, False),
(datetime(2021, 4, 10, tzinfo=pytz.UTC), True, False, True),
(datetime(2021, 4, 12, tzinfo=pytz.UTC), True, False, False),
]

for idx, (date, has_check, is_warning) in enumerate(tr_data):
for idx, (date, has_check, is_comment, is_warning) in enumerate(tr_data):
submission = create_submission(
id=100 + idx,
create_time=date - timedelta(days=1),
Expand All @@ -87,7 +88,11 @@ def test_user_info_text_old_user(client: Client) -> None:
if has_check:
check_status = TranscriptionCheck.TranscriptionCheckStatus
status = (
check_status.WARNING_RESOLVED if is_warning else check_status.APPROVED
check_status.COMMENT_RESOLVED
if is_comment
else check_status.WARNING_RESOLVED
if is_warning
else check_status.APPROVED
)
create_check(transcription, status=status)

Expand All @@ -99,8 +104,9 @@ def test_user_info_text_old_user(client: Client) -> None:
- Last active: 2021-04-13 (1.1 weeks ago)
*Transcription Quality*:
- Checks: 2 (40.0% of transcriptions)
- Warnings: 1 (50.0% of checks)
- Checks: 3 (60.0% of transcriptions)
- Warnings: 1 (33.3% of checks)
- Comments: 1 (33.3% of checks)
- Watch status: Automatic (100.0%)
*Debug Info*:
Expand Down

0 comments on commit 7aa3bf2

Please sign in to comment.