fix: peak hours analysis uses all historical data

Remove date range filtering from peak-hours endpoint so the
analysis considers all available data in the database, not just
the last 30 days.
This commit is contained in:
Jose Selesan
2026-08-28 13:31:30 -03:00
parent 0998d64cbb
commit f2c26c266c
4 changed files with 10 additions and 41 deletions

View File

@@ -2,7 +2,6 @@ import type { Context } from "hono";
import type { QuoteType } from "../../../generated/prisma/client";
import { cache } from "../../../lib/cache";
import { prisma } from "../../../lib/prisma";
import { parseLocalDate, startOfNextLocalDay } from "../../../lib/utils";
const VALID_TYPES = ["BLUE", "BNA", "BELO"] as const;
@@ -18,21 +17,7 @@ export async function getPeakHours(c: Context) {
);
}
const type = rawType as QuoteType;
const startDateParam = c.req.query("startDate");
const endDateParam = c.req.query("endDate");
const now = new Date();
const startDate = startDateParam
? parseLocalDate(startDateParam)
: new Date(now.getFullYear(), now.getMonth(), 1);
const endDate = endDateParam ? startOfNextLocalDay(endDateParam) : now;
if (Number.isNaN(startDate.getTime()) || Number.isNaN(endDate.getTime())) {
return c.json({ error: "Invalid date format. Use ISO 8601." }, 400);
}
const cacheKey = `quotes:peak-hours:${type}:${startDate.toISOString()}:${endDate.toISOString()}`;
const cacheKey = `quotes:peak-hours:${rawType}`;
const cached = cache.get(cacheKey);
if (cached) return c.json(cached);
@@ -56,8 +41,6 @@ export async function getPeakHours(c: Context) {
) AS rn
FROM "quotes_history"
WHERE "type" = ${rawType}::"QuoteType"
AND "timeStamp" >= ${startDate}::timestamptz
AND "timeStamp" < ${endDate}::timestamptz
)
SELECT
peak_hour AS hour,
@@ -75,8 +58,6 @@ export async function getPeakHours(c: Context) {
SELECT COUNT(DISTINCT DATE("timeStamp"))::int AS count
FROM "quotes_history"
WHERE "type" = ${rawType}::"QuoteType"
AND "timeStamp" >= ${startDate}::timestamptz
AND "timeStamp" < ${endDate}::timestamptz
`;
const response = {