Skip to content

Commit

Permalink
Aggregate daily data from hourly
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Jul 7, 2023
1 parent 3258a23 commit 560451c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/utils/wrappa/postgres/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ const queryAggregatedDailyTimestampRange = async (
chainEqual = chain ? sql`WHERE chain = ${chain}` : sql``;
}
return await sql<IAggregatedData[]>`
SELECT bridge_id, ts, total_deposited_usd, total_withdrawn_usd, total_deposit_txs, total_withdrawal_txs FROM
bridges.daily_aggregated
SELECT
bridge_id,
date_trunc('day', ts) AS day_ts,
SUM(total_deposited_usd) AS total_deposited_usd,
SUM(total_withdrawn_usd) AS total_withdrawn_usd,
SUM(total_deposit_txs) AS total_deposit_txs,
SUM(total_withdrawal_txs) AS total_withdrawal_txs
FROM
bridges.hourly_aggregated
WHERE
ts >= to_timestamp(${startTimestamp}) AND
ts <= to_timestamp(${endTimestamp}) AND
Expand Down Expand Up @@ -231,8 +238,8 @@ const queryAggregatedDailyDataAtTimestamp = async (timestamp: number, chain?: st
);`;
}
return await sql<IAggregatedData[]>`
SELECT date(ts) as ts, * FROM
SELECT date(ts) as ts, * FROM
bridges.hourly_aggregated
WHERE
date(ts) = date(to_timestamp(${timestamp}))
Expand Down

0 comments on commit 560451c

Please sign in to comment.