func (r *ReplicaCalculate) GetPlainMetricReplicaCount(metrics metricsclient.PodMetricsInfo,
	currentReplicas int32,
	targetUtilization int64,
	readyPodCount int64,
	missingPods,
	ignoredPods sets.String) int32 {
	usageRatio, _ := metricsclient.GetMetricUtilizationRatio(metrics, targetUtilization)
	rebalanceIgnored := len(ignoredPods) > 0 && usageRatio > 1.0
	if !rebalanceIgnored && len(missingPods) == 0 {
		if math.Abs(1.0-usageRatio) <= r.Tolerance {
			return currentReplicas
		}
		return int32(math.Ceil(usageRatio * float64(readyPodCount)))
	}
	if len(missingPods) > 0 {
		if usageRatio < 1.0 {
			for podName := range missingPods {
				metrics[podName] = metricsclient.PodMetric{Value: targetUtilization}
			}
		} else {
			for podName := range missingPods {
				metrics[podName] = metricsclient.PodMetric{Value: 0}
			}
		}
	}
	if rebalanceIgnored {
		for podName := range ignoredPods {
			metrics[podName] = metricsclient.PodMetric{Value: 0}
		}
	}
	newUsageRatio, _ := metricsclient.GetMetricUtilizationRatio(metrics, targetUtilization)
	if math.Abs(1.0-newUsageRatio) <= r.Tolerance || (usageRatio < 1.0 && newUsageRatio > 1.0) || (usageRatio > 1.0 && newUsageRatio < 1.0) {
		return currentReplicas
	}
	return int32(math.Ceil(newUsageRatio * float64(len(metrics))))
}
GetPlainMetricReplicaCount calculates the replica count based on the metrics of each pod and a target utilization, providing
a different replica count if the calculated usage ratio is beyond the tolerance
package calculate
import (
	"math"
	"k8s.io/apimachinery/pkg/util/sets"
	metricsclient "k8s.io/kubernetes/pkg/controller/podautoscaler/metrics"
)
type Calculater interface {
	GetUsageRatioReplicaCount(currentReplicas int32, usageRatio float64, readyPodCount int64) int32
	GetPlainMetricReplicaCount(metrics metricsclient.PodMetricsInfo,
		currentReplicas int32,
		targetUtilization int64,
		readyPodCount int64,
		missingPods,
		ignoredPods sets.String) int32
}
type ReplicaCalculate struct {
	Tolerance float64
}
func (r *ReplicaCalculate) GetUsageRatioReplicaCount(currentReplicas int32, usageRatio float64, readyPodCount int64) int32 {
	var replicaCount int32
	if currentReplicas != 0 {
		if math.Abs(1.0-usageRatio) <= r.Tolerance {
			return currentReplicas
		}
		replicaCount = int32(math.Ceil(usageRatio * float64(readyPodCount)))
	} else {
		replicaCount = int32(math.Ceil(usageRatio))
	}
	return replicaCount
}