Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bids 2006/validator rank via api #235

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/app/components/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@
<ion-label>General</ion-label>
</ion-list-header>

<ion-list class="performance">
<ion-list class="performance" *ngIf="data.bestRank != 0">
<ion-item lines="none" *ngIf="data.bestRank == data.worstRank">
<ion-label class="stat-title">
<span tooltip="Global rank of this validator, based on last 7 days" placement="right" trigger="click" hideDelayAfterClick="5000"> Rank </span>
Expand All @@ -734,7 +734,7 @@
<ion-icon name="ribbon-outline" class="rank-ribbon"></ion-icon>

<span class="rank-text">
{{ data.bestRank | percentageabs : data.currentEpoch.validatorscount : rankPercentMode : 'Top ' }}
{{ data.bestRank | percentageabs : data.bestTopPercentage : rankPercentMode : 'Top ' }}
</span>
</ion-label>
</ion-item>
Expand All @@ -746,7 +746,7 @@
<ion-label class="value left">
<ion-icon name="ribbon-outline" class="rank-ribbon"></ion-icon>
<span class="rank-text">
{{ data.bestRank | percentageabs : data.currentEpoch.validatorscount : rankPercentMode : 'Top ' }}
{{ data.bestRank | percentageabs : data.bestTopPercentage : rankPercentMode : 'Top ' }}
</span>
</ion-label>
</div>
Expand All @@ -768,7 +768,7 @@
<ion-label class="value">
<ion-icon name="ribbon-outline" class="rank-ribbon"></ion-icon>
<span class="rank-text">
{{ data.worstRank | percentageabs : data.currentEpoch.validatorscount : rankPercentMode : 'Top ' }}
{{ data.worstRank | percentageabs : data.worstTopPercentage : rankPercentMode : 'Top ' }}
</span>
</ion-label>
</div>
Expand Down
25 changes: 23 additions & 2 deletions src/app/controllers/OverviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export type OverviewData = {
activationeligibilityCount: number
bestRank: number
worstRank: number
bestTopPercentage: number
worstTopPercentage: number
displayAttrEffectiveness: boolean
attrEffectiveness: number

Expand Down Expand Up @@ -157,6 +159,7 @@ export default class OverviewController {
const overallBalance = this.sumBigIntBalanceRP(validators, (cur) => new BigNumber(cur.data.balance))
const validatorCount = validators.length
const activeValidators = this.getActiveValidators(validators)
const offlineValidators = this.getOfflineValidators(validators)

const consensusPerf = this.getConsensusPerformance(validators, validatorDepositActive)

Expand Down Expand Up @@ -190,8 +193,18 @@ export default class OverviewController {
}
}

const bestRank = findLowest(validators, (cur) => cur.data.rank7d)
const worstRank = findHighest(validators, (cur) => cur.data.rank7d)
let bestRank = 0
let bestTopPercentage = 0
let worstRank = 0
let worstTopPercentage = 0
const rankRelevantValidators = activeValidators.concat(offlineValidators)
if (rankRelevantValidators.length > 0) {
bestRank = findLowest(rankRelevantValidators, (cur) => cur.data.rank7d)
bestTopPercentage = findLowest(rankRelevantValidators, (cur) => cur.data.rankpercentage)
worstRank = findHighest(rankRelevantValidators, (cur) => cur.data.rank7d)
worstTopPercentage = findHighest(rankRelevantValidators, (cur) => cur.data.rankpercentage)
}

const rocketpoolValiCount = sumBigInt(validators, (cur) => (cur.rocketpool ? new BigNumber(1) : new BigNumber(0)))
const feeSum = sumBigInt(validators, (cur) =>
cur.rocketpool ? new BigNumber(cur.rocketpool.minipool_node_fee).multipliedBy('100') : new BigNumber('0')
Expand All @@ -213,7 +226,9 @@ export default class OverviewController {
overallBalance: overallBalance,
validatorCount: validatorCount,
bestRank: bestRank,
bestTopPercentage: bestTopPercentage,
worstRank: worstRank,
worstTopPercentage: worstTopPercentage,
attrEffectiveness: attrEffectiveness,
displayAttrEffectiveness: displayAttrEffectiveness,
consensusPerformance: consensusPerf,
Expand Down Expand Up @@ -810,6 +825,12 @@ export default class OverviewController {
})
}

private getOfflineValidators(validators: Validator[]) {
return validators.filter((item) => {
return item.state == ValidatorState.OFFLINE
})
}

private getSlashedValidators(validators: Validator[]) {
return validators.filter((item) => {
return item.state == ValidatorState.SLASHED
Expand Down
30 changes: 22 additions & 8 deletions src/app/pipes/percentageabs.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,31 @@ import BigNumber from 'bignumber.js'
name: 'percentageabs',
})
export class PercentageabsPipe implements PipeTransform {
transform(value_: number | BigNumber, max_: number | BigNumber, percentMode: boolean, preablePrct = ''): string {
LuccaBitfly marked this conversation as resolved.
Show resolved Hide resolved
const value = value_ instanceof BigNumber ? value_ : new BigNumber(value_)
const max = max_ instanceof BigNumber ? max_ : new BigNumber(max_)

/**
* Takes an absolute value (`value_`) and a relative percentage representation of it (`percentage_` ) and returns a formatted string of one of those (based on `percentMode`).
*
* @param {number | BigNumber} value_ - The absolute value to be shown (used when `percentMode` is false).
* @param {number | BigNumber} percentage_ - The relative percentage representation for the value (used when `percentMode` is true)
* @param {boolean} percentMode - A flag indicating whether to use `value_` (false) or `percentage_` (true).
* @param {string} [prefix=''] - An optional prefix to prepend to the resulting string if the absolute value is shown.
* @returns {string} The formatted string.
*/
transform(value_: number | BigNumber, percentage_: number | BigNumber, percentMode: boolean, prefix = ''): string {
if (percentMode) {
let percentValue = value.dividedBy(max).multipliedBy(100).decimalPlaces(1)
if (percentValue.toNumber() <= 0.1) {
percentValue = value.dividedBy(max).multipliedBy(100).decimalPlaces(3)
const percentage = percentage_ instanceof BigNumber ? percentage_ : new BigNumber(percentage_)
const percentageNumber = percentage.toNumber()
if (percentageNumber <= 0.1) {
return prefix + '0.1 %'
}
let decimalPlaces = 1
if (percentageNumber < 1.0) {
decimalPlaces = 3
} else if (percentageNumber < 10.0) {
decimalPlaces = 2
}
return preablePrct + percentValue.toString() + ' %'
return prefix + percentage.decimalPlaces(decimalPlaces).toString() + ' %'
} else {
const value = value_ instanceof BigNumber ? value_ : new BigNumber(value_)
return value.toFormat()
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/requests/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ export interface ValidatorResponse {
performance31d: BigNumber
performance365d: BigNumber
performance7d: BigNumber
rank7d: number
performancetotal: BigNumber
rank7d: number
rankpercentage: number
}

export interface AttestationPerformanceResponse {
Expand Down