mirror of
https://github.com/GrassrootsEconomics/cic-dw.git
synced 2024-12-22 02:47:32 +01:00
patch: cameroon specific dashboard queries
This commit is contained in:
parent
c490f28a96
commit
8456ea78f8
@ -8,6 +8,7 @@ cors = [
|
|||||||
"https://dashboard.sarafu.network",
|
"https://dashboard.sarafu.network",
|
||||||
"https://dashboard.grassecon.org",
|
"https://dashboard.grassecon.org",
|
||||||
"https://dashboard.grassrootseconomics.org",
|
"https://dashboard.grassrootseconomics.org",
|
||||||
|
"https://dashboard.localvoucherscameroon.org",
|
||||||
"http://localhost:3000"
|
"http://localhost:3000"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/georgysavva/scany/pgxscan"
|
"github.com/georgysavva/scany/pgxscan"
|
||||||
|
"github.com/jackc/pgx/v4"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,15 +19,25 @@ type lineChartRes struct {
|
|||||||
func handleNewRegistrations(c echo.Context) error {
|
func handleNewRegistrations(c echo.Context) error {
|
||||||
var (
|
var (
|
||||||
api = c.Get("api").(*api)
|
api = c.Get("api").(*api)
|
||||||
|
qP = c.QueryParams()
|
||||||
|
|
||||||
|
rows pgx.Rows
|
||||||
|
err error
|
||||||
data []lineChartRes
|
data []lineChartRes
|
||||||
)
|
)
|
||||||
|
|
||||||
from, to := date_range.ParseDateRange(c.QueryParams())
|
from, to := date_range.ParseDateRange(qP)
|
||||||
|
|
||||||
rows, err := api.db.Query(context.Background(), api.q["new-user-registrations"], from, to)
|
if qP.Get("country") == "cmr" {
|
||||||
if err != nil {
|
rows, err = api.db.Query(context.Background(), api.q["new-user-registrations-cmr"], from, to)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rows, err = api.db.Query(context.Background(), api.q["new-user-registrations"], from, to)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
||||||
@ -39,15 +50,25 @@ func handleNewRegistrations(c echo.Context) error {
|
|||||||
func handleTransactionsCount(c echo.Context) error {
|
func handleTransactionsCount(c echo.Context) error {
|
||||||
var (
|
var (
|
||||||
api = c.Get("api").(*api)
|
api = c.Get("api").(*api)
|
||||||
|
qP = c.QueryParams()
|
||||||
|
|
||||||
|
rows pgx.Rows
|
||||||
|
err error
|
||||||
data []lineChartRes
|
data []lineChartRes
|
||||||
)
|
)
|
||||||
|
|
||||||
from, to := date_range.ParseDateRange(c.QueryParams())
|
from, to := date_range.ParseDateRange(qP)
|
||||||
|
|
||||||
rows, err := api.db.Query(context.Background(), api.q["transactions-count"], from, to)
|
if qP.Get("country") == "cmr" {
|
||||||
if err != nil {
|
rows, err = api.db.Query(context.Background(), api.q["transactions-count-cmr"], from, to)
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rows, err = api.db.Query(context.Background(), api.q["transactions-count"], from, to)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
if err := pgxscan.ScanAll(&data, rows); err != nil {
|
||||||
|
@ -12,6 +12,22 @@ GROUP BY date_range.day
|
|||||||
ORDER BY date_range.day
|
ORDER BY date_range.day
|
||||||
LIMIT 730;
|
LIMIT 730;
|
||||||
|
|
||||||
|
-- name: new-user-registrations-cmr
|
||||||
|
-- This is a patch to support CMR dashboard
|
||||||
|
-- This query generates a date range and left joins the users table to include days with no registrations
|
||||||
|
-- Produces x, y results for displaying on a line chart
|
||||||
|
WITH date_range AS (
|
||||||
|
SELECT day::date FROM generate_series('08-01-2022', '08-26-2022', INTERVAL '1 day') day
|
||||||
|
)
|
||||||
|
|
||||||
|
SELECT date_range.day AS x, COUNT(users.id) AS y
|
||||||
|
FROM date_range
|
||||||
|
LEFT JOIN users ON date_range.day = CAST(users.date_registered AS date)
|
||||||
|
WHERE users.phone_number LIKE '237%'
|
||||||
|
GROUP BY date_range.day
|
||||||
|
ORDER BY date_range.day
|
||||||
|
LIMIT 730;
|
||||||
|
|
||||||
-- name: transactions-count
|
-- name: transactions-count
|
||||||
-- This query generates a date range and left joins the transactions table to include days with no transactions
|
-- This query generates a date range and left joins the transactions table to include days with no transactions
|
||||||
-- Produces x, y results for displaying on a line chart
|
-- Produces x, y results for displaying on a line chart
|
||||||
@ -31,6 +47,29 @@ GROUP BY date_range.day
|
|||||||
ORDER BY date_range.day
|
ORDER BY date_range.day
|
||||||
LIMIT 730;
|
LIMIT 730;
|
||||||
|
|
||||||
|
-- name: transaction-count-cmr
|
||||||
|
-- This is a patch to support CMR dashboard
|
||||||
|
-- This query generates a date range and left joins the transactions table to include days with no transactions
|
||||||
|
-- Produces x, y results for displaying on a line chart
|
||||||
|
WITH date_range AS (
|
||||||
|
SELECT day::date FROM generate_series('08-01-2022', '08-26-2022', INTERVAL '1 day') day
|
||||||
|
),
|
||||||
|
exclude AS (
|
||||||
|
SELECT sys_address FROM sys_accounts WHERE sys_address IS NOT NULL
|
||||||
|
),
|
||||||
|
cmr_tokens AS (
|
||||||
|
SELECT token_address from tokens WHERE token_symbol IN ('MBIP')
|
||||||
|
)
|
||||||
|
SELECT date_range.day AS x, COUNT(transactions.id) AS y
|
||||||
|
FROM date_range
|
||||||
|
LEFT JOIN transactions ON date_range.day = CAST(transactions.date_block AS date)
|
||||||
|
AND transactions.sender_address NOT IN (SELECT sys_address FROM exclude) AND transactions.recipient_address NOT IN (SELECT sys_address FROM exclude)
|
||||||
|
AND transactions.success = true
|
||||||
|
AND transactions.token_address IN (SELECT token_address FROM cmr_tokens)
|
||||||
|
GROUP BY date_range.day
|
||||||
|
ORDER BY date_range.day
|
||||||
|
LIMIT 730;
|
||||||
|
|
||||||
-- name: token-transactions-count
|
-- name: token-transactions-count
|
||||||
-- This query gets transactions for a specific token for a given date range
|
-- This query gets transactions for a specific token for a given date range
|
||||||
WITH date_range AS (
|
WITH date_range AS (
|
||||||
|
Loading…
Reference in New Issue
Block a user