Skip to content

Commit

Permalink
fix(gluwave): carb rate did not end at correct time
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalhama committed Oct 3, 2024
1 parent ced17cc commit 8c2bd3d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions gluwave/src/components/carbohydrate-absorption-rate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { db } from '@/db'
import { Statistics } from '@/lib/sql_utils'
import { carbs } from '@/schema'
import { addHours, setHours, startOfDay, subHours } from 'date-fns'
import { and, eq, gte, lt, sql } from 'drizzle-orm'
import { and, eq, gte, lt, lte, sql } from 'drizzle-orm'
import { redirect } from 'next/navigation'
import { Tuple } from 'victory'

Expand Down Expand Up @@ -37,7 +37,7 @@ const getReportedCarbRate = (userId: string, start: Date, end: Date) => {
UNION ALL
SELECT timestamp + MAKE_INTERVAL(mins => carbs.decay) AS timestamp
SELECT timestamp + MAKE_INTERVAL(mins => carbs.decay + 1) AS timestamp
FROM carbs
WHERE user_id = ${userId}
AND ${start.toISOString()} <= timestamp + MAKE_INTERVAL(mins => carbs.decay)
Expand All @@ -52,7 +52,7 @@ const getReportedCarbRate = (userId: string, start: Date, end: Date) => {
sql`${carbs.timestamp} + MAKE_INTERVAL(mins => ${carbs.decay})`,
sql`timeframe.timestamp`
),
lt(carbs.timestamp, sql`timeframe.timestamp`)
lte(carbs.timestamp, sql`timeframe.timestamp`)
)
)
.groupBy(sql`timeframe.timestamp`)
Expand Down Expand Up @@ -86,8 +86,15 @@ export default async function CarbohydrateAbsorptionRate({ href }: Props) {
y: (o.observedCarbs / (o.interval ?? 1)) * (15 * 60),
}
})
const d = await db.execute(sql`SELECT timestamp
FROM carbs
WHERE timestamp <= ${end.toISOString()}`)
console.log('d', d.rows)

const reported_rate = await getReportedCarbRate(user.id, start, end)
console.log(start, end)

console.log(reported_rate)

const reportedRate = reported_rate.map((o) => {
return {
Expand Down

0 comments on commit 8c2bd3d

Please sign in to comment.