Skip to content

Commit

Permalink
- linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed May 13, 2022
1 parent c780931 commit f12e872
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 80 deletions.
71 changes: 0 additions & 71 deletions cmd/termui/presenter/common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package presenter

import (
"math"
"math/big"

"github.com/ElrondNetwork/elrond-go/common"
)

const metricNotAvailable = "N/A"

func (psh *PresenterStatusHandler) getFromCacheAsUint64(metric string) uint64 {
Expand Down Expand Up @@ -42,67 +35,3 @@ func (psh *PresenterStatusHandler) getFromCacheAsString(metric string) string {

return valStr
}

func (psh *PresenterStatusHandler) getBigIntFromStringMetric(metric string) *big.Int {
stringValue := psh.getFromCacheAsString(metric)
bigIntValue, ok := big.NewInt(0).SetString(stringValue, 10)
if !ok {
return big.NewInt(0)
}

return bigIntValue
}

func areEqualWithZero(parameters ...uint64) bool {
for _, param := range parameters {
if param == 0 {
return true
}
}

return false
}

func (psh *PresenterStatusHandler) computeChanceToBeInConsensus() float64 {
consensusGroupSize := psh.getFromCacheAsUint64(common.MetricConsensusGroupSize)
numValidators := psh.getFromCacheAsUint64(common.MetricNumValidators)
isChanceZero := areEqualWithZero(consensusGroupSize, numValidators)
if isChanceZero {
return 0
}

return float64(consensusGroupSize) / float64(numValidators)
}

func (psh *PresenterStatusHandler) computeRoundsPerHourAccordingToHitRate() float64 {
totalBlocks := psh.GetProbableHighestNonce()
rounds := psh.GetCurrentRound()
roundDuration := psh.GetRoundTime()
secondsInAnHour := uint64(3600)
isRoundsPerHourZero := areEqualWithZero(totalBlocks, rounds, roundDuration)
if isRoundsPerHourZero {
return 0
}

hitRate := float64(totalBlocks) / float64(rounds)
roundsPerHour := float64(secondsInAnHour) / float64(roundDuration)
return hitRate * roundsPerHour
}

func (psh *PresenterStatusHandler) computeRewardsInErd() *big.Float {
rewardsValue := psh.getBigIntFromStringMetric(common.MetricRewardsValue)
denomination := psh.getFromCacheAsUint64(common.MetricDenomination)
denominationCoefficientFloat := 1.0
if denomination > 0 {
denominationCoefficientFloat /= math.Pow10(int(denomination))
}

denominationCoefficient := big.NewFloat(denominationCoefficientFloat)

if rewardsValue.Cmp(big.NewInt(0)) <= 0 {
return big.NewFloat(0)
}

rewardsInErd := big.NewFloat(0).Mul(big.NewFloat(0).SetInt(rewardsValue), denominationCoefficient)
return rewardsInErd
}
12 changes: 6 additions & 6 deletions cmd/termui/view/termuic/termuiRenders/widgetsRender.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type WidgetsRender struct {
presenter view.Presenter
}

//NewWidgetsRender method will create new WidgetsRender that display termui console
// NewWidgetsRender method will create new WidgetsRender that display termui console
func NewWidgetsRender(presenter view.Presenter, grid *DrawableContainer) (*WidgetsRender, error) {
if presenter == nil || presenter.IsInterfaceNil() {
return nil, view.ErrNilPresenterInterface
Expand Down Expand Up @@ -106,7 +106,7 @@ func (wr *WidgetsRender) setGrid() {
wr.container.SetBottom(gridBottom)
}

//RefreshData method is used to prepare data that are displayed on container
// RefreshData method is used to prepare data that are displayed on container
func (wr *WidgetsRender) RefreshData(numMillisecondsRefreshTime int) {
wr.prepareInstanceInfo()
wr.prepareChainInfo(numMillisecondsRefreshTime)
Expand All @@ -116,7 +116,7 @@ func (wr *WidgetsRender) RefreshData(numMillisecondsRefreshTime int) {
}

func (wr *WidgetsRender) prepareInstanceInfo() {
//8 rows and one column
// 8 rows and one column
numRows := 8
rows := make([][]string, numRows)

Expand All @@ -138,7 +138,7 @@ func (wr *WidgetsRender) prepareInstanceInfo() {
fmt.Sprintf("Node name: %s (Shard %s - %s)",
nodeName,
shardIdStr,
strings.Title(nodeTypeAndListDisplay),
nodeTypeAndListDisplay,
),
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func (wr *WidgetsRender) prepareInstanceInfo() {
}

func (wr *WidgetsRender) prepareChainInfo(numMillisecondsRefreshTime int) {
//10 rows and one column
// 10 rows and one column
numRows := 10
rows := make([][]string, numRows)

Expand Down Expand Up @@ -266,7 +266,7 @@ func computeRedundancyStr(redundancyLevel int64, redundancyIsMainActive string)
}

func (wr *WidgetsRender) prepareBlockInfo() {
//7 rows and one column
// 7 rows and one column
numRows := 8
rows := make([][]string, numRows)

Expand Down
3 changes: 0 additions & 3 deletions consensus/spos/bls/subroundBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,9 +998,6 @@ func TestSubroundBlock_CallFuncRemainingTimeWithStructShouldWork(t *testing.T) {

time.Sleep(200 * time.Millisecond)
assert.True(t, remainingTimeInCurrentRound() < 0)

roundStartTime = roundStartTime.Add(500 * time.Millisecond)
assert.True(t, remainingTimeInCurrentRound() < 0)
}

func TestSubroundBlock_CallFuncRemainingTimeWithStructShouldNotWork(t *testing.T) {
Expand Down

0 comments on commit f12e872

Please sign in to comment.