Skip to content

Commit

Permalink
chore: rename statistics to stats to remain consistent (#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
sborrazas authored Aug 13, 2024
1 parent f44d45a commit 6988432
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 85 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ GET /v3/aex141/:contract_id/templates - nft templates
GET /v3/aex141/:contract_id/templates/:id/tokens - nft supply from a template
GET /v3/aex141/transfers - nft transfers that can be filtered by sender/recipient
GET /v3/deltastats - statistics for generations from tip of the chain
GET /v3/totalstats - aggregated statistics for generations from tip of the chain
GET /v3/minerstats - total rewards for each miner
GET /v3/stats/delta - statistics for generations from tip of the chain
GET /v3/stats/total - aggregated statistics for generations from tip of the chain
GET /v3/stats/miners - total rewards for each miner
GET /v3/statistics/transactions - statistics over time of transactions count
GET /v3/statistics/blocks - statistics over time of blocks count
GET /v3/statistics/names - statistics over time of names count
GET /v3/stats/transactions - statistics over time of transactions count
GET /v3/stats/blocks - statistics over time of blocks count
GET /v3/stats/names - statistics over time of names count
GET /v3/status - middleware status
```
Expand Down Expand Up @@ -3247,14 +3247,14 @@ $ curl -s 'https://testnet.aeternity.io/mdw/v3/aex141/transfers?to=ak_QVSUoGrJ31
---
## Statistics
## Stats
### `/v3/deltastats`
### `/v3/stats/delta`
To show a statistics for a given height, we can use "stats" endpoint:
```
$ curl -s "https://mainnet.aeternity.io/mdw/v3/deltastats?limit=1" | jq '.'
$ curl -s "https://mainnet.aeternity.io/mdw/v3/stats/delta?limit=1" | jq '.'
{
"data": [
{
Expand All @@ -3276,16 +3276,16 @@ $ curl -s "https://mainnet.aeternity.io/mdw/v3/deltastats?limit=1" | jq '.'
"oracles_registered": 0
}
],
"next": "/v3/deltastats?limit=1&cursor=419208"
"next": "/v3/stats/delta?limit=1&cursor=419208"
}
```
### `/v3/totalstats`
### `/v3/stats/total`
Aggregated (summarized) statistics are also available, showing the total sum of rewards and the token supply:
```
$ curl -s "https://mainnet.aeternity.io/mdw/v3/totalstats?scope=gen:421454-0&limit=1" | jq '.'
$ curl -s "https://mainnet.aeternity.io/mdw/v3/stats/total?scope=gen:421454-0&limit=1" | jq '.'
{
"data": [
{
Expand All @@ -3306,26 +3306,26 @@ $ curl -s "https://mainnet.aeternity.io/mdw/v3/totalstats?scope=gen:421454-0&lim
"total_token_supply": 8.945137682239798e+25
}
],
"next": "/v3/totalstats?scope=gen:421454-0&limit=1&cursor=42152"
"next": "/v3/stats/total?scope=gen:421454-0&limit=1&cursor=42152"
}
```
These endpoints allow pagination, with typical `forward/backward` direction or scope denoted by `gen/from-to`.
### `/v3/minerstats`
### `/v3/stats/miners`
Total reward given to each chain miner.
```
$ curl -s "https://mainnet.aeternity.io/mdw/v3/minerstats?limit=1" | jq '.'
$ curl -s "https://mainnet.aeternity.io/mdw/v3/stats/miners?limit=1" | jq '.'
{
"data": [
{
"miner": "ak_2wkBCLxwjfcT3DHoisV7tGVQK8uni8XQwWZ6RUKD9DDwYSz8XN",
"total_reward": 76626041292504000000
}
],
"next": "/v3/totalminers?cursor=ak_2wk52gAYRWAMi7gWP7A1oMvHEP9kpmp471VJFpvVzWMHnRc47a",
"next": "/v3/stats/miners?cursor=ak_2wk52gAYRWAMi7gWP7A1oMvHEP9kpmp471VJFpvVzWMHnRc47a",
"prev": null
}
```
Expand Down
34 changes: 17 additions & 17 deletions docs/swagger_v3/stats.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ schemas:
sum_dev_reward: 33027000000000000000
total_token_supply: 10000000000000000000000000000
last_tx_hash: th_2FHxDzpQMRTiRfpYRV3eCcsheHr1sjf9waxk7z6JDTVcgqZRXR
Statistic:
Stat:
type: object
description: Statistic
description: Stat
required:
- count
- start_date
Expand Down Expand Up @@ -329,14 +329,14 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/statistics/blocks:
/stats/blocks:
get:
deprecated: false
description: Get total blocks count statistics.
operationId: GetBlocksStatistics
description: Get total blocks count stats.
operationId: GetBlocksStats
parameters:
- name: interval_by
description: The interval in which to return the statistics.
description: The interval in which to return the stats.
in: query
required: false
schema:
Expand Down Expand Up @@ -386,22 +386,22 @@ paths:
data:
type: array
items:
$ref: '#/components/schemas/Statistic'
$ref: '#/components/schemas/Stat'
- $ref: '#/components/schemas/PaginatedResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/statistics/transactions:
/stats/transactions:
get:
deprecated: false
description: Get total transactions count statistics.
operationId: GetTransactionsStatistics
description: Get total transactions count stats.
operationId: GetTransactionsStats
parameters:
- name: interval_by
description: The interval in which to return the statistics.
description: The interval in which to return the stats.
in: query
required: false
schema:
Expand Down Expand Up @@ -448,22 +448,22 @@ paths:
data:
type: array
items:
$ref: '#/components/schemas/Statistic'
$ref: '#/components/schemas/Stat'
- $ref: '#/components/schemas/PaginatedResponse'
'400':
description: Bad request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/statistics/names:
/stats/names:
get:
deprecated: false
description: Get total names count statistics.
operationId: GetNamesStatistics
description: Get total names count stats.
operationId: GetNamesStats
parameters:
- name: interval_by
description: The interval in which to return the statistics.
description: The interval in which to return the stats.
in: query
required: false
schema:
Expand Down Expand Up @@ -503,7 +503,7 @@ paths:
data:
type: array
items:
$ref: '#/components/schemas/Statistic'
$ref: '#/components/schemas/Stats'
- $ref: '#/components/schemas/PaginatedResponse'
'400':
description: Bad request
Expand Down
12 changes: 6 additions & 6 deletions lib/ae_mdw/stats.ex
Original file line number Diff line number Diff line change
Expand Up @@ -218,29 +218,29 @@ defmodule AeMdw.Stats do
end
end

@spec fetch_transactions_statistics(State.t(), pagination(), query(), range(), cursor()) ::
@spec fetch_transactions_stats(State.t(), pagination(), query(), range(), cursor()) ::
{:ok, {pagination_cursor(), [statistic()], pagination_cursor()}}
def fetch_transactions_statistics(state, pagination, query, range, cursor) do
def fetch_transactions_stats(state, pagination, query, range, cursor) do
with {:ok, filters} <- Util.convert_params(query, &convert_transactions_param/1) do
tx_tag = Map.get(filters, :tx_type, :all)

fetch_statistics(state, pagination, filters, range, cursor, {:transactions, tx_tag})
end
end

@spec fetch_blocks_statistics(State.t(), pagination(), query(), range(), cursor()) ::
@spec fetch_blocks_stats(State.t(), pagination(), query(), range(), cursor()) ::
{:ok, {pagination_cursor(), [statistic()], pagination_cursor()}} | {:error, reason()}
def fetch_blocks_statistics(state, pagination, query, range, cursor) do
def fetch_blocks_stats(state, pagination, query, range, cursor) do
with {:ok, filters} <- Util.convert_params(query, &convert_blocks_param/1) do
type_tag = Map.get(filters, :block_type, :all)

fetch_statistics(state, pagination, filters, range, cursor, {:blocks, type_tag})
end
end

@spec fetch_names_statistics(State.t(), pagination(), query(), range(), cursor()) ::
@spec fetch_names_stats(State.t(), pagination(), query(), range(), cursor()) ::
{:ok, {pagination_cursor(), [statistic()], pagination_cursor()}} | {:error, reason()}
def fetch_names_statistics(state, pagination, query, range, cursor) do
def fetch_names_stats(state, pagination, query, range, cursor) do
with {:ok, filters} <- Util.convert_params(query, &convert_param/1) do
fetch_statistics(state, pagination, filters, range, cursor, :names_activated)
end
Expand Down
42 changes: 21 additions & 21 deletions lib/ae_mdw_web/controllers/stats_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ defmodule AeMdwWeb.StatsController do
alias AeMdwWeb.Util
alias Plug.Conn

@statistics_limit 1_000
@stats_limit 1_000

plug PaginatedPlug when action not in ~w(transactions_statistics blocks_statistics)a
plug PaginatedPlug when action not in ~w(transactions_stats blocks_stats names_stats)a

plug PaginatedPlug,
[max_limit: @statistics_limit]
when action in ~w(transactions_statistics blocks_statistics)a
[max_limit: @stats_limit]
when action in ~w(transactions_stats blocks_stats names_stats)a

action_fallback(FallbackController)

Expand Down Expand Up @@ -71,42 +71,42 @@ defmodule AeMdwWeb.StatsController do
end
end

@spec miners(Conn.t(), map()) :: Conn.t()
def miners(%Conn{assigns: assigns} = conn, _params) do
@spec miners_stats(Conn.t(), map()) :: Conn.t()
def miners_stats(%Conn{assigns: assigns} = conn, _params) do
%{state: state, pagination: pagination, cursor: cursor} = assigns

{prev_cursor, miners, next_cursor} = Miners.fetch_miners(state, pagination, cursor)

Util.render(conn, prev_cursor, miners, next_cursor)
end

@spec transactions_statistics(Conn.t(), map()) :: Conn.t()
def transactions_statistics(%Conn{assigns: assigns} = conn, _params) do
@spec transactions_stats(Conn.t(), map()) :: Conn.t()
def transactions_stats(%Conn{assigns: assigns} = conn, _params) do
%{state: state, pagination: pagination, query: query, scope: scope, cursor: cursor} = assigns

with {:ok, paginated_statistics} <-
Stats.fetch_transactions_statistics(state, pagination, query, scope, cursor) do
Util.render(conn, paginated_statistics)
with {:ok, paginated_stats} <-
Stats.fetch_transactions_stats(state, pagination, query, scope, cursor) do
Util.render(conn, paginated_stats)
end
end

@spec blocks_statistics(Conn.t(), map()) :: Conn.t()
def blocks_statistics(%Conn{assigns: assigns} = conn, _params) do
@spec blocks_stats(Conn.t(), map()) :: Conn.t()
def blocks_stats(%Conn{assigns: assigns} = conn, _params) do
%{state: state, pagination: pagination, query: query, scope: scope, cursor: cursor} = assigns

with {:ok, paginated_statistics} <-
Stats.fetch_blocks_statistics(state, pagination, query, scope, cursor) do
Util.render(conn, paginated_statistics)
with {:ok, paginated_stats} <-
Stats.fetch_blocks_stats(state, pagination, query, scope, cursor) do
Util.render(conn, paginated_stats)
end
end

@spec names_statistics(Conn.t(), map()) :: Conn.t()
def names_statistics(%Conn{assigns: assigns} = conn, _params) do
@spec names_stats(Conn.t(), map()) :: Conn.t()
def names_stats(%Conn{assigns: assigns} = conn, _params) do
%{state: state, pagination: pagination, query: query, scope: scope, cursor: cursor} = assigns

with {:ok, paginated_statistics} <-
Stats.fetch_names_statistics(state, pagination, query, scope, cursor) do
Util.render(conn, paginated_statistics)
with {:ok, paginated_stats} <-
Stats.fetch_names_stats(state, pagination, query, scope, cursor) do
Util.render(conn, paginated_stats)
end
end
end
15 changes: 7 additions & 8 deletions lib/ae_mdw_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@ defmodule AeMdwWeb.Router do
get "/accounts/:account_id/dex/swaps", DexController, :account_swaps
get "/accounts/:id/transactions/count", TxController, :count_id

get "/deltastats", StatsController, :delta_stats
get "/stats/transactions", StatsController, :transactions_stats
get "/stats/blocks", StatsController, :blocks_stats
get "/stats/names", StatsController, :names_stats
get "/stats/total", StatsController, :total_stats
get "/stats/delta", StatsController, :delta_stats
get "/stats/miners", StatsController, :miners_stats
get "/stats", StatsController, :stats
get "/minerstats", StatsController, :miners

get "/names", NameController, :names
get "/names/count", NameController, :names_count
Expand All @@ -101,12 +105,7 @@ defmodule AeMdwWeb.Router do
get "/names/:id/transfers", NameController, :name_transfers
get "/names/:id/history", NameController, :name_history

get "/statistics/transactions", StatsController, :transactions_statistics
get "/statistics/blocks", StatsController, :blocks_statistics
get "/statistics/names", StatsController, :names_statistics

get "/transfers", TransferController, :transfers
get "/totalstats/", StatsController, :total_stats
get "/status", UtilController, :status

get "/aex9", AexnTokenController, :aex9_contracts
Expand Down Expand Up @@ -216,7 +215,7 @@ defmodule AeMdwWeb.Router do

get "/deltastats", StatsController, :delta_stats
get "/stats", StatsController, :stats
get "/minerstats", StatsController, :miners
get "/minerstats", StatsController, :miners_stats
get "/wealth", WealthController, :wealth

get "/api", UtilController, :static_file,
Expand Down
Loading

0 comments on commit 6988432

Please sign in to comment.