@@ -389,7 +389,10 @@ func (d *DataAccessService) GetValidatorDashboardSummary(ctx context.Context, da
389389 }
390390 case enums .VDBSummaryColumns .Efficiency :
391391 sortParam = func (resultEntry t.VDBSummaryTableRow ) float64 {
392- return resultEntry .Efficiency
392+ if resultEntry .Efficiency == nil {
393+ return - 1
394+ }
395+ return * resultEntry .Efficiency
393396 }
394397 case enums .VDBSummaryColumns .Attestations :
395398 sortParam = func (resultEntry t.VDBSummaryTableRow ) float64 {
@@ -741,23 +744,21 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
741744 }
742745
743746 if totalBlockChance > 0 {
744- ret .Luck .Proposal .Percent = (float64 (totalBlocksScheduled )) / totalBlockChance * 100
747+ proposalLuck := (float64 (totalBlocksScheduled )) / totalBlockChance * 100
748+ ret .Luck .Proposal .Percent = & proposalLuck
745749
746750 // calculate the average time it takes for the set of validators to propose a single block on average
747751 ret .Luck .Proposal .AverageIntervalSeconds = uint64 (time .Duration ((luckHours / totalBlockChance ) * float64 (time .Hour )).Seconds ())
748752
749753 ret .Luck .Proposal .ExpectedTimestamp = uint64 (lastBlockTs .Unix ()) + ret .Luck .Proposal .AverageIntervalSeconds
750- } else {
751- ret .Luck .Proposal .Percent = 0
752754 }
753755
754- if totalSyncExpected == 0 {
755- ret .Luck .Sync .Percent = 0
756- } else {
756+ if totalSyncExpected > 0 {
757757 totalSyncSlotDuties := float64 (ret .SyncCommittee .StatusCount .Failed ) + float64 (ret .SyncCommittee .StatusCount .Success )
758758 slotDutiesPerSyncCommittee := float64 (utils .SlotsPerSyncCommittee ())
759759 syncCommittees := math .Ceil (totalSyncSlotDuties / slotDutiesPerSyncCommittee ) // gets the number of sync committees
760- ret .Luck .Sync .Percent = syncCommittees / totalSyncExpected * 100
760+ syncLuck := syncCommittees / totalSyncExpected * 100
761+ ret .Luck .Sync .Percent = & syncLuck
761762
762763 // calculate the average time it takes for the set of validators to be elected into a sync committee on average
763764 ret .Luck .Sync .AverageIntervalSeconds = uint64 (time .Duration ((luckHours / totalSyncExpected ) * float64 (time .Hour )).Seconds ())
@@ -816,24 +817,16 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
816817 return ret , nil
817818}
818819
819- func calcEfficiencyNulled (dividend , divisor decimal.Decimal ) * float64 {
820+ func calcEfficiency (dividend , divisor decimal.Decimal ) * float64 {
820821 if divisor .IsZero () {
821822 return nil
822823 }
823- efficiency := calcEfficiency (dividend , divisor )
824- return & efficiency
825- }
826-
827- func calcEfficiency (dividend , divisor decimal.Decimal ) float64 {
828- if divisor .IsZero () {
829- return 100
830- }
831824 eff := dividend .Div (divisor ).InexactFloat64 () * 100
832825 if eff > 100 {
833826 log .Error (nil , "efficiency is greater than 100%" , 1 , map [string ]interface {}{"efficiency" : eff })
834827 eff = 100
835828 }
836- return eff
829+ return & eff
837830}
838831
839832// for summary charts: series id is group id, no stack
@@ -956,7 +949,7 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
956949 }
957950
958951 if ! dashboardId .AggregateGroups && requestedGroupsMap [row .GroupId ] {
959- eff := calcEfficiencyNulled (row .EfficiencyDividend , row .EfficiencyDivisor )
952+ eff := calcEfficiency (row .EfficiencyDividend , row .EfficiencyDivisor )
960953 if eff == nil {
961954 continue
962955 }
@@ -998,7 +991,7 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
998991 totalLineGroupId = t .DefaultGroupId
999992 }
1000993 for _ , row := range totalEfficiencyMap {
1001- data [row.Timestamp ][totalLineGroupId ] = calcEfficiencyNulled (row .EfficiencyDividend , row .EfficiencyDivisor )
994+ data [row.Timestamp ][totalLineGroupId ] = calcEfficiency (row .EfficiencyDividend , row .EfficiencyDivisor )
1002995 }
1003996 groupMap [totalLineGroupId ] = true
1004997 }
0 commit comments