Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
balance_tracker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
balance_tracker
Commits
3ab5ca75
Commit
3ab5ca75
authored
1 month ago
by
Michal Zander
Browse files
Options
Downloads
Patches
Plain Diff
Adjusted code for linter compliance on CI
parent
e79042b6
No related branches found
No related tags found
2 merge requests
!168
Update return types: VEST balances should be returned as strings to address JSON limitations
,
!160
Add daily and monthly aggregations for balances
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.sqlfluff
+3
-1
3 additions, 1 deletion
.sqlfluff
backend/aggregated_history.sql
+62
-57
62 additions, 57 deletions
backend/aggregated_history.sql
db/btracker_app.sql
+1
-3
1 addition, 3 deletions
db/btracker_app.sql
with
66 additions
and
61 deletions
.sqlfluff
+
3
−
1
View file @
3ab5ca75
[sqlfluff]
[sqlfluff]
dialect = postgres
dialect = postgres
max_line_length = 150
max_line_length = 150
exclude_rules = CP03, LT01, CP05, CP04
exclude_rules = CP03
warnings = LT01, CP05, PRS
This diff is collapsed.
Click to expand it.
backend/aggregated_history.sql
+
62
−
57
View file @
3ab5ca75
-- noqa: disable=AL01, AM05
SET
ROLE
btracker_owner
;
SET
ROLE
btracker_owner
;
DROP
TYPE
IF
EXISTS
balance_history_aggregation
CASCADE
;
DROP
TYPE
IF
EXISTS
balance_history_aggregation
CASCADE
;
...
@@ -10,38 +12,41 @@ CREATE TYPE balance_history_aggregation AS (
...
@@ -10,38 +12,41 @@ CREATE TYPE balance_history_aggregation AS (
CREATE
OR
REPLACE
VIEW
balance_history_by_year
AS
CREATE
OR
REPLACE
VIEW
balance_history_by_year
AS
WITH
get_year
AS
(
WITH
get_year
AS
(
SELECT
SELECT
account
,
account
,
nai
,
nai
,
balance
,
balance
,
min_balance
,
min_balance
,
max_balance
,
max_balance
,
source_op_block
,
source_op_block
,
date_trunc
(
'year'
,
updated_at
)
AS
by_year
,
updated_at
,
updated_at
DATE_TRUNC
(
'year'
,
updated_at
)
AS
by_year
FROM
balance_history_by_month
FROM
balance_history_by_month
),
),
get_latest_updates
AS
(
get_latest_updates
AS
(
SELECT
SELECT
account
,
account
,
nai
,
nai
,
balance
,
balance
,
source_op_block
,
source_op_block
,
by_year
,
by_year
,
ROW_NUMBER
()
OVER
(
PARTITION
BY
account
,
nai
,
by_year
ORDER
BY
updated_at
DESC
)
AS
rn_by_year
ROW_NUMBER
()
OVER
(
PARTITION
BY
account
,
nai
,
by_year
ORDER
BY
updated_at
DESC
)
AS
rn_by_year
FROM
get_year
bh
FROM
get_year
),
),
get_min_max_balances_by_year
AS
(
get_min_max_balances_by_year
AS
(
SELECT
SELECT
account
,
account
,
nai
,
nai
,
by_year
,
by_year
,
MAX
(
max_balance
)
AS
max_balance
,
MAX
(
max_balance
)
AS
max_balance
,
MIN
(
min_balance
)
AS
min_balance
MIN
(
min_balance
)
AS
min_balance
FROM
get_year
FROM
get_year
GROUP
BY
account
,
nai
,
by_year
GROUP
BY
account
,
nai
,
by_year
)
)
SELECT
SELECT
gl
.
account
,
gl
.
account
,
gl
.
nai
,
gl
.
nai
,
gl
.
balance
,
gl
.
balance
,
...
@@ -49,17 +54,17 @@ get_min_max_balances_by_year AS (
...
@@ -49,17 +54,17 @@ get_min_max_balances_by_year AS (
gm
.
max_balance
,
gm
.
max_balance
,
gl
.
source_op_block
,
gl
.
source_op_block
,
gl
.
by_year
AS
updated_at
gl
.
by_year
AS
updated_at
FROM
get_latest_updates
gl
FROM
get_latest_updates
gl
JOIN
get_min_max_balances_by_year
gm
ON
gl
.
account
=
gm
.
account
AND
gl
.
nai
=
gm
.
nai
AND
gl
.
by_year
=
gm
.
by_year
JOIN
get_min_max_balances_by_year
gm
ON
gl
.
account
=
gm
.
account
AND
gl
.
nai
=
gm
.
nai
AND
gl
.
by_year
=
gm
.
by_year
WHERE
rn_by_year
=
1
;
WHERE
gl
.
rn_by_year
=
1
;
CREATE
OR
REPLACE
FUNCTION
get_balance_history_aggregation
(
CREATE
OR
REPLACE
FUNCTION
get_balance_history_aggregation
(
_account_id
INT
,
_account_id
INT
,
_coin_type
INT
,
_coin_type
INT
,
_granularity
btracker_endpoints
.
granularity
,
_granularity
btracker_endpoints
.
granularity
,
_direction
btracker_endpoints
.
sort_direction
,
_direction
btracker_endpoints
.
sort_direction
,
_from_block
INT
,
_from_block
INT
,
_to_block
INT
_to_block
INT
)
)
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
LANGUAGE
'plpgsql'
LANGUAGE
'plpgsql'
...
@@ -127,11 +132,11 @@ END
...
@@ -127,11 +132,11 @@ END
$$
;
$$
;
CREATE
OR
REPLACE
FUNCTION
get_balance_history_by_day
(
CREATE
OR
REPLACE
FUNCTION
get_balance_history_by_day
(
_account_id
INT
,
_account_id
INT
,
_coin_type
INT
,
_coin_type
INT
,
_direction
btracker_endpoints
.
sort_direction
,
_direction
btracker_endpoints
.
sort_direction
,
_from_block
INT
,
_from_block
INT
,
_to_block
INT
_to_block
INT
)
)
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
LANGUAGE
'plpgsql'
LANGUAGE
'plpgsql'
...
@@ -139,8 +144,8 @@ STABLE
...
@@ -139,8 +144,8 @@ STABLE
AS
AS
$$
$$
DECLARE
DECLARE
_from_timestamp
TIMESTAMP
:
=
date_trunc
(
'day'
,(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_from_block
)::
TIMESTAMP
);
_from_timestamp
TIMESTAMP
:
=
DATE_TRUNC
(
'day'
,(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_from_block
)::
TIMESTAMP
);
_to_timestamp
TIMESTAMP
:
=
date_trunc
(
'day'
,
(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_to_block
)::
TIMESTAMP
);
_to_timestamp
TIMESTAMP
:
=
DATE_TRUNC
(
'day'
,
(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_to_block
)::
TIMESTAMP
);
BEGIN
BEGIN
RETURN
QUERY
(
RETURN
QUERY
(
...
@@ -221,11 +226,11 @@ END
...
@@ -221,11 +226,11 @@ END
$$
;
$$
;
CREATE
OR
REPLACE
FUNCTION
get_balance_history_by_month
(
CREATE
OR
REPLACE
FUNCTION
get_balance_history_by_month
(
_account_id
INT
,
_account_id
INT
,
_coin_type
INT
,
_coin_type
INT
,
_direction
btracker_endpoints
.
sort_direction
,
_direction
btracker_endpoints
.
sort_direction
,
_from_block
INT
,
_from_block
INT
,
_to_block
INT
_to_block
INT
)
)
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
LANGUAGE
'plpgsql'
LANGUAGE
'plpgsql'
...
@@ -233,8 +238,8 @@ STABLE
...
@@ -233,8 +238,8 @@ STABLE
AS
AS
$$
$$
DECLARE
DECLARE
_from_timestamp
TIMESTAMP
:
=
date_trunc
(
'month'
,(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_from_block
)::
TIMESTAMP
);
_from_timestamp
TIMESTAMP
:
=
DATE_TRUNC
(
'month'
,(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_from_block
)::
TIMESTAMP
);
_to_timestamp
TIMESTAMP
:
=
date_trunc
(
'month'
,
(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_to_block
)::
TIMESTAMP
);
_to_timestamp
TIMESTAMP
:
=
DATE_TRUNC
(
'month'
,
(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_to_block
)::
TIMESTAMP
);
BEGIN
BEGIN
RETURN
QUERY
(
RETURN
QUERY
(
WITH
date_series
AS
(
WITH
date_series
AS
(
...
@@ -314,11 +319,11 @@ END
...
@@ -314,11 +319,11 @@ END
$$
;
$$
;
CREATE
OR
REPLACE
FUNCTION
get_balance_history_by_year
(
CREATE
OR
REPLACE
FUNCTION
get_balance_history_by_year
(
_account_id
INT
,
_account_id
INT
,
_coin_type
INT
,
_coin_type
INT
,
_direction
btracker_endpoints
.
sort_direction
,
_direction
btracker_endpoints
.
sort_direction
,
_from_block
INT
,
_from_block
INT
,
_to_block
INT
_to_block
INT
)
)
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
RETURNS
SETOF
balance_history_aggregation
-- noqa: LT01, CP05
LANGUAGE
'plpgsql'
LANGUAGE
'plpgsql'
...
@@ -326,8 +331,8 @@ STABLE
...
@@ -326,8 +331,8 @@ STABLE
AS
AS
$$
$$
DECLARE
DECLARE
_from_timestamp
TIMESTAMP
:
=
date_trunc
(
'year'
,(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_from_block
)::
TIMESTAMP
);
_from_timestamp
TIMESTAMP
:
=
DATE_TRUNC
(
'year'
,(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_from_block
)::
TIMESTAMP
);
_to_timestamp
TIMESTAMP
:
=
date_trunc
(
'year'
,
(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_to_block
)::
TIMESTAMP
);
_to_timestamp
TIMESTAMP
:
=
DATE_TRUNC
(
'year'
,
(
SELECT
b
.
created_at
FROM
hive
.
blocks_view
b
WHERE
b
.
num
=
_to_block
)::
TIMESTAMP
);
BEGIN
BEGIN
RETURN
QUERY
(
RETURN
QUERY
(
WITH
date_series
AS
(
WITH
date_series
AS
(
...
...
This diff is collapsed.
Click to expand it.
db/btracker_app.sql
+
1
−
3
View file @
3ab5ca75
-- noqa: disable=CP03
SET
ROLE
btracker_owner
;
SET
ROLE
btracker_owner
;
DO
$$
DO
$$
...
@@ -402,7 +400,7 @@ $$;
...
@@ -402,7 +400,7 @@ $$;
*/
*/
CREATE
OR
REPLACE
PROCEDURE
main
(
CREATE
OR
REPLACE
PROCEDURE
main
(
IN
_appContext
hive
.
context_name
,
IN
_appContext
hive
.
context_name
,
IN
_maxBlockLimit
INT
=
NULL
IN
_maxBlockLimit
INT
=
null
)
)
LANGUAGE
'plpgsql'
LANGUAGE
'plpgsql'
AS
AS
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment