bucket-local-time-in-code-not-in-sql
Installation
SKILL.md
Derive local buckets from one scan
Four of a period's figures — the hour histogram, the busiest day, the per-day counts and the total —
are all questions about the same rows of an append-only event table (local-listening-analytics),
and all four are questions about local time. Written as SQL aggregates that is four scans, each
needing a local-time conversion inside the engine. Written as one query returning the raw pairs, it
is one scan and no conversion at all:
// adapted — the only query in this family that returns rows rather than a number
@Query("SELECT timestamp, listenedSecond FROM activity_event" +
" WHERE timestamp BETWEEN :startTimestamp AND :endTimestamp")
suspend fun getSamplesInRange(startTimestamp: LocalDateTime, endTimestamp: LocalDateTime): List<Sample>