// Package config define config struct of model runtime service package config import ( "modelRT/constant" ) // AnchorParamListConfig define anchor params list config struct type AnchorParamListConfig struct { AnchorName string FuncType string // 函数类型 UpperLimit float32 // 比较值上限 LowerLimit float32 // 比较值下限 } // 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 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 } // 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} } } return nil, []float32{} }