Skip to content

fix(VarWatch): better speed efficiency fraction representation#70

Open
Aurumaker72 wants to merge 2 commits intomainfrom
better-spd-eff-fraction
Open

fix(VarWatch): better speed efficiency fraction representation#70
Aurumaker72 wants to merge 2 commits intomainfrom
better-spd-eff-fraction

Conversation

@Aurumaker72
Copy link
Member

Improves speed efficiency fraction representation.

Copilot AI review requested due to automatic review settings March 2, 2026 18:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the speed efficiency fraction display in the VarWatch module by extracting the fraction-formatting logic into a new reusable Formatter.fraction utility function, replacing an inline multi-branch conditional.

Changes:

  • Adds a new Formatter.fraction(value, denominator) function that rounds a [0,1] value to the nearest fraction with the given denominator.
  • Updates VarWatch's spd_efficiency handler to call Formatter.fraction(spd_efficiency, 4) instead of the inlined if/elseif chain.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/core/Formatter.lua Adds Formatter.fraction, a generic utility to format a [0,1] float as a fraction string
src/core/VarWatch.lua Simplifies the spd_efficiency display by delegating fraction formatting to Formatter.fraction

---@param value number A number in the range 0-1.
---@param denominator number The denominator of the fraction.
---@return string The value's string representation as a fraction.
Formatter.fraction = function(value, denominator)
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The Formatter.fraction function clamps value to the range [0, 1] before computing the numerator. However, Engine.GetSpeedEfficiency() can return values greater than 1 (it computes the ratio of actual distance moved to sliding speed, which has no upper bound). This means any efficiency above 1 (i.e., above 100%) will be silently clamped and displayed as 4/4 regardless of the actual value.

For consistency with Formatter.percent — which handles super-threshold values by rendering ∞%Formatter.fraction (or its caller in VarWatch) should handle out-of-range values explicitly, for example by returning something like >4/4 or a special symbol when value > 1, rather than silently clamping and misrepresenting the data.

Suggested change
Formatter.fraction = function(value, denominator)
Formatter.fraction = function(value, denominator)
if value > 1 then
return string.format('>%d/%d', denominator, denominator)
end

Copilot uses AI. Check for mistakes.
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.

2 participants