Skip to content

Fix user stats showing -Inf/NaN for vote metrics when user has no votes - #85

Draft
IvoLeist with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-max-votes-per-session-display
Draft

Fix user stats showing -Inf/NaN for vote metrics when user has no votes#85
IvoLeist with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-max-votes-per-session-display

Conversation

Copilot AI commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

R's max() and mean() return -Inf and NaN on empty vectors, causing those values to surface in the user stats table when a user has not yet cast any votes.

Changes

  • R/mod_userstats.R: Initialize average_votes_per_session and max_votes_per_session to NA, computing them only when nrow(session_counts_df) > 0 — consistent with the existing guard pattern already used for session_times and time_vals in the same function.

  • tests/testthat/test-user-stats-module.R: Add a test covering the zero-votes case, asserting that neither -Inf nor NaN appear in the stats output for these metrics.

# Before
max_votes_per_session = max(session_counts_df$images_voted),   # → -Inf when empty

# After
max_votes_per_session <- NA
if (nrow(session_counts_df) > 0) {
  max_votes_per_session <- max(session_counts_df$images_voted)
}

Copilot AI changed the title [WIP] Fix user stats showing '-Inf' for max votes per session Fix user stats showing -Inf/NaN for vote metrics when user has no votes Apr 14, 2026
Copilot AI requested a review from IvoLeist April 14, 2026 12:48
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.

User stats show "max_votes_per_session -Inf" when a user has not voted any image yet

2 participants