logs-analyzer/signoz/pkg/query-service/converter/percent_converter.go

31 lines
520 B
Go
Raw Normal View History

2024-09-02 22:47:30 +03:00
package converter
// percentConverter is a converter for percent unit
type percentConverter struct{}
func NewPercentConverter() Converter {
return &percentConverter{}
}
func (*percentConverter) Name() string {
return "percent"
}
func FromPercentUnit(u Unit) float64 {
switch u {
case "percent":
return 1
case "percentunit":
return 100
default:
return 1
}
}
func (c *percentConverter) Convert(v Value, to Unit) Value {
return Value{
F: v.F * FromPercentUnit(v.U) / FromPercentUnit(to),
U: to,
}
}