mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
Merge pull request #1138 from MBombeck/feat/pulse-hourly-mean-complete
fix(pulse): a day of pulse is the mean of its hours' means, everywhere
This commit is contained in:
75 files changed
+4699
-230
No files matched your search
@@ -135,4 +135,65 @@ describe("<ChartDataTable>", () => {
|
||||
/data-slot="table-container"[^>]*class="[^"]*overflow-x-auto/,
|
||||
);
|
||||
});
|
||||
|
||||
describe("naming the statistic", () => {
|
||||
const pulsePoints = points(3).map((p) => ({ ...p, PULSE: 64 }));
|
||||
const pulseProps = (over: Partial<ChartDataTableProps> = {}) =>
|
||||
props({
|
||||
points: pulsePoints,
|
||||
columns: [{ key: "PULSE", label: "Pulse" }],
|
||||
unit: "bpm",
|
||||
metricLabel: "Pulse",
|
||||
...over,
|
||||
});
|
||||
|
||||
it("says a day of pulse is the average of its hours, so a workout does not outweigh the day", () => {
|
||||
const html = render(<ChartDataTable {...pulseProps()} />);
|
||||
expect(html).toContain('data-slot="chart-data-table-statistic"');
|
||||
expect(html).toContain(
|
||||
"Pulse is each day's average, with every hour counting once",
|
||||
);
|
||||
});
|
||||
|
||||
it("says it in German too", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="de">
|
||||
<ChartDataTable {...pulseProps()} />
|
||||
</I18nProvider>,
|
||||
);
|
||||
expect(html).toContain("jede Stunde einmal zählt");
|
||||
});
|
||||
|
||||
it("says it for the week and month grains as well", () => {
|
||||
for (const bucket of ["week", "month"] as const) {
|
||||
expect(
|
||||
render(<ChartDataTable {...pulseProps({ bucket })} />),
|
||||
).toContain('data-slot="chart-data-table-statistic"');
|
||||
}
|
||||
});
|
||||
|
||||
it("adds nothing for a metric that is the plain mean of its readings", () => {
|
||||
const html = render(<ChartDataTable {...props()} />);
|
||||
expect(html).not.toContain('data-slot="chart-data-table-statistic"');
|
||||
});
|
||||
|
||||
it("names only the pulse column when it shares a table with others", () => {
|
||||
const html = render(
|
||||
<ChartDataTable
|
||||
{...props({
|
||||
points: pulsePoints,
|
||||
columns: [
|
||||
{ key: "BLOOD_PRESSURE_SYS", label: "Systolic" },
|
||||
{ key: "PULSE", label: "Pulse" },
|
||||
],
|
||||
})}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
html.match(/data-slot="chart-data-table-statistic"/g),
|
||||
).toHaveLength(1);
|
||||
expect(html).toContain("Pulse is each day");
|
||||
expect(html).not.toContain("Systolic is each day");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { ChartBucketType } from "@/lib/charts/bucket-time-series";
|
||||
import { usesHourlyMeanDay } from "@/lib/measurements/day-statistic";
|
||||
|
||||
/**
|
||||
* The data points behind the chart, as a table.
|
||||
@@ -132,6 +133,21 @@ export function ChartDataTable({
|
||||
<Table>
|
||||
<TableCaption className="mt-2 text-left text-xs">
|
||||
{t(BUCKET_CAPTION_KEY[bucket], { metric: metricLabel })}
|
||||
{/* Name the statistic where it is not the plain mean of the
|
||||
readings: a day of pulse is the mean of its hours' means. */}
|
||||
{columns
|
||||
.filter((column) => usesHourlyMeanDay(column.key))
|
||||
.map((column) => (
|
||||
<span
|
||||
key={column.key}
|
||||
data-slot="chart-data-table-statistic"
|
||||
className="mt-1 block"
|
||||
>
|
||||
{t("charts.dataTable.hourlyMeanNote", {
|
||||
metric: column.label,
|
||||
})}
|
||||
</span>
|
||||
))}
|
||||
</TableCaption>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
type ComponentType,
|
||||
} from "react";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { usesHourlyMeanDay } from "@/lib/measurements/day-statistic";
|
||||
import { RichChartTooltip, type RichTooltipRow } from "./chart-tooltip";
|
||||
import { ChartEmptyState } from "./chart-empty-state";
|
||||
import { ChartErrorState } from "./chart-error-state";
|
||||
@@ -2240,7 +2241,14 @@ export function HealthChart({
|
||||
}
|
||||
}
|
||||
rows.push({
|
||||
name: item.name ?? dataKey,
|
||||
// Name the statistic where it is not the plain mean
|
||||
// of the readings: a day of pulse is the mean of its
|
||||
// hours' means.
|
||||
name: usesHourlyMeanDay(dataKey)
|
||||
? t("charts.tooltipHourlyMean", {
|
||||
metric: item.name ?? dataKey,
|
||||
})
|
||||
: (item.name ?? dataKey),
|
||||
value: `${formatTooltipValue(item.value)}${
|
||||
unit ? ` ${unit}` : ""
|
||||
}`,
|
||||
|
||||
Reference in new issue
Block a user