2024-12-18 16:25:49 +08:00
|
|
|
// Package config define config struct of model runtime service
|
|
|
|
|
package config
|
|
|
|
|
|
2024-12-20 16:06:42 +08:00
|
|
|
import (
|
|
|
|
|
"modelRT/constant"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// AnchorParamListConfig define anchor params list config struct
|
|
|
|
|
type AnchorParamListConfig struct {
|
|
|
|
|
AnchorName string
|
|
|
|
|
FuncType string // 函数类型
|
|
|
|
|
UpperLimit float32 // 比较值上限
|
|
|
|
|
LowerLimit float32 // 比较值下限
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-18 16:25:49 +08:00
|
|
|
// AnchorParamBaseConfig define anchor params base config struct
|
|
|
|
|
type AnchorParamBaseConfig struct {
|
|
|
|
|
UUID string
|
|
|
|
|
AnchorName string // 锚定参量名称
|
|
|
|
|
CompareValUpperLimit float32 // 比较值上限
|
|
|
|
|
CompareValLowerLimit float32 // 比较值下限
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AnchorParamConfig define anchor params config struct
|
|
|
|
|
type AnchorParamConfig struct {
|
|
|
|
|
AnchorParamBaseConfig
|
2024-12-20 16:06:42 +08:00
|
|
|
CalculateFunc func(archorValue float32, args ...float32) float32 // 计算函数
|
|
|
|
|
CalculateParams []float32 // 计算参数
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var baseVoltageFunc = func(archorValue float32, args ...float32) float32 {
|
|
|
|
|
voltage := archorValue
|
|
|
|
|
resistance := args[1]
|
|
|
|
|
return voltage / resistance
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var baseCurrentFunc = func(archorValue float32, args ...float32) float32 {
|
|
|
|
|
current := archorValue
|
|
|
|
|
resistance := args[1]
|
|
|
|
|
return current * resistance
|
2024-12-18 16:25:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-12-20 16:06:42 +08:00
|
|
|
// SelectAnchorCalculateFuncAndParams define select anchor func and anchor calculate value by component type 、 anchor name and component data
|
|
|
|
|
func SelectAnchorCalculateFuncAndParams(componentType int, anchorName string, componentData map[string]interface{}) (func(archorValue float32, args ...float32) float32, []float32) {
|
|
|
|
|
if componentType == constant.DemoType {
|
|
|
|
|
if anchorName == "voltage" {
|
|
|
|
|
resistance := componentData["resistance"].(float32)
|
|
|
|
|
return baseVoltageFunc, []float32{resistance}
|
|
|
|
|
} else if anchorName == "current" {
|
|
|
|
|
resistance := componentData["resistance"].(float32)
|
|
|
|
|
return baseCurrentFunc, []float32{resistance}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-18 16:25:49 +08:00
|
|
|
return nil, []float32{}
|
|
|
|
|
}
|