Skip to content

Commit

Permalink
refactor: update tx speed network stats to use median latency for the…
Browse files Browse the repository at this point in the history
… bucket with median load for 24h period (closes #112)
  • Loading branch information
mistakia committed Apr 10, 2024
1 parent c20eff9 commit 48bc739
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 223 deletions.
36 changes: 33 additions & 3 deletions src/views/components/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BigNumber from 'bignumber.js'

import { getNetwork, getNetworkStats, getNetworkWattHour } from '@core/network'
import { getNetworkUnconfirmedBlockCount } from '@core/accounts'
import { nanodb_actions } from '@core/nanodb'

import Network from './network'

Expand All @@ -12,22 +13,51 @@ const mapStateToProps = createSelector(
getNetworkStats,
getNetworkWattHour,
getNetworkUnconfirmedBlockCount,
(network, stats, wattHour, unconfirmed_block_pool_count) => {
(state) => state.get('nanodb'),
(network, stats, wattHour, unconfirmed_block_pool_count, nanodb) => {
const send_volume_raw = network.getIn(
['stats', 'nanodb', 'send_volume_last_24_hours'],
0
)
const send_volume_nano = BigNumber(send_volume_raw)
.shiftedBy(-30)
.toNumber()

const confirmation_latency_by_bucket = nanodb.getIn(
['block_confirmed_summary_24h', 'confirmation_latency_ms_by_bucket'],
{}
)

const buckets_sorted_by_confirmed_blocks = Object.keys(
confirmation_latency_by_bucket
).sort((a, b) => {
return (
confirmation_latency_by_bucket[a].confirmed_blocks -
confirmation_latency_by_bucket[b].confirmed_blocks
)
})

const median_bucket =
buckets_sorted_by_confirmed_blocks[
Math.floor(buckets_sorted_by_confirmed_blocks.length / 2)
]

const median_latency_of_median_bucket_by_confirmed_blocks_24h =
confirmation_latency_by_bucket[median_bucket]?.median

return {
network,
stats,
wattHour,
unconfirmed_block_pool_count,
send_volume_nano
send_volume_nano,
median_latency_of_median_bucket_by_confirmed_blocks_24h
}
}
)

export default connect(mapStateToProps)(Network)
const map_dispatch_to_props = {
get_blocks_confirmed_summary: nanodb_actions.get_blocks_confirmed_summary
}

export default connect(mapStateToProps, map_dispatch_to_props)(Network)
Loading

0 comments on commit 48bc739

Please sign in to comment.