Measurements
The measurements utilities provide helpers for working with energy consumption and generation data from the Kraken API.
Overview
Energy measurements come from the measurements field on the Property GraphQL endpoint. These utilities help with:
- Parsing and transforming measurement data
- Calculating consumption statistics
- Formatting values for display
Usage
import {
getMeasurements,
calculateDailyTotal,
formatConsumption
} from '@krakentech/blueprint-measurements';
// Fetch measurements for a property
const measurements = await getMeasurements({
propertyId: 'prop-123',
from: '2024-01-01',
to: '2024-01-31',
granularity: 'DAILY'
});
// Calculate totals
const dailyTotal = calculateDailyTotal(measurements);
// Format for display
const formatted = formatConsumption(dailyTotal, 'kWh');
Components
The @krakentech/blueprint-measurements package also exports React components for visualizing energy data:
ConsumptionGraph
Renders a bar chart of energy consumption over time with support for:
- Multiple tariff bands (multi-color bars)
- Cost/usage toggle
- Responsive sizing
ConsumptionGraphControl
A control panel for filtering consumption data by:
- Time interval (daily, weekly, monthly, yearly)
- Custom date ranges
StatisticsCard
Shows a comparison of current vs previous period consumption.
API Reference
getMeasurements
interface GetMeasurementsParams {
propertyId: string;
marketSupplyPointId?: string;
from: string;
to: string;
granularity: 'HALF_HOURLY' | 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY';
readingDirection?: 'IMPORT' | 'EXPORT';
utilityType?: 'ELECTRICITY' | 'GAS';
}
function getMeasurements(params: GetMeasurementsParams): Promise<Measurement[]>;
calculateDailyTotal
function calculateDailyTotal(measurements: Measurement[]): number;
formatConsumption
function formatConsumption(
value: number,
unit: 'kWh' | 'MWh',
locale?: string
): string;