The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add additional data points for 0 event minute data points.
TzeYiing32206629f7d8
diff --git a/studio/components/interfaces/Settings/Logs/LogEventChart.tsx b/studio/components/interfaces/Settings/Logs/LogEventChart.tsxindex 0163b15aaa0..56c69944855 100644--- a/studio/components/interfaces/Settings/Logs/LogEventChart.tsx+++ b/studio/components/interfaces/Settings/Logs/LogEventChart.tsx@@ -2,6 +2,7 @@ import { BarChart } from 'components/to-be-cleaned/Charts/ChartRenderer'import dayjs from 'dayjs'import { LogData } from '.'import utc from 'dayjs/plugin/utc'+import { useMemo } from 'react'dayjs.extend(utc)interface Props {data: LogData[]@@ -11,32 +12,7 @@ interface Props {type TimestampMap = { [timestamp: number]: number }const LogEventChart: React.FC<Props> = ({ data, onBarClick }) => {if (!data) return null-- const countMap = data- .map((d) => {- // truncate to per-minute- return { ...d, timestamp: Math.round(d.timestamp / 1000 / 1000 / 60) * 60 }- })- .reduce((acc, d) => {- if (acc[d.timestamp]) {- acc[d.timestamp] = acc[d.timestamp] + 1- } else {- acc[d.timestamp] = 1- }- return acc- }, {} as TimestampMap)-- let aggregated = []- for (const [key, value] of Object.entries(countMap)) {- const v: number = Number(key)- aggregated.push({- period_start: dayjs.unix(v).utc().format(),- timestamp: key,- timestampMicro: v * 1000 * 1000,- count: value,- })- }- aggregated = aggregated.sort((a, b) => a.timestampMicro - b.timestampMicro)+ const aggregated = useAggregated(data)return (<BarChart@@ -51,9 +27,54 @@ const LogEventChart: React.FC<Props> = ({ data, onBarClick }) => {// 60s beforeonBarClick((Number(timestamp) + 60) * 1000 * 1000)}}- customDateFormat="D MMM, HH:mm"+ customDateFormat="MMM D, HH:mm"/>)}+const useAggregated = (data: LogData[]) => {+ const truncateToMinute = (micro: number) => Math.round(micro / 1000 / 1000 / 60) * 60+ return useMemo(() => {+ const countMap = data+ .map((d) => {+ // truncate to per-minute+ return { ...d, timestamp: truncateToMinute(d.timestamp) }+ })+ .reduce((acc, d) => {+ if (acc[d.timestamp]) {+ acc[d.timestamp] = acc[d.timestamp] + 1+ } else {+ acc[d.timestamp] = 1+ }+ return acc+ }, {} as TimestampMap)++ // Add in additional data points for empty minutes+ const oldestEvent = data[data.length - 1]+ if (!oldestEvent) return []+ const currentTimestamp = new Date().getTime()+ const oldestTimestampMicro = oldestEvent.timestamp+ const minutesDifference = Math.round(+ (currentTimestamp - oldestTimestampMicro / 1000) / 1000 / 60+ )+ for (const minToAdd of Array.from(Array(minutesDifference).keys())) {+ const tsToCheck = truncateToMinute(oldestTimestampMicro) + minToAdd * 60+ if (!(tsToCheck in countMap)) {+ countMap[tsToCheck] = 0+ }+ }++ let aggregated = []+ for (const [key, value] of Object.entries(countMap)) {+ const v: number = Number(key)+ aggregated.push({+ period_start: dayjs.unix(v).utc().format(),+ timestamp: key,+ timestampMicro: v * 1000 * 1000,+ count: value,+ })+ }+ return aggregated.sort((a, b) => a.timestampMicro - b.timestampMicro)+ }, [JSON.stringify(data)])+}export default LogEventChart