Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions app/tag-app/src/main/resources/initsql/address_label_gp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ select address,label_type,label_name,wired_type,data,updated_at,'-1' as owner,'S
select address,label_type,label_name,'OTHER' as wired_type,0 as data,updated_at, owner, source ,'' "group",'' level,'other' category,'' trade_type,'' project,'' asset,'' bus_type from address_label_third_party union all
select address,label_type,label_name,'OTHER' as wired_type,0 as data,updated_at,owner, source ,'' "group",'' level,'other' category,'' trade_type,'' project,'' asset,'' bus_type from address_label_ugc;


update
address_info b
set
days = trunc((extract(epoch from cast( now() as TIMESTAMP)) - A."timestamp")/(24 * 60 * 60))
from
block_timestamp A
where
A.height = b.first_up_chain_block_height
and b.days is null;

drop table if exists address_labels_json_gin;
create table address_labels_json_gin
(
Expand All @@ -109,10 +120,12 @@ truncate
vacuum address_labels_json_gin;

INSERT INTO address_labels_json_gin(address,
days,
address_type,
labels,
updated_at)
SELECT address_label_gp.address,
address_info.days,
CASE
WHEN COUNT(contract_address) > 0 THEN 'c'
ELSE 'p'
Expand All @@ -139,14 +152,14 @@ FROM address_label_gp
LEFT JOIN address_info ON (address_label_gp.address = address_info.address)
GROUP BY (address_label_gp.address, address_info.days);

UPDATE address_labels_json_gin
SET days = subquery.days
FROM (SELECT address_info.address,
trunc((extract(epoch FROM CAST(NOW() AS TIMESTAMP)) - block_timestamp.timestamp) / (24 * 60 * 60)) AS days
FROM block_timestamp
LEFT JOIN address_info
ON (address_info.first_up_chain_block_height = block_timestamp.height)) AS subquery
WHERE address_labels_json_gin.address = subquery.address;
-- UPDATE address_labels_json_gin
-- SET days = subquery.days
-- FROM (SELECT address_info.address,
-- trunc((extract(epoch FROM CAST(NOW() AS TIMESTAMP)) - block_timestamp.timestamp) / (24 * 60 * 60)) AS days
-- FROM block_timestamp
-- LEFT JOIN address_info
-- ON (address_info.first_up_chain_block_height = block_timestamp.height)) AS subquery
-- WHERE address_labels_json_gin.address = subquery.address;


CREATE TABLE tag_result AS SELECT * FROM address_labels_json_gin LIMIT 1;
Expand Down
77 changes: 32 additions & 45 deletions app/tag-app/src/main/resources/initsql/static_asset_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,52 @@ create table static_asset_level_data
(
static_code varchar(200) not null,
address_num numeric(250, 20) NULL,
dimension_type varchar(50) null,---维度类型:token\project\action
dimension_type varchar(50) null,---维度类型:asset\project\action
wired_type varchar(50) null,---维度类型:token\project\action
bus_type varchar(50) null,---业务类型:vol balance activity
"level" varchar(50) null----级别类型 L1\L2....
);


----按资产+级别
insert into static_asset_level_data(static_code,address_num,dimension_type,bus_type,level)
select
case when asset is null or asset='' then 'total' else asset end as static_code,
count(1) as address_num,
'defi' as dimension_type,
bus_type,
level
from
address_label_gp where (bus_type='balance' or bus_type='activity' or bus_type='volume') and category='grade'
and asset in(select distinct token_name from top_ten_token where token_type='defi')
group by asset,bus_type,level;

----按资产+级别
insert into static_asset_level_data(static_code,address_num,dimension_type,bus_type,level)
insert into static_asset_level_data(static_code,address_num,dimension_type,wired_type,bus_type,level)
select
case when asset is null or asset='' then 'total' else asset end as static_code,
case when asset is null or asset='' or asset='ALL' then 'total' else asset end as static_code,
count(1) as address_num,
'nft' as dimension_type,
'asset' as dimension_type,
case when lower(wired_type)='defi' then 'token' else lower(wired_type) end as wired_type,
bus_type,
level
from
address_label_gp where (bus_type='balance' or bus_type='activity' or bus_type='volume') and category='grade'
and asset in(select distinct token_name from top_ten_token where token_type='nft')
group by asset,bus_type,level;
and asset in(select distinct token_name from top_ten_token)
group by asset,wired_type,bus_type,level;

----按平台+级别
insert into static_asset_level_data(static_code,address_num,dimension_type,bus_type,level)
insert into static_asset_level_data(static_code,address_num,dimension_type,wired_type,bus_type,level)
select
case when project is null or project='' then 'total' else project end as static_code,
count(1) as address_num,
'platorm' as dimension_type,
case when lower(wired_type)='defi' then 'token' else lower(wired_type) end as wired_type,
bus_type,
level
from
address_label_gp where (bus_type='balance' or bus_type='activity' or bus_type='volume') and category='grade'
group by project,bus_type,level;
group by project,wired_type,bus_type,level;


----按行为+级别
insert into static_asset_level_data(static_code,address_num,dimension_type,bus_type,level)
insert into static_asset_level_data(static_code,address_num,dimension_type,wired_type,bus_type,level)
select
case when trade_type is null or trade_type='' then 'total' else trade_type end as static_code,
case when trade_type is null or trade_type='' or trade_type='ALL' then 'total' else trade_type end as static_code,
count(1) as address_num,
'action' as dimension_type,
case when lower(wired_type)='defi' then 'token' else lower(wired_type) end as wired_type,
bus_type,
level
from
address_label_gp where (bus_type='balance' or bus_type='activity' or bus_type='volume') and category='grade'
group by trade_type,bus_type,level;
group by trade_type,wired_type,bus_type,level;



Expand All @@ -67,26 +57,30 @@ DROP TABLE if EXISTS static_asset_level_data_json;
create table static_asset_level_data_json
(
static_code varchar(200) not null,
dimension_type varchar(50) null,---维度类型:token\project\action
dimension_type varchar(50) null,---维度类型:asset\project\action
wired_type varchar(50) null,---维度类型:token\nft\web3
bus_type varchar(50) null,---业务类型:vol balance activity
json_text text
);
insert
into
static_asset_level_data_json(static_code,
dimension_type,
wired_type,
bus_type,
json_text)
select
sald.static_code ,
sald.dimension_type ,
sald.wired_type ,
sald.bus_type,
JSON_BUILD_OBJECT(bus_type, json_agg(JSON_BUILD_OBJECT('level_name', level, 'level_address_num', address_num)))
from
static_asset_level_data sald
group by
static_code,
dimension_type,
wired_type,
bus_type;

------计算聚合项目数据(static_code聚合)
Expand All @@ -95,35 +89,40 @@ create table static_item_json
(
static_code varchar(200) not null,
dimension_type varchar(50) null,---维度类型:token\project\action
wired_type varchar(50) null,---维度类型:token\nft\web3
json_text text
);
insert into static_item_json(static_code,dimension_type,json_text)
insert into static_item_json(static_code,dimension_type,wired_type,json_text)
select
sald.static_code ,
sald.dimension_type,
sald.wired_type,
JSON_BUILD_OBJECT('item_code',static_code, 'item_entity',json_agg(json_text::jsonb))
from
static_asset_level_data_json sald
group by
static_code,
dimension_type;
dimension_type,
wired_type;

------计算聚合类型数据(dimension_type聚合)token\project\action
DROP TABLE if EXISTS static_type_json;
create table static_type_json
(
dimension_type varchar(50) null,---维度类型:token\project\action
dimension_type varchar(50) null,---维度类型:asset\project\action
wired_type varchar(50) null,---维度类型:token\nft\web3
json_text text
);

insert into static_type_json
select
sald.dimension_type,
JSON_BUILD_OBJECT(dimension_type, json_agg(json_text::jsonb))
sald.wired_type,
JSON_BUILD_OBJECT(wired_type, json_agg(json_text::jsonb))
from
static_item_json sald
group by
dimension_type;
dimension_type,wired_type;

------计算聚合类型数据(dimension_type聚合)token\project\action
DROP TABLE if EXISTS static_category_json;
Expand All @@ -138,18 +137,6 @@ select
sald.dimension_type,
JSON_BUILD_OBJECT(dimension_type, json_agg(json_text::jsonb))
from
(select case when dimension_type='defi' or dimension_type='nft' then 'asset' else dimension_type end as
dimension_type,json_text from static_type_json ) sald
static_type_json sald
group by
dimension_type;

update static_category_json set json_text =subquery.json_text from
(select * from static_type_json) as subquery where static_category_json.dimension_type<>'defi' and
static_category_json.dimension_type = subquery.dimension_type;







dimension_type;
20 changes: 10 additions & 10 deletions app/tag-app/src/main/resources/initsql/static_crowd_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ from
,
address
from
address_label_gp_test where label_name in('crowd_active_users',
'crowd_elite',
'crowd_nft_active_users',
'crowd_long_term_holder',
'crowd_nft_whale',
'crowd_nft_high_demander',
'crowd_token_whale',
'crowd_defi_active_users',
'crowd_defi_high_demander',
'crowd_web3_active_users')
address_label_gp where label_name in('crowd_active_users',
'crowd_elite',
'crowd_nft_active_users',
'crowd_long_term_holder',
'crowd_nft_whale',
'crowd_nft_high_demander',
'crowd_token_whale',
'crowd_defi_active_users',
'crowd_defi_high_demander',
'crowd_web3_active_users')
group by
label_name,
address) out_t
Expand Down
Loading