Skip to content

feat(client): adaptive W/kW display for miner power usage#115

Open
Schnitzel wants to merge 1 commit intoblock:mainfrom
Schnitzel:feat/adaptive-power-display
Open

feat(client): adaptive W/kW display for miner power usage#115
Schnitzel wants to merge 1 commit intoblock:mainfrom
Schnitzel:feat/adaptive-power-display

Conversation

@Schnitzel
Copy link
Copy Markdown

Summary

  • MinerPowerUsage was hardcoding kW as the unit with no conversion, causing low-wattage miners (e.g. Bitaxe at ~12.5 W) to display as 0 kW
  • Adds formatPowerKW utility: values < 1 kW are shown in W (1 decimal place), values >= 1 kW are shown in kW (1 decimal place)
  • Replaces the <MinerMeasurement unit="kW"> call with inline rendering using the adaptive formatter

Test plan

  • Verified formatPowerKW unit tests pass (stringUtils.test.ts)
  • Bitaxe Gamma (~12.5 W) shows as 12.5 W instead of 0 kW
  • Large miners (e.g. 3,200 W) still show as 3.2 kW

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 28, 2026 18:02
@Schnitzel Schnitzel requested a review from a team as a code owner April 28, 2026 18:02
@github-actions github-actions Bot added javascript Pull requests that update javascript code client labels Apr 28, 2026
MinerPowerUsage was hardcoding kW as the unit, showing low-wattage
miners (e.g. Bitaxe at ~12.5 W) as "0 kW". Adds formatPowerKW which
renders values below 1 kW in W (1 decimal) and >= 1 kW in kW (1 decimal).

Signed-off-by: Michael Schmid <michael.schmid@amazee.io>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Schnitzel Schnitzel force-pushed the feat/adaptive-power-display branch from e836e96 to e168d81 Compare April 28, 2026 18:03
Copy link
Copy Markdown
Contributor

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

Adds adaptive power-unit formatting to the client so low-power miners no longer display as 0 kW, aligning fleet UI output with actual kW telemetry values.

Changes:

  • Added formatPowerKW utility to format kW values as either W (< 1 kW) or kW (>= 1 kW).
  • Added unit tests for formatPowerKW.
  • Updated MinerPowerUsage to render power usage with adaptive units instead of hardcoding kW.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
client/src/shared/utils/stringUtils.ts Adds formatPowerKW helper for adaptive W/kW formatting.
client/src/shared/utils/stringUtils.test.ts Adds test coverage for formatPowerKW.
client/src/protoFleet/features/fleetManagement/components/MinerList/MinerPowerUsage.tsx Switches power usage cell rendering to use adaptive formatting.

Comment on lines 1 to 2
import MinerMeasurement from "./MinerMeasurement";
import UnsupportedMetric from "./UnsupportedMetric";
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

MinerMeasurement is still imported but no longer used after switching to inline rendering. This will fail linting under @typescript-eslint/no-unused-vars; remove the import or use the component again (e.g., by extending it to support adaptive units).

Copilot uses AI. Check for mistakes.
Comment on lines +35 to +44
/**
* Formats a power value in kW with adaptive units.
* Values >= 1 kW are shown in kW (1 decimal place).
* Values < 1 kW are converted to W (rounded to nearest integer).
*/
export const formatPowerKW = (kw: number): { value: string; unit: string } => {
if (kw >= 1) {
return { value: separateByCommas(kw.toFixed(1)), unit: "kW" };
}
return { value: separateByCommas((kw * 1000).toFixed(1)), unit: "W" };
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The docstring says values < 1 kW are converted to W "(rounded to nearest integer)", but the implementation uses toFixed(1) (one decimal place). Update the comment to match the actual formatting behavior (or adjust the implementation to match the comment).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

Comment on lines +23 to +31
if (powerUsage === undefined) return <SkeletonBar className="w-full pr-10" />;
if (powerUsage === null) return <>{INACTIVE_PLACEHOLDER}</>;
if (powerUsage.length === 0) return null;

const latestValue = getLatestMeasurementWithData(powerUsage)?.value;
if (latestValue === undefined) return <>{INACTIVE_PLACEHOLDER}</>;

const { value, unit } = formatPowerKW(latestValue);
return <>{value} {unit}</>;
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

MinerPowerUsage now re-implements the same loading/offline/empty/latest-value logic that already exists in MinerMeasurement. To avoid future drift between measurement cells, consider refactoring MinerMeasurement to accept a formatter (or render prop) so MinerPowerUsage can keep the shared state handling while still using adaptive units.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@ankitgoswami ankitgoswami left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I agree with the bot about the code duplication. Adding an optional formatValue?: (value: number) => { value: string; unit: string } prop seems like a good idea. Default behavior keeps getDisplayValue(latestValue) + unit. MinerPowerUsage becomes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants