@@ -813,17 +813,30 @@ func (d *DataAccessService) GetValidatorDashboardGroupSummary(ctx context.Contex
813813 return ret , nil
814814}
815815
816+ func calcEfficiencyNulled (dividend , divisor decimal.Decimal ) * float64 {
817+ if divisor .IsZero () {
818+ return nil
819+ }
820+ efficiency := calcEfficiency (dividend , divisor )
821+ return & efficiency
822+ }
823+
816824func calcEfficiency (dividend , divisor decimal.Decimal ) float64 {
817825 if divisor .IsZero () {
818- return 0
826+ return 100
827+ }
828+ eff := dividend .Div (divisor ).InexactFloat64 () * 100
829+ if eff > 100 {
830+ log .Error (nil , "efficiency is greater than 100%" , 1 , map [string ]interface {}{"efficiency" : eff })
831+ eff = 100
819832 }
820- return dividend . Div ( divisor ). InexactFloat64 () * 100
833+ return eff
821834}
822835
823836// for summary charts: series id is group id, no stack
824837
825- func (d * DataAccessService ) GetValidatorDashboardSummaryChart (ctx context.Context , dashboardId t.VDBId , groupIds []int64 , efficiency enums.VDBSummaryChartEfficiencyType , aggregation enums.ChartAggregation , afterTs uint64 , beforeTs uint64 ) (* t.ChartData [int , float64 ], error ) {
826- ret := & t.ChartData [int , float64 ]{}
838+ func (d * DataAccessService ) GetValidatorDashboardSummaryChart (ctx context.Context , dashboardId t.VDBId , groupIds []int64 , efficiency enums.VDBSummaryChartEfficiencyType , aggregation enums.ChartAggregation , afterTs uint64 , beforeTs uint64 ) (* t.ChartData [int , * float64 ], error ) {
839+ ret := & t.ChartData [int , * float64 ]{}
827840
828841 if len (groupIds ) == 0 { // short circuit if no groups are selected
829842 return ret , nil
@@ -929,26 +942,22 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
929942
930943 // convert the returned data to the expected return type (not pretty)
931944 tsMap := make (map [time.Time ]bool )
932- data := make (map [time.Time ]map [int64 ]float64 )
945+ data := make (map [time.Time ]map [int64 ]* float64 )
933946 groupMap := make (map [int64 ]bool )
934947
935948 totalEfficiencyMap := make (map [time.Time ]* t.VDBValidatorSummaryChartRow )
936949 for _ , row := range queryResults {
937950 tsMap [row .Timestamp ] = true
938-
939951 if data [row .Timestamp ] == nil {
940- data [row .Timestamp ] = make (map [int64 ]float64 )
952+ data [row .Timestamp ] = make (map [int64 ]* float64 )
941953 }
942954
943955 if ! dashboardId .AggregateGroups && requestedGroupsMap [row .GroupId ] {
944- data [row. Timestamp ][row. GroupId ] = calcEfficiency (row .EfficiencyDividend , row .EfficiencyDivisor )
945- if data [row. Timestamp ][row. GroupId ] == 0 {
956+ eff := calcEfficiencyNulled (row .EfficiencyDividend , row .EfficiencyDivisor )
957+ if eff == nil {
946958 continue
947959 }
948- if data [row.Timestamp ][row.GroupId ] > 100 {
949- log .Error (nil , "efficiency is greater than 100%" , 0 , map [string ]interface {}{"efficiency" : efficiency })
950- data [row.Timestamp ][row.GroupId ] = 100
951- }
960+ data [row.Timestamp ][row.GroupId ] = eff
952961 groupMap [row .GroupId ] = true
953962 }
954963
@@ -975,7 +984,7 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
975984 }
976985
977986 for ts := range tsMap {
978- data [ts ][int64 (t .NetworkAverage )] = averageNetworkEfficiency
987+ data [ts ][int64 (t .NetworkAverage )] = & averageNetworkEfficiency
979988 }
980989 groupMap [t .NetworkAverage ] = true
981990 }
@@ -986,14 +995,7 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
986995 totalLineGroupId = t .DefaultGroupId
987996 }
988997 for _ , row := range totalEfficiencyMap {
989- data [row.Timestamp ][totalLineGroupId ] = calcEfficiency (row .EfficiencyDividend , row .EfficiencyDivisor )
990- if data [row.Timestamp ][totalLineGroupId ] == 0 {
991- continue
992- }
993- if data [row.Timestamp ][totalLineGroupId ] > 100 {
994- log .Error (nil , "efficiency is greater than 100%" , 0 , map [string ]interface {}{"efficiency" : efficiency })
995- data [row.Timestamp ][totalLineGroupId ] = 100
996- }
998+ data [row.Timestamp ][totalLineGroupId ] = calcEfficiencyNulled (row .EfficiencyDividend , row .EfficiencyDivisor )
997999 }
9981000 groupMap [totalLineGroupId ] = true
9991001 }
@@ -1013,13 +1015,13 @@ func (d *DataAccessService) GetValidatorDashboardSummaryChart(ctx context.Contex
10131015 for _ , ts := range tsArray {
10141016 ret .Categories = append (ret .Categories , uint64 (ts .Unix ()))
10151017 }
1016- ret .Series = make ([]t.ChartSeries [int , float64 ], 0 , len (groupsArray ))
1018+ ret .Series = make ([]t.ChartSeries [int , * float64 ], 0 , len (groupsArray ))
10171019
1018- seriesMap := make (map [int64 ]* t.ChartSeries [int , float64 ])
1020+ seriesMap := make (map [int64 ]* t.ChartSeries [int , * float64 ])
10191021 for _ , group := range groupsArray {
1020- series := t.ChartSeries [int , float64 ]{
1022+ series := t.ChartSeries [int , * float64 ]{
10211023 Id : int (group ),
1022- Data : make ([]float64 , 0 , len (tsMap )),
1024+ Data : make ([]* float64 , 0 , len (tsMap )),
10231025 }
10241026 seriesMap [group ] = & series
10251027 }
0 commit comments