Skip to content

Commit

Permalink
Feature: histograms for block stats (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored Oct 27, 2023
1 parent a773784 commit 676192e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cmd/api/docs/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cmd/api/docs/swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/api/handler/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (sh StatsHandler) Summary(c echo.Context) error {
}

type histogramRequest struct {
Table string `example:"block" param:"table" swaggertype:"string" validate:"required,oneof=block tx event message"`
Table string `example:"block" param:"table" swaggertype:"string" validate:"required,oneof=block block_stats tx event message"`
Function string `example:"count" param:"function" swaggertype:"string" validate:"required,oneof=avg sum min max count"`
Timeframe string `example:"hour" param:"timeframe" swaggertype:"string" validate:"required,oneof=hour day week month year"`
Column string `example:"fee" query:"column" swaggertype:"string" validate:"omitempty"`
Expand All @@ -90,7 +90,7 @@ type histogramRequest struct {
// @Description.markdown histogram
// @Tags stats
// @ID stats-histogram
// @Param table path string true "Table name" Enums(block, tx, event, message)
// @Param table path string true "Table name" Enums(block, block_stats, tx, event, message)
// @Param function path string true "Function name" Enums(min, max, avg, sum, count)
// @Param timeframe path string true "Timeframe" Enums(hour, day, week, month, year)
// @Param column query string false "Column name which will be used for computation. Optional for count"
Expand Down
8 changes: 8 additions & 0 deletions cmd/api/markdown/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Returns string value by passed table and function.

### Availiable tables
* `block`
* `block_stats`
* `tx`
* `message`
* `event`
Expand All @@ -23,9 +24,16 @@ Returns string value by passed table and function.
#### Block
* `height` -- min max
* `time` -- min max

#### Block stats
* `height` -- min max
* `time` -- min max
* `tx_count` -- min max sum avg
* `events_count` -- min max sum avg
* `blobs_size` -- min max sum avg
* `block_time` -- min max sum avg
* `supply_chnge` -- min max sum avg
* `inflation_rate` -- min max avg
* `fee` -- min max sum avg

#### Tx
Expand Down
5 changes: 3 additions & 2 deletions internal/storage/block_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package storage

import (
"context"
"github.com/celenium-io/celestia-indexer/internal/storage/types"
"time"

"github.com/celenium-io/celestia-indexer/internal/storage/types"

pkgTypes "github.com/celenium-io/celestia-indexer/pkg/types"
"github.com/shopspring/decimal"
"github.com/uptrace/bun"
Expand All @@ -28,7 +29,7 @@ type BlockStats struct {
TxCount int64 `bun:"tx_count" comment:"Count of transactions in block" stats:"func:min max sum avg"`
EventsCount int64 `bun:"events_count" comment:"Count of events in begin and end of block" stats:"func:min max sum avg"`
BlobsSize int64 `bun:"blobs_size" comment:"Summary blocks size from pay for blob" stats:"func:min max sum avg"`
BlockTime uint64 `bun:"block_time" comment:"Time in milliseconds between current and previous block" stats:"func:min max avg sum"`
BlockTime uint64 `bun:"block_time" comment:"Time in milliseconds between current and previous block" stats:"func:min max sum avg"`
SupplyChange decimal.Decimal `bun:",type:numeric" comment:"Change of total supply in the block" stats:"func:min max sum avg"`
InflationRate decimal.Decimal `bun:",type:numeric" comment:"Inflation rate" stats:"func:min max avg"`
Fee decimal.Decimal `bun:"fee,type:numeric" comment:"Summary block fee" stats:"func:min max sum avg"`
Expand Down

0 comments on commit 676192e

Please sign in to comment.