util

package
v0.0.0-...-2f3587d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InterpolationTypeLinear = "linear"
)

Variables

This section is empty.

Functions

func Avg

func Avg(values []float64) float64

Avg calculates the average of all values in the given array

func CalculateInterpolatedCurveValue

func CalculateInterpolatedCurveValue(steps map[int]float64, interpolationType string, input float64) float64

CalculateInterpolatedCurveValue creates an interpolated function from the given map of x-values -> y-values as specified by the interpolationType and returns the y-value for the given input

func CheckFilePermissionsForExecution

func CheckFilePermissionsForExecution(filePath string) (bool, error)

CheckFilePermissionsForExecution checks whether the given filePath owner, group and permissions are safe to use this file for execution by fan2go.

func Coerce

func Coerce(value float64, min float64, max float64) float64

Coerce returns a value that is at least min and at most max, otherwise value

func ContainsString

func ContainsString(s []string, e string) bool

func CreateRollingWindow

func CreateRollingWindow(size int) *rolling.PointPolicy

func ExtractKeysWithDistinctValues

func ExtractKeysWithDistinctValues(input map[int]int) []int

func FillWindow

func FillWindow(window *rolling.PointPolicy, size int, value float64)

FillWindow completely fills the given window with the given value

func FindClosest

func FindClosest(target int, arr []int) int

FindClosest finds the closest value to target in options.

func FindFilesMatching

func FindFilesMatching(path string, expr *regexp.Regexp) []string

FindFilesMatching finds all files in a given directory, matching the given regex

func GetWindowAvg

func GetWindowAvg(window *rolling.PointPolicy) float64

GetWindowAvg returns the average of all values in the window

func GetWindowMax

func GetWindowMax(window *rolling.PointPolicy) float64

GetWindowMax returns the max value in the window

func HexString

func HexString(hex string) string

HexString parses the given string as hex and string formats it, removing any leading zeros in the process

func InterpolateLinearly

func InterpolateLinearly(data *map[int]float64, start int, stop int) map[int]float64

InterpolateLinearly takes the given mapping and adds interpolated values in [start;stop].

func Max

func Max(s []float64) float64

func Min

func Min(s []float64) float64

func Ratio

func Ratio(target float64, rangeMin float64, rangeMax float64) float64

Ratio calculates the ration that target has in comparison to rangeMin and rangeMax Make sure that: rangeMin <= target <= rangeMax rangeMax - rangeMin != 0

func ReadIntFromFile

func ReadIntFromFile(path string) (value int, err error)

func SafeCmdExecution

func SafeCmdExecution(executable string, args []string, timeout time.Duration) (string, error)

func SortedKeys

func SortedKeys[T constraints.Ordered, K any](input map[T]K) []T

func UpdateSimpleMovingAvg

func UpdateSimpleMovingAvg(oldAvg float64, n int, newValue float64) float64

UpdateSimpleMovingAvg calculates the new moving average, based on an existing average and buffer size

func Values

func Values[A constraints.Ordered, B any](input map[A]B) []B

func WriteIntToFile

func WriteIntToFile(value int, path string) error

WriteIntToFile write a single integer to a file.go path

Types

type PidLoop

type PidLoop struct {
	// contains filtered or unexported fields
}

func NewPidLoop

func NewPidLoop(p float64, i float64, d float64) *PidLoop

func (*PidLoop) Loop

func (p *PidLoop) Loop(target float64, measured float64) float64

Loop advances the pid loop

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL