Skip to content

Commit

Permalink
Merge pull request #1981 from afumagalli98/1979
Browse files Browse the repository at this point in the history
Improved compliance stats API
  • Loading branch information
afumagalli98 authored Nov 11, 2024
2 parents 31b975e + d675ec0 commit 37dd5c4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions api-service/service/frontend_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ func (as *APIService) GetComplianceStats() (*dto.ComplianceStats, error) {
mongodbStats.Count +
mariadbStats.Count

avg := (oracleStats.CompliancePercentageVal + mysqlStats.CompliancePercentageVal + sqlServerStats.CompliancePercentageVal +
postgresqlStats.CompliancePercentageVal + mongodbStats.CompliancePercentageVal + mariadbStats.CompliancePercentageVal) / 6
weightedSum := (oracleStats.CompliancePercentageVal * float64(oracleStats.HostCount)) +
(mysqlStats.CompliancePercentageVal * float64(mysqlStats.HostCount)) +
(sqlServerStats.CompliancePercentageVal * float64(sqlServerStats.HostCount)) +
(postgresqlStats.CompliancePercentageVal * float64(postgresqlStats.HostCount)) +
(mongodbStats.CompliancePercentageVal * float64(mongodbStats.HostCount)) +
(mariadbStats.CompliancePercentageVal * float64(mariadbStats.HostCount))

weightedAvg := weightedSum / float64(hostsCount)

totStats := dto.Stats{
Count: instancesCount,
HostCount: hostsCount,
CompliancePercentageVal: avg,
CompliancePercentageStr: fmt.Sprintf("%.2f%%", avg),
CompliancePercentageVal: weightedAvg,
CompliancePercentageStr: fmt.Sprintf("%.2f%%", weightedAvg),
}

res := dto.ComplianceStats{
Expand Down Expand Up @@ -147,7 +153,7 @@ func (as *APIService) oracleStats() (*dto.Stats, error) {
compliancePercentage = (totCompliance * 100) / float64(len(compliances))
}

if compliancePercentage == 0 {
if compliancePercentage == 0 || hostCount == 0 {
compliancePercentage = 100
}

Expand Down Expand Up @@ -187,7 +193,7 @@ func (as *APIService) mysqlStats() (*dto.Stats, error) {
compliancePercentage = (totCompliance * 100) / float64(len(compliances))
}

if compliancePercentage == 0 {
if compliancePercentage == 0 || hostCount == 0 {
compliancePercentage = 100
}

Expand Down Expand Up @@ -227,7 +233,7 @@ func (as *APIService) sqlServerStats() (*dto.Stats, error) {
compliancePercentage = (totCompliance * 100) / float64(len(compliances))
}

if compliancePercentage == 0 {
if compliancePercentage == 0 || hostCount == 0 {
compliancePercentage = 100
}

Expand Down

0 comments on commit 37dd5c4

Please sign in to comment.