From 085d0c91ec04ac181c3ec0fe77f81b70f1197a66 Mon Sep 17 00:00:00 2001 From: slandymani Date: Thu, 28 Mar 2024 16:32:25 +0200 Subject: [PATCH] add daily/monthly average tx fee --- database/schema/00-cosmos.sql | 14 ++++++++++++++ .../bdjuno/tables/public_daily_average_fee.yaml | 12 ++++++++++++ .../bdjuno/tables/public_monthly_average_fee.yaml | 12 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 hasura/metadata/databases/bdjuno/tables/public_daily_average_fee.yaml create mode 100644 hasura/metadata/databases/bdjuno/tables/public_monthly_average_fee.yaml diff --git a/database/schema/00-cosmos.sql b/database/schema/00-cosmos.sql index 60d27f54c..548303ee5 100644 --- a/database/schema/00-cosmos.sql +++ b/database/schema/00-cosmos.sql @@ -122,4 +122,18 @@ SELECT DATE_TRUNC('month', b.timestamp) AS month, COUNT(t.height) AS transaction_volume FROM block b LEFT JOIN transaction t ON b.height = t.height +GROUP BY month; + +CREATE VIEW daily_average_fee AS +SELECT DATE_TRUNC('day', b.timestamp) AS day, + AVG((fee->'amount'->0->>'amount')::numeric) AS avg_daily_fee +FROM block b +LEFT JOIN transaction t ON b.height = t.height +GROUP BY day; + +CREATE VIEW monthly_average_fee AS +SELECT DATE_TRUNC('month', b.timestamp) AS month, + AVG((fee->'amount'->0->>'amount')::numeric) AS avg_monthly_fee +FROM block b +LEFT JOIN transaction t ON b.height = t.height GROUP BY month; \ No newline at end of file diff --git a/hasura/metadata/databases/bdjuno/tables/public_daily_average_fee.yaml b/hasura/metadata/databases/bdjuno/tables/public_daily_average_fee.yaml new file mode 100644 index 000000000..8ab924531 --- /dev/null +++ b/hasura/metadata/databases/bdjuno/tables/public_daily_average_fee.yaml @@ -0,0 +1,12 @@ +table: + name: daily_average_fee + schema: public +select_permissions: + - permission: + allow_aggregations: true + columns: + - day + - avg_daily_fee + filter: {} + limit: 100 + role: anonymous \ No newline at end of file diff --git a/hasura/metadata/databases/bdjuno/tables/public_monthly_average_fee.yaml b/hasura/metadata/databases/bdjuno/tables/public_monthly_average_fee.yaml new file mode 100644 index 000000000..0e3da54df --- /dev/null +++ b/hasura/metadata/databases/bdjuno/tables/public_monthly_average_fee.yaml @@ -0,0 +1,12 @@ +table: + name: monthly_average_fee + schema: public +select_permissions: + - permission: + allow_aggregations: true + columns: + - month + - avg_monthly_fee + filter: {} + limit: 100 + role: anonymous \ No newline at end of file