@@ -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 {
@@ -738,23 +741,21 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
738741 }
739742
740743 if totalBlockChance > 0 {
741- ret .Luck .Proposal .Percent = (float64 (totalBlocksScheduled )) / totalBlockChance * 100
744+ proposalLuck := (float64 (totalBlocksScheduled )) / totalBlockChance * 100
745+ ret .Luck .Proposal .Percent = & proposalLuck
742746
743747 // calculate the average time it takes for the set of validators to propose a single block on average
744748 ret .Luck .Proposal .AverageIntervalSeconds = uint64 (time .Duration ((luckHours / totalBlockChance ) * float64 (time .Hour )).Seconds ())
745749
746750 ret .Luck .Proposal .ExpectedTimestamp = uint64 (lastBlockTs .Unix ()) + ret .Luck .Proposal .AverageIntervalSeconds
747- } else {
748- ret .Luck .Proposal .Percent = 0
749751 }
750752
751- if totalSyncExpected == 0 {
752- ret .Luck .Sync .Percent = 0
753- } else {
753+ if totalSyncExpected > 0 {
754754 totalSyncSlotDuties := float64 (ret .SyncCommittee .StatusCount .Failed ) + float64 (ret .SyncCommittee .StatusCount .Success )
755755 slotDutiesPerSyncCommittee := float64 (utils .SlotsPerSyncCommittee ())
756756 syncCommittees := math .Ceil (totalSyncSlotDuties / slotDutiesPerSyncCommittee ) // gets the number of sync committees
757- ret .Luck .Sync .Percent = syncCommittees / totalSyncExpected * 100
757+ syncLuck := syncCommittees / totalSyncExpected * 100
758+ ret .Luck .Sync .Percent = & syncLuck
758759
759760 // calculate the average time it takes for the set of validators to be elected into a sync committee on average
760761 ret .Luck .Sync .AverageIntervalSeconds = uint64 (time .Duration ((luckHours / totalSyncExpected ) * float64 (time .Hour )).Seconds ())
@@ -813,24 +814,16 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
813814 return ret , nil
814815}
815816
816- func calcEfficiencyNulled (dividend , divisor decimal.Decimal ) * float64 {
817+ func calcEfficiency (dividend , divisor decimal.Decimal ) * float64 {
817818 if divisor .IsZero () {
818819 return nil
819820 }
820- efficiency := calcEfficiency (dividend , divisor )
821- return & efficiency
822- }
823-
824- func calcEfficiency (dividend , divisor decimal.Decimal ) float64 {
825- if divisor .IsZero () {
826- return 100
827- }
828821 eff := dividend .Div (divisor ).InexactFloat64 () * 100
829822 if eff > 100 {
830823 log .Error (nil , "efficiency is greater than 100%" , 1 , map [string ]interface {}{"efficiency" : eff })
831824 eff = 100
832825 }
833- return eff
826+ return & eff
834827}
835828
836829// for summary charts: series id is group id, no stack
@@ -953,7 +946,7 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
953946 }
954947
955948 if ! dashboardId .AggregateGroups && requestedGroupsMap [row .GroupId ] {
956- eff := calcEfficiencyNulled (row .EfficiencyDividend , row .EfficiencyDivisor )
949+ eff := calcEfficiency (row .EfficiencyDividend , row .EfficiencyDivisor )
957950 if eff == nil {
958951 continue
959952 }
@@ -995,7 +988,7 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
995988 totalLineGroupId = t .DefaultGroupId
996989 }
997990 for _ , row := range totalEfficiencyMap {
998- data [row.Timestamp ][totalLineGroupId ] = calcEfficiencyNulled (row .EfficiencyDividend , row .EfficiencyDivisor )
991+ data [row.Timestamp ][totalLineGroupId ] = calcEfficiency (row .EfficiencyDividend , row .EfficiencyDivisor )
999992 }
1000993 groupMap [totalLineGroupId ] = true
1001994 }
0 commit comments