• Builds comparison datasets for two time ranges.

    Parameters

    • readingHistory: ReadingHistory

      Reading history data.

    • primaryRange: TimeRange

      First time period to compare.

    • secondaryRange: TimeRange

      Second time period to compare.

    Returns {
        primary: {
            trends: { date: string; chapters: number; count: number }[];
            velocity: {
                perDay: number;
                perWeek: number;
                perMonth: number;
                totalChapters: number;
                activeDays: number;
            };
            habits: {
                byDayOfWeek: { day: string; chapters: number }[];
                byTimeOfDay: { hour: string; chapters: number }[];
                peakDay: null | string;
                peakHour: null | string;
            };
        };
        secondary: {
            trends: { date: string; chapters: number; count: number }[];
            velocity: {
                perDay: number;
                perWeek: number;
                perMonth: number;
                totalChapters: number;
                activeDays: number;
            };
            habits: {
                byDayOfWeek: { day: string; chapters: number }[];
                byTimeOfDay: { hour: string; chapters: number }[];
                peakDay: null | string;
                peakHour: null | string;
            };
        };
        primaryLabel: string;
        secondaryLabel: string;
    }

    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],
    };
    }