Skip to content

Commit

Permalink
Fix Current limits not reporting proper values
Browse files Browse the repository at this point in the history
ElectricalConnectionParameterDescription data also may contain power values per phase. To get the current values, the MeasurementDescription data needs to be evaluated and proper measurementIds passed over to filter the parameter data properly
  • Loading branch information
DerAndereAndi committed Jun 20, 2024
1 parent 4032f49 commit 159ba13
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 66 deletions.
2 changes: 1 addition & 1 deletion api/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type ElectricalConnectionCommonInterface interface {
float64, float64, float64, error)

// Get the min, max, default current limits for each phase
GetPhaseCurrentLimits() (
GetPhaseCurrentLimits(measDesc []model.MeasurementDescriptionDataType) (
resultMin []float64, resultMax []float64, resultDefault []float64, resultErr error)

// Adjust a value to be within the permitted value range
Expand Down
49 changes: 34 additions & 15 deletions features/internal/electricalconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,33 +176,52 @@ var PhaseNameMapping = []model.ElectricalConnectionPhaseNameType{
model.ElectricalConnectionPhaseNameTypeC}

// Get the min, max, default current limits for each phase
func (e *ElectricalConnectionCommon) GetPhaseCurrentLimits() (
func (e *ElectricalConnectionCommon) GetPhaseCurrentLimits(measurementDescs []model.MeasurementDescriptionDataType) (
resultMin []float64, resultMax []float64, resultDefault []float64, resultErr error) {
for _, phaseName := range PhaseNameMapping {
// electricalParameterDescription contains the measured phase for each measurementId
filter := model.ElectricalConnectionParameterDescriptionDataType{
AcMeasuredPhases: util.Ptr(phaseName),
}
elParamDesc, err := e.GetParameterDescriptionsForFilter(filter)
if err != nil || len(elParamDesc) != 1 || elParamDesc[0].ParameterId == nil {
if err != nil || len(elParamDesc) == 0 {
continue
}

filter1 := model.ElectricalConnectionPermittedValueSetDataType{
ParameterId: elParamDesc[0].ParameterId,
}
dataMin, dataMax, dataDefault, err := e.GetPermittedValueDataForFilter(filter1)
if err != nil {
continue
}
// check all params and assume there are no phase specific power limits
for _, paramEl := range elParamDesc {
if paramEl.ParameterId == nil || paramEl.MeasurementId == nil {
continue
}

// check if the measurementId is in measurementDescs
found := false
for _, mDesc := range measurementDescs {
if mDesc.MeasurementId != nil && *mDesc.MeasurementId == *paramEl.MeasurementId {
found = true
break
}
}
if !found {
continue
}

filter1 := model.ElectricalConnectionPermittedValueSetDataType{
ParameterId: paramEl.ParameterId,
}
dataMin, dataMax, dataDefault, err := e.GetPermittedValueDataForFilter(filter1)
if err != nil {
continue
}

// Min current data should be derived from min power data
// but as this value is only properly provided via VAS the
// currrent min values can not be trusted.
// Min current data should be derived from min power data
// but as this value is only properly provided via VAS the
// currrent min values can not be trusted.

resultMin = append(resultMin, dataMin)
resultMax = append(resultMax, dataMax)
resultDefault = append(resultDefault, dataDefault)
resultMin = append(resultMin, dataMin)
resultMax = append(resultMax, dataMax)
resultDefault = append(resultDefault, dataDefault)
}
}

if len(resultMin) == 0 {
Expand Down
62 changes: 50 additions & 12 deletions features/internal/electricalconnection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type ElectricalConnectionSuite struct {
localEntity spineapi.EntityLocalInterface
remoteEntity spineapi.EntityRemoteInterface

localFeature spineapi.FeatureLocalInterface
remoteFeature spineapi.FeatureRemoteInterface
localFeature, localMeasFeature spineapi.FeatureLocalInterface
remoteFeature, remoteMeasFeature spineapi.FeatureRemoteInterface

localSut,
remoteSut *internal.ElectricalConnectionCommon
Expand All @@ -47,18 +47,28 @@ func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) {
model.FunctionTypeElectricalConnectionCharacteristicListData,
},
},
{
featureType: model.FeatureTypeTypeMeasurement,
functions: []model.FunctionType{
model.FunctionTypeMeasurementDescriptionListData,
},
},
},
)

s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer)
assert.NotNil(s.T(), s.localFeature)
s.localSut = internal.NewLocalElectricalConnection(s.localFeature)
assert.NotNil(s.T(), s.localSut)
s.localMeasFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer)
assert.NotNil(s.T(), s.localMeasFeature)

