Reading history data.
First time period to compare.
Second time period to compare.
Primary and secondary datasets with labels.
export function buildComparisonDatasets(
readingHistory: ReadingHistory,
primaryRange: TimeRange,
secondaryRange: TimeRange,
): {
primary: {
trends: ReturnType<typeof computeReadingTrends>;
velocity: ReturnType<typeof computeReadingVelocity>;
habits: ReturnType<typeof computeReadingHabits>;
};
secondary: {
trends: ReturnType<typeof computeReadingTrends>;
velocity: ReturnType<typeof computeReadingVelocity>;
habits: ReturnType<typeof computeReadingHabits>;
};
primaryLabel: string;
secondaryLabel: string;
} {
const rangeLabels: Record<TimeRange, string> = {
"7d": "Last 7 days",
"30d": "Last 30 days",
"90d": "Last 90 days",
all: "All time",
};
return {
primary: {
trends: computeReadingTrends(readingHistory, primaryRange),
velocity: computeReadingVelocity(readingHistory, primaryRange),
habits: computeReadingHabits(readingHistory, primaryRange),
},
secondary: {
trends: computeReadingTrends(readingHistory, secondaryRange),
velocity: computeReadingVelocity(readingHistory, secondaryRange),
habits: computeReadingHabits(readingHistory, secondaryRange),
},
primaryLabel: rangeLabels[primaryRange],
secondaryLabel: rangeLabels[secondaryRange],
};
}
Builds comparison datasets for two time ranges.