57 lines
1.9 KiB
Go
57 lines
1.9 KiB
Go
// Package config define config struct of model runtime service
|
|
package config
|
|
|
|
import (
|
|
"modelRT/constants"
|
|
)
|
|
|
|
// AnchorParamListConfig define anchor params list config struct
|
|
type AnchorParamListConfig struct {
|
|
AnchorName string
|
|
FuncType string // 函数类型
|
|
UpperLimit float64 // 比较值上限
|
|
LowerLimit float64 // 比较值下限
|
|
}
|
|
|
|
// AnchorParamBaseConfig define anchor params base config struct
|
|
type AnchorParamBaseConfig struct {
|
|
ComponentUUID string // componentUUID
|
|
AnchorName string // 锚定参量名称
|
|
CompareValUpperLimit float64 // 比较值上限
|
|
CompareValLowerLimit float64 // 比较值下限
|
|
AnchorRealTimeData []float64 // 锚定参数实时值
|
|
}
|
|
|
|
// AnchorParamConfig define anchor params config struct
|
|
type AnchorParamConfig struct {
|
|
AnchorParamBaseConfig
|
|
CalculateFunc func(archorValue float64, args ...float64) float64 // 计算函数
|
|
CalculateParams []float64 // 计算参数
|
|
}
|
|
|
|
var baseVoltageFunc = func(archorValue float64, args ...float64) float64 {
|
|
voltage := archorValue
|
|
resistance := args[1]
|
|
return voltage / resistance
|
|
}
|
|
|
|
var baseCurrentFunc = func(archorValue float64, args ...float64) float64 {
|
|
current := archorValue
|
|
resistance := args[1]
|
|
return current * resistance
|
|
}
|
|
|
|
// 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 float64, args ...float64) float64, []float64) {
|
|
if componentType == constants.DemoType {
|
|
if anchorName == "voltage" {
|
|
resistance := componentData["resistance"].(float64)
|
|
return baseVoltageFunc, []float64{resistance}
|
|
} else if anchorName == "current" {
|
|
resistance := componentData["resistance"].(float64)
|
|
return baseCurrentFunc, []float64{resistance}
|
|
}
|
|
}
|
|
return nil, []float64{}
|
|
}
|