s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer)
assert.NotNil(s.T(), s.remoteFeature)
s.remoteSut = internal.NewRemoteElectricalConnection(s.remoteFeature)
assert.NotNil(s.T(), s.remoteSut)
s.remoteMeasFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer)
assert.NotNil(s.T(), s.remoteMeasFeature)
}

func (s *ElectricalConnectionSuite) Test_CheckEventPayloadDataForFilter() {
Expand Down Expand Up @@ -612,34 +622,34 @@ func (s *ElectricalConnectionSuite) Test_GetCharacteristicForContextType() {
}

func (s *ElectricalConnectionSuite) Test_EVCurrentLimits() {
minData, maxData, defaultData, err := s.localSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err := s.localSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
assert.Nil(s.T(), defaultData)
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
assert.Nil(s.T(), defaultData)

minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
assert.Nil(s.T(), defaultData)
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
assert.Nil(s.T(), defaultData)

minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
assert.Nil(s.T(), defaultData)
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
Expand Down Expand Up @@ -673,18 +683,46 @@ func (s *ElectricalConnectionSuite) Test_EVCurrentLimits() {
fErr = s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, paramData, nil, nil)
assert.Nil(s.T(), fErr)

minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
assert.Nil(s.T(), defaultData)

minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits(nil)
assert.NotNil(s.T(), err)
assert.Nil(s.T(), minData)
assert.Nil(s.T(), maxData)
assert.Nil(s.T(), defaultData)

measData := &model.MeasurementDescriptionListDataType{
MeasurementDescriptionData: []model.MeasurementDescriptionDataType{
{
MeasurementId: util.Ptr(model.MeasurementIdType(0)),
MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
Unit: util.Ptr(model.UnitOfMeasurementTypeA),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent),
},
{
MeasurementId: util.Ptr(model.MeasurementIdType(1)),
MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
Unit: util.Ptr(model.UnitOfMeasurementTypeA),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent)},
{
MeasurementId: util.Ptr(model.MeasurementIdType(2)),
MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent),
CommodityType: util.Ptr(model.CommodityTypeTypeElectricity),
Unit: util.Ptr(model.UnitOfMeasurementTypeA),
ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent)},
},
}
fErr = s.localMeasFeature.UpdateData(model.FunctionTypeMeasurementDescriptionListData, measData, nil, nil)
assert.Nil(s.T(), fErr)
fErr = s.remoteMeasFeature.UpdateData(model.FunctionTypeMeasurementDescriptionListData, measData, nil, nil)
assert.Nil(s.T(), fErr)

type permittedStruct struct {
defaultExists bool
defaultValue, expectedDefaultValue float64
Expand Down Expand Up @@ -775,7 +813,7 @@ func (s *ElectricalConnectionSuite) Test_EVCurrentLimits() {
fErr = s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, permData, nil, nil)
assert.Nil(s.T(), fErr)

minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits(measData.MeasurementDescriptionData)
assert.Nil(s.T(), err)

assert.Equal(s.T(), len(tc.permitted), len(minData))
Expand All @@ -787,7 +825,7 @@ func (s *ElectricalConnectionSuite) Test_EVCurrentLimits() {
assert.Equal(s.T(), item.expectedDefaultValue, defaultData[index])
}

minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits()
minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits(measData.MeasurementDescriptionData)
assert.Nil(s.T(), err)

assert.Equal(s.T(), len(tc.permitted), len(minData))
Expand Down
37 changes: 19 additions & 18 deletions mocks/ElectricalConnectionCommonInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 19 additions & 18 deletions mocks/ElectricalConnectionServerInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 159ba13

Please sign in to comment.