Skip to content

feat: avg click distance metric (% of canvas diagonal) - #18

Merged
Reasel merged 9 commits into
masterfrom
feat/avg-click-distance
Jun 22, 2026
Merged

Reasel merged 9 commits into
masterfrom
feat/avg-click-distance

Conversation

@Reasel

@Reasel Reasel commented Jun 22, 2026

Copy link
Copy Markdown
Owner

Avg Click Distance metric

Adds a third live metric alongside Consistency and Avg Click Interval: Average Click Distance — the mean mouse jump between consecutive clicks, expressed as a percentage of the game canvas diagonal (0–100%). Lets you compare how much mouse movement an activity demands, independent of resolution or display mode.

panel

How it works

  • The mouse listener now records each click's (x, y) in parallel with its timestamp.
  • computeAverageDistance averages the Euclidean distance between consecutive clicks (in click order, no sorting); toDistancePercent normalizes that against the canvas diagonal (sqrt(w² + h²)). Both are pure and unit-tested; getAverageClickDistance is the live wrapper using client.getCanvasWidth()/getCanvasHeight().
  • Stored per session (Session.avgDistancePercent) and shown in the panel via a stat card + a linear 0–100 DistanceIndicator, plus the history line and copy-to-clipboard text. Format %.1f%% everywhere.
  • Guards: fewer than 2 clicks, or canvas diagonal ≤ 0, → 0.0.

Backward compatibility

Sessions saved before this change have no distance field; Gson deserializes it to 0.0, so they render 0.0% (visible in the history row of the screenshot). No migration needed.

Drive-by fix

Removed a double-registration of the mouse listener: startUp() registered it and startSession() registered it again with no intervening unregister, which double-counted clicks during a session. Registration is now managed solely by start/stopSession.

Tests

14 unit tests covering the two pure helpers (empty/single point, known distances, zero/half/full-diagonal normalization) plus the updated Session constructor. Full build green.

Caveat

If the canvas is resized mid-session, stored pixel distances are normalized by the canvas diagonal at stop time, a small accepted skew for an AFK stat.

@Reasel
Reasel merged commit ac7bfad into master Jun 22, 2026
1 check passed
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.

1 participant