MDK Logo

Operational efficiency

Reporting-tool tab shell for site, miner-type, and mining-unit efficiency views

@tetherto/mdk-react-devkit/foundation

OperationsEfficiency is a three-tab reporting surface:

  • Site View
  • Miner Type View
  • Mining Unit View

Your app loads metrics or tail-log data, passes it through the siteView, minerTypeView, and minerUnitView prop bags, and the shell renders charts and time-frame controls.

Prerequisites

Import

import {
  OperationsEfficiency,
  toOperationsEfficiencyMinerType,
  toOperationsEfficiencyMinerUnit,
  TAIL_LOG_MINER_TYPE_KEY,
  TAIL_LOG_CONTAINER_KEY,
} from '@tetherto/mdk-react-devkit/foundation'
import type {
  EfficiencyDateRange,
  MetricsEfficiencyLogEntry,
} from '@tetherto/mdk-react-devkit/foundation'

OperationsEfficiency

Tab shell built on Tabs from @tetherto/mdk-react-devkit/core. Each tab receives an optional props object; omit a tab’s props to render it with empty defaults.

Props

PropStatusTypeDefaultDescription
defaultTabOptional'site-view' | 'miner-type-view' | 'mining-unit-view''site-view'Initial active tab key
siteViewOptionalEfficiencySiteViewPropsnoneData and callbacks for the Site View line chart
minerTypeViewOptionalEfficiencyMinerTypeViewPropsnoneBar chart input for Miner Type View
minerUnitViewOptionalEfficiencyMinerUnitViewPropsnoneBar chart input for Mining Unit View (same shape as miner type)

Site view tab

Wire the Site View to /auth/metrics/efficiency (v2). Map the response log array to MetricsEfficiencyLogEntry and pass it on siteView.log.

PropStatusTypeDefaultDescription
logOptionalMetricsEfficiencyLogEntry[][]Time series for the line chart (ts, efficiencyWThs)
avgEfficiencyOptionalnumber | nullnullAverage efficiency for the selected range; shown in the chart header
nominalValueOptionalnumber | nullnullNominal efficiency target; when set, adds a nominal series to the chart
isLoadingOptionalbooleanfalseWhen true, shows loading state on the chart container
dateRangeOptionalEfficiencyDateRangenone{ start, end } millisecond range for the date picker
onDateRangeChangeOptionalfunctionnoneCalled when the user selects a new range from the chart brush or date picker
onResetOptionalfunctionnoneCalled when the user activates Reset on the site chart header

Miner type and mining unit tabs

Miner Type View and Mining Unit View use bar charts fed by ToBarChartDataInput ({ labels, series }). Until the metrics API supports groupBy=miner, build that input from tail-log (stat-5m / t-miner) using the pure helpers below. A backend follow-up will allow swapping the data source in foundation without changing this props contract.

HelperInputOutput
toOperationsEfficiencyMinerType{ tailLog }{ chartInput, isEmpty } — reads TAIL_LOG_MINER_TYPE_KEY from tail-log
toOperationsEfficiencyMinerUnit{ tailLog, containers? }{ chartInput, isEmpty } — reads TAIL_LOG_CONTAINER_KEY; optional containers for labels

Pass the result on minerTypeView / minerUnitView:

PropStatusTypeDefaultDescription
chartInputOptionalToBarChartDataInputnoneDeclarative bar data; convert with buildBarChartData if you need Chart.js data elsewhere
isEmptyOptionalbooleanfalseWhen true, shows the chart empty state
isLoadingOptionalbooleanfalseWhen true, shows loading on the bar chart container
onTimeFrameChangeOptionalfunctionnoneCalled with (start: Date, end: Date) when the preset or custom range changes

Example

import { useMemo, useState } from 'react'
import {
  OperationsEfficiency,
  toOperationsEfficiencyMinerType,
  toOperationsEfficiencyMinerUnit,
} from '@tetherto/mdk-react-devkit/foundation'
import type { EfficiencyDateRange, MetricsEfficiencyLogEntry } from '@tetherto/mdk-react-devkit/foundation'

function OperationalEfficiencyPanel({
  efficiencyLog,
  minerTypeTailLog,
  containerTailLog,
}: {
  efficiencyLog: MetricsEfficiencyLogEntry[]
  minerTypeTailLog: Record<string, unknown>
  containerTailLog: Record<string, unknown>
}) {
  const [dateRange, setDateRange] = useState<EfficiencyDateRange | undefined>()

  const minerType = useMemo(
    () => toOperationsEfficiencyMinerType({ tailLog: minerTypeTailLog }),
    [minerTypeTailLog],
  )
  const minerUnit = useMemo(
    () => toOperationsEfficiencyMinerUnit({ tailLog: containerTailLog }),
    [containerTailLog],
  )

  return (
    <OperationsEfficiency
      siteView={{
        log: efficiencyLog,
        dateRange,
        onDateRangeChange: setDateRange,
      }}
      minerTypeView={{
        chartInput: minerType.chartInput,
        isEmpty: minerType.isEmpty,
      }}
      minerUnitView={{
        chartInput: minerUnit.chartInput,
        isEmpty: minerUnit.isEmpty,
      }}
    />
  )
}

Next steps

Consider related reference materials:

On this page