mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-21 06:21:04 +00:00
fix: Relates to #9. Reuse calculation of average block time
Issues: * Unable to import `blockAverage` into Chain.ts or Node.ts due to Issue #21. * TypeScript says `[ts] Module '"/Users/Me/code/blockchain/clones/paritytech/dotstats/packages/common/build/index"' has no exported member 'blockAverage'.`
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { Maybe, Types } from '@dotstats/common';
|
||||
|
||||
export function blockAverage(blockTimes: Array<number>): Maybe<Types.Milliseconds> {
|
||||
let count = 0;
|
||||
let sum = 0;
|
||||
|
||||
for (const time of blockTimes) {
|
||||
if (time) {
|
||||
count += 1;
|
||||
sum += time;
|
||||
}
|
||||
}
|
||||
|
||||
if (count === 0) {
|
||||
return 0 as Types.Milliseconds;
|
||||
}
|
||||
|
||||
return (sum / count) as Types.Milliseconds;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './helpers';
|
||||
export * from './id';
|
||||
export * from './block';
|
||||
|
||||
import * as Types from './types';
|
||||
import * as FeedMessage from './feed';
|
||||
|
||||
Reference in New Issue
Block a user