|
|
|
@ -31,18 +31,18 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the query for fetching the number of successful transactions in a week. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_success_transactions_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_success_transactions_number_query do |
|
|
|
|
@spec success_transactions_number_query() :: Ecto.Query.t() |
|
|
|
|
def success_transactions_number_query do |
|
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
|
Transaction |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|
|> where([tx], tx.status == ^1) |
|
|
|
|
|> select([tx], count(tx.hash)) |
|
|
|
|
else |
|
|
|
|
Transaction |
|
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|
|> where([tx, block], tx.status == ^1) |
|
|
|
|
|> select([tx, block], count(tx.hash)) |
|
|
|
@ -52,13 +52,13 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the query for the number of smart contracts deployed in the current week. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_deployed_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_deployed_smart_contracts_number_query do |
|
|
|
|
@spec deployed_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
|
def deployed_smart_contracts_number_query do |
|
|
|
|
transactions_query = |
|
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
|
Transaction |
|
|
|
|
|> where([tx], not is_nil(tx.created_contract_address_hash)) |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|
|> where([tx], tx.status == ^1) |
|
|
|
|
|> select([tx], tx.created_contract_address_hash) |
|
|
|
@ -67,7 +67,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|
|> where([tx], not is_nil(tx.created_contract_address_hash)) |
|
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx, block], tx.status == ^1) |
|
|
|
|
|> select([tx, block], tx.created_contract_address_hash) |
|
|
|
|
end |
|
|
|
@ -77,7 +77,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
# InternalTransaction |
|
|
|
|
# |> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
|
# |> where([it, tx], not is_nil(it.created_contract_address_hash)) |
|
|
|
|
# |> where([it, tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
# |> where([it, tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
# |> where([it, tx], tx.block_consensus == true) |
|
|
|
|
# |> where([it, tx], tx.status == ^1) |
|
|
|
|
# |> select([it, tx], it.created_contract_address_hash) |
|
|
|
@ -97,41 +97,41 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the query for the number of verified smart contracts in the current week. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_verified_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_verified_smart_contracts_number_query do |
|
|
|
|
@spec verified_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
|
def verified_smart_contracts_number_query do |
|
|
|
|
SmartContract |
|
|
|
|
|> where([sc], sc.inserted_at >= ago(7, "day")) |
|
|
|
|
|> where([sc], sc.inserted_at >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> select([sc], count(sc.address_hash)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the query for the number of new addresses in the current week. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_new_addresses_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_new_addresses_number_query do |
|
|
|
|
@spec new_addresses_number_query() :: Ecto.Query.t() |
|
|
|
|
def new_addresses_number_query do |
|
|
|
|
Address |
|
|
|
|
|> where([a], a.inserted_at >= ago(7, "day")) |
|
|
|
|
|> where([a], a.inserted_at >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> select([a], count(a.hash)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the query for the number of new tokens detected in the current week. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_new_tokens_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_new_tokens_number_query do |
|
|
|
|
@spec new_tokens_number_query() :: Ecto.Query.t() |
|
|
|
|
def new_tokens_number_query do |
|
|
|
|
Token |
|
|
|
|
|> where([token], token.inserted_at >= ago(7, "day")) |
|
|
|
|
|> where([token], token.inserted_at >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> select([token], count(token.contract_address_hash)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the query for the number of new token transfers detected in the current week. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_new_token_transfers_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_new_token_transfers_number_query do |
|
|
|
|
@spec new_token_transfers_number_query() :: Ecto.Query.t() |
|
|
|
|
def new_token_transfers_number_query do |
|
|
|
|
TokenTransfer |
|
|
|
|
|> join(:inner, [tt], block in Block, on: block.number == tt.block_number) |
|
|
|
|
|> where([tt, block], block.timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tt, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tt, block], block.consensus == true) |
|
|
|
|
|> select([tt, block], fragment("COUNT(*)")) |
|
|
|
|
end |
|
|
|
@ -139,17 +139,17 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
@doc """ |
|
|
|
|
Retrieves the query for the number of addresses initiated transactions in the current week. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_simplified_active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_simplified_active_addresses_number_query do |
|
|
|
|
@spec simplified_active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
|
def simplified_active_addresses_number_query do |
|
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
|
Transaction |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash)) |
|
|
|
|
else |
|
|
|
|
Transaction |
|
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash)) |
|
|
|
|
end |
|
|
|
@ -159,12 +159,12 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
Retrieves the query for the number of active EOA and smart-contract addresses (from/to/contract participated in transactions, internal transactions, token transfers) in the current week. |
|
|
|
|
This query is currently unused since the very low performance: it doesn't return results in 1 hour. |
|
|
|
|
""" |
|
|
|
|
@spec weekly_active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
|
def weekly_active_addresses_number_query do |
|
|
|
|
@spec active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
|
def active_addresses_number_query do |
|
|
|
|
transactions_query = |
|
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
|
Transaction |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|
|> distinct(true) |
|
|
|
|
|> select([tx], %{ |
|
|
|
@ -179,7 +179,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
else |
|
|
|
|
Transaction |
|
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|
|> distinct(true) |
|
|
|
|
|> select([tx, block], %{ |
|
|
|
@ -197,7 +197,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
|
InternalTransaction |
|
|
|
|
|> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
|
|> where([it, tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([it, tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([it, tx], tx.block_consensus == true) |
|
|
|
|
|> where([it, tx], tx.status == ^1) |
|
|
|
|
|> select([it, tx], %{ |
|
|
|
@ -214,7 +214,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
InternalTransaction |
|
|
|
|
|> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|
|> where([it, tx, block], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([it, tx, block], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([it, tx, block], block.consensus == true) |
|
|
|
|
|> where([it, tx, block], tx.status == ^1) |
|
|
|
|
|> select([it, tx, block], %{ |
|
|
|
@ -233,7 +233,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
|
TokenTransfer |
|
|
|
|
|> join(:inner, [tt], transaction in assoc(tt, :transaction)) |
|
|
|
|
|> where([tt, tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tt, tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tt, tx], tx.block_consensus == true) |
|
|
|
|
|> where([tt, tx], tx.status == ^1) |
|
|
|
|
|> select([tt, tx], %{ |
|
|
|
@ -245,7 +245,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
TokenTransfer |
|
|
|
|
|> join(:inner, [tt], transaction in assoc(tt, :transaction)) |
|
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|
|> where([tt, tx, block], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|
|> where([tt, tx, block], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|
|> where([tt, tx, block], block.consensus == true) |
|
|
|
|
|> where([tt, tx, block], tx.status == ^1) |
|
|
|
|
|> select([tt, tx, block], %{ |
|
|
|
@ -266,4 +266,8 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|
select: fragment("COUNT(DISTINCT ?)", q.address_hash) |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp update_period_hours do |
|
|
|
|
Application.get_env(:explorer, Explorer.Chain.Metrics)[:update_period_hours] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|