From b3f9e2c8c7988e659a2fd2c61b68ca985a9e3195 Mon Sep 17 00:00:00 2001 From: "ahmed.magdy" Date: Tue, 26 Nov 2024 12:31:08 +0200 Subject: [PATCH 1/5] have CurrentLimits method in opev and oscev filter for LoadControlLimitDescriptionData instead of MeasurementDescriptionData --- usecases/cem/opev/public.go | 37 +++++++++++++++++++++++++++++------- usecases/cem/oscev/public.go | 37 +++++++++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/usecases/cem/opev/public.go b/usecases/cem/opev/public.go index 15764008..f7b3d10c 100644 --- a/usecases/cem/opev/public.go +++ b/usecases/cem/opev/public.go @@ -26,23 +26,46 @@ func (e *OPEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } + lc, err := client.NewLoadControl(e.LocalEntity, entity) + if err != nil { + return nil, nil, nil, err + } + meas, err := client.NewMeasurement(e.LocalEntity, entity) if err != nil { return nil, nil, nil, err } - filter := model.MeasurementDescriptionDataType{ - MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + filter := model.LoadControlLimitDescriptionDataType { + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), } - measDesc, err := meas.GetDescriptionsForFilter(filter) + + limitDescs, err := lc.GetLimitDescriptionsForFilter(filter) if err != nil { return nil, nil, nil, err } + if len(limitDescs) != 3 { + return nil, nil, nil, api.ErrDataNotAvailable + } - return ec.GetPhaseCurrentLimits(measDesc) + measDescs := make([]model.MeasurementDescriptionDataType, 0) + for _, ld := range limitDescs { + filter := model.MeasurementDescriptionDataType{ + MeasurementId: ld.MeasurementId, + } + mds, err := meas.GetDescriptionsForFilter(filter) + if err != nil { + return nil, nil, nil, err + } + if len(mds) != 1 { + return nil, nil, nil, api.ErrDataNotAvailable + } + measDescs = append(measDescs, mds[0]) + } + return ec.GetPhaseCurrentLimits(measDescs) } // return the current loadcontrol obligation limits diff --git a/usecases/cem/oscev/public.go b/usecases/cem/oscev/public.go index 6e030e37..655b3bb2 100644 --- a/usecases/cem/oscev/public.go +++ b/usecases/cem/oscev/public.go @@ -26,23 +26,46 @@ func (e *OSCEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } + lc, err := client.NewLoadControl(e.LocalEntity, entity) + if err != nil { + return nil, nil, nil, err + } + meas, err := client.NewMeasurement(e.LocalEntity, entity) if err != nil { return nil, nil, nil, err } - filter := model.MeasurementDescriptionDataType{ - MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + filter := model.LoadControlLimitDescriptionDataType { + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), } - measDesc, err := meas.GetDescriptionsForFilter(filter) + + limitDescs, err := lc.GetLimitDescriptionsForFilter(filter) if err != nil { return nil, nil, nil, err } + if len(limitDescs) != 3 { + return nil, nil, nil, api.ErrDataNotAvailable + } - return ec.GetPhaseCurrentLimits(measDesc) + measDescs := make([]model.MeasurementDescriptionDataType, 0) + for _, ld := range limitDescs { + filter := model.MeasurementDescriptionDataType{ + MeasurementId: ld.MeasurementId, + } + mds, err := meas.GetDescriptionsForFilter(filter) + if err != nil { + return nil, nil, nil, err + } + if len(mds) != 1 { + return nil, nil, nil, api.ErrDataNotAvailable + } + measDescs = append(measDescs, mds[0]) + } + return ec.GetPhaseCurrentLimits(measDescs) } // return the current loadcontrol recommendation limits From c083afa9a31712c48f12b9be6e62c655d780e786 Mon Sep 17 00:00:00 2001 From: "ahmed.magdy" Date: Tue, 26 Nov 2024 13:50:12 +0200 Subject: [PATCH 2/5] adjusting the unit test to make up for lost coverage --- usecases/cem/opev/public_test.go | 75 ++++++++++++++++++++++++++++++- usecases/cem/oscev/public_test.go | 75 ++++++++++++++++++++++++++++++- 2 files changed, 148 insertions(+), 2 deletions(-) diff --git a/usecases/cem/opev/public_test.go b/usecases/cem/opev/public_test.go index 644e0f6a..d7c949a7 100644 --- a/usecases/cem/opev/public_test.go +++ b/usecases/cem/opev/public_test.go @@ -16,9 +16,58 @@ func (s *CemOPEVSuite) Test_Public() { _, _, _, err = s.sut.CurrentLimits(s.evEntity) assert.NotNil(s.T(), err) + lc := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + assert.NotNil(s.T(), lc) + meas := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer) assert.NotNil(s.T(), meas) + lData := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + }, + }, + } + + _,errT := lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(2)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), + MeasurementId: util.Ptr(model.MeasurementIdType(2)), + }, + }, + } + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, &model.FilterType{}, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + mData := &model.MeasurementDescriptionListDataType{ MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ { @@ -30,7 +79,31 @@ func (s *CemOPEVSuite) Test_Public() { }, }, } - _, errT := meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) + _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + mData = &model.MeasurementDescriptionListDataType{ + MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ + { + 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), + }, + }, + } + _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, &model.FilterType{}, nil) assert.Nil(s.T(), errT) _, _, _, err = s.sut.CurrentLimits(s.evEntity) diff --git a/usecases/cem/oscev/public_test.go b/usecases/cem/oscev/public_test.go index 1f6d8ed5..4b637de3 100644 --- a/usecases/cem/oscev/public_test.go +++ b/usecases/cem/oscev/public_test.go @@ -16,9 +16,58 @@ func (s *CemOSCEVSuite) Test_Public() { _, _, _, err = s.sut.CurrentLimits(s.evEntity) assert.NotNil(s.T(), err) + lc := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + assert.NotNil(s.T(), lc) + meas := s.evEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer) assert.NotNil(s.T(), meas) + lData := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + }, + }, + } + + _,errT := lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(2)), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), + MeasurementId: util.Ptr(model.MeasurementIdType(2)), + }, + }, + } + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, &model.FilterType{}, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + mData := &model.MeasurementDescriptionListDataType{ MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ { @@ -30,7 +79,31 @@ func (s *CemOSCEVSuite) Test_Public() { }, }, } - _, errT := meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) + _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + mData = &model.MeasurementDescriptionListDataType{ + MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ + { + 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), + }, + }, + } + _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, &model.FilterType{}, nil) assert.Nil(s.T(), errT) _, _, _, err = s.sut.CurrentLimits(s.evEntity) From 0b7bf593c9c25362574f3ddbfc88c329f3b8dcf8 Mon Sep 17 00:00:00 2001 From: "ahmed.magdy" Date: Tue, 26 Nov 2024 23:42:57 +0200 Subject: [PATCH 3/5] relevant limit descriptions found need only be more than 0; nil check for measurement ID in relevant LoadControlLimitDescriptions --- usecases/cem/opev/public.go | 8 ++++-- usecases/cem/opev/public_test.go | 48 +++++++++++-------------------- usecases/cem/oscev/public.go | 8 ++++-- usecases/cem/oscev/public_test.go | 48 +++++++++++-------------------- 4 files changed, 44 insertions(+), 68 deletions(-) diff --git a/usecases/cem/opev/public.go b/usecases/cem/opev/public.go index f7b3d10c..ff93e151 100644 --- a/usecases/cem/opev/public.go +++ b/usecases/cem/opev/public.go @@ -47,14 +47,18 @@ func (e *OPEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, if err != nil { return nil, nil, nil, err } - if len(limitDescs) != 3 { + if len(limitDescs) == 0 { return nil, nil, nil, api.ErrDataNotAvailable } measDescs := make([]model.MeasurementDescriptionDataType, 0) for _, ld := range limitDescs { + measId := ld.MeasurementId + if measId == nil { + return nil, nil, nil, api.ErrDataNotAvailable + } filter := model.MeasurementDescriptionDataType{ - MeasurementId: ld.MeasurementId, + MeasurementId: measId, } mds, err := meas.GetDescriptionsForFilter(filter) if err != nil { diff --git a/usecases/cem/opev/public_test.go b/usecases/cem/opev/public_test.go index d7c949a7..b4e3965a 100644 --- a/usecases/cem/opev/public_test.go +++ b/usecases/cem/opev/public_test.go @@ -24,14 +24,6 @@ func (s *CemOPEVSuite) Test_Public() { lData := &model.LoadControlLimitDescriptionListDataType{ LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ - { - LimitId: util.Ptr(model.LoadControlLimitIdType(0)), - LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), - LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - }, }, } @@ -44,20 +36,26 @@ func (s *CemOPEVSuite) Test_Public() { lData = &model.LoadControlLimitDescriptionListDataType{ LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ { - LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), Unit: util.Ptr(model.UnitOfMeasurementTypeA), ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), - MeasurementId: util.Ptr(model.MeasurementIdType(1)), }, + }, + } + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ { - LimitId: util.Ptr(model.LoadControlLimitIdType(2)), - LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), - LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeOverloadProtection), - MeasurementId: util.Ptr(model.MeasurementIdType(2)), + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), }, }, } @@ -70,13 +68,6 @@ func (s *CemOPEVSuite) Test_Public() { mData := &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), - }, }, } _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) @@ -88,14 +79,7 @@ func (s *CemOPEVSuite) Test_Public() { mData = &model.MeasurementDescriptionListDataType{ MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ { - 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)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), Unit: util.Ptr(model.UnitOfMeasurementTypeA), @@ -103,7 +87,7 @@ func (s *CemOPEVSuite) Test_Public() { }, }, } - _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, &model.FilterType{}, nil) + _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) assert.Nil(s.T(), errT) _, _, _, err = s.sut.CurrentLimits(s.evEntity) diff --git a/usecases/cem/oscev/public.go b/usecases/cem/oscev/public.go index 655b3bb2..fae73c82 100644 --- a/usecases/cem/oscev/public.go +++ b/usecases/cem/oscev/public.go @@ -47,14 +47,18 @@ func (e *OSCEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, if err != nil { return nil, nil, nil, err } - if len(limitDescs) != 3 { + if len(limitDescs) == 0 { return nil, nil, nil, api.ErrDataNotAvailable } measDescs := make([]model.MeasurementDescriptionDataType, 0) for _, ld := range limitDescs { + measId := ld.MeasurementId + if measId == nil { + return nil, nil, nil, api.ErrDataNotAvailable + } filter := model.MeasurementDescriptionDataType{ - MeasurementId: ld.MeasurementId, + MeasurementId: measId, } mds, err := meas.GetDescriptionsForFilter(filter) if err != nil { diff --git a/usecases/cem/oscev/public_test.go b/usecases/cem/oscev/public_test.go index 4b637de3..8a390dcc 100644 --- a/usecases/cem/oscev/public_test.go +++ b/usecases/cem/oscev/public_test.go @@ -24,14 +24,6 @@ func (s *CemOSCEVSuite) Test_Public() { lData := &model.LoadControlLimitDescriptionListDataType{ LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ - { - LimitId: util.Ptr(model.LoadControlLimitIdType(0)), - LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), - LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - }, }, } @@ -44,20 +36,26 @@ func (s *CemOSCEVSuite) Test_Public() { lData = &model.LoadControlLimitDescriptionListDataType{ LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ { - LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), Unit: util.Ptr(model.UnitOfMeasurementTypeA), ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), - MeasurementId: util.Ptr(model.MeasurementIdType(1)), }, + }, + } + + _,errT = lc.UpdateData(true, model.FunctionTypeLoadControlLimitDescriptionListData, lData, nil, nil) + assert.Nil(s.T(), errT) + + _, _, _, err = s.sut.CurrentLimits(s.evEntity) + assert.NotNil(s.T(), err) + + lData = &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ { - LimitId: util.Ptr(model.LoadControlLimitIdType(2)), - LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), - LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), - MeasurementId: util.Ptr(model.MeasurementIdType(2)), + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), }, }, } @@ -70,13 +68,6 @@ func (s *CemOSCEVSuite) Test_Public() { mData := &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), - }, }, } _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) @@ -88,14 +79,7 @@ func (s *CemOSCEVSuite) Test_Public() { mData = &model.MeasurementDescriptionListDataType{ MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ { - 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)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), Unit: util.Ptr(model.UnitOfMeasurementTypeA), @@ -103,7 +87,7 @@ func (s *CemOSCEVSuite) Test_Public() { }, }, } - _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, &model.FilterType{}, nil) + _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) assert.Nil(s.T(), errT) _, _, _, err = s.sut.CurrentLimits(s.evEntity) From fd32aadd3a398cdc4b94836686973b52353559d1 Mon Sep 17 00:00:00 2001 From: "ahmed.magdy" Date: Tue, 26 Nov 2024 23:52:10 +0200 Subject: [PATCH 4/5] create bare-bone measurement description filters from measurement ids obtained from relevant load control limit descritpions. they need not exist in the measurement description list. --- usecases/cem/opev/public.go | 14 +------------- usecases/cem/opev/public_test.go | 27 --------------------------- usecases/cem/oscev/public.go | 14 +------------- usecases/cem/oscev/public_test.go | 27 --------------------------- 4 files changed, 2 insertions(+), 80 deletions(-) diff --git a/usecases/cem/opev/public.go b/usecases/cem/opev/public.go index ff93e151..4a34ed52 100644 --- a/usecases/cem/opev/public.go +++ b/usecases/cem/opev/public.go @@ -31,11 +31,6 @@ func (e *OPEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } - meas, err := client.NewMeasurement(e.LocalEntity, entity) - if err != nil { - return nil, nil, nil, err - } - filter := model.LoadControlLimitDescriptionDataType { LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), @@ -60,14 +55,7 @@ func (e *OPEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, filter := model.MeasurementDescriptionDataType{ MeasurementId: measId, } - mds, err := meas.GetDescriptionsForFilter(filter) - if err != nil { - return nil, nil, nil, err - } - if len(mds) != 1 { - return nil, nil, nil, api.ErrDataNotAvailable - } - measDescs = append(measDescs, mds[0]) + measDescs = append(measDescs, filter) } return ec.GetPhaseCurrentLimits(measDescs) } diff --git a/usecases/cem/opev/public_test.go b/usecases/cem/opev/public_test.go index b4e3965a..c4263648 100644 --- a/usecases/cem/opev/public_test.go +++ b/usecases/cem/opev/public_test.go @@ -66,33 +66,6 @@ func (s *CemOPEVSuite) Test_Public() { _, _, _, err = s.sut.CurrentLimits(s.evEntity) assert.NotNil(s.T(), err) - mData := &model.MeasurementDescriptionListDataType{ - MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ - }, - } - _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) - assert.Nil(s.T(), errT) - - _, _, _, err = s.sut.CurrentLimits(s.evEntity) - assert.NotNil(s.T(), err) - - mData = &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), - }, - }, - } - _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) - assert.Nil(s.T(), errT) - - _, _, _, err = s.sut.CurrentLimits(s.evEntity) - assert.NotNil(s.T(), err) - _, err = s.sut.LoadControlLimits(s.mockRemoteEntity) assert.NotNil(s.T(), err) diff --git a/usecases/cem/oscev/public.go b/usecases/cem/oscev/public.go index fae73c82..23972f27 100644 --- a/usecases/cem/oscev/public.go +++ b/usecases/cem/oscev/public.go @@ -31,11 +31,6 @@ func (e *OSCEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, return nil, nil, nil, err } - meas, err := client.NewMeasurement(e.LocalEntity, entity) - if err != nil { - return nil, nil, nil, err - } - filter := model.LoadControlLimitDescriptionDataType { LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), LimitCategory: util.Ptr(model.LoadControlCategoryTypeRecommendation), @@ -60,14 +55,7 @@ func (e *OSCEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, filter := model.MeasurementDescriptionDataType{ MeasurementId: measId, } - mds, err := meas.GetDescriptionsForFilter(filter) - if err != nil { - return nil, nil, nil, err - } - if len(mds) != 1 { - return nil, nil, nil, api.ErrDataNotAvailable - } - measDescs = append(measDescs, mds[0]) + measDescs = append(measDescs, filter) } return ec.GetPhaseCurrentLimits(measDescs) } diff --git a/usecases/cem/oscev/public_test.go b/usecases/cem/oscev/public_test.go index 8a390dcc..047f1c19 100644 --- a/usecases/cem/oscev/public_test.go +++ b/usecases/cem/oscev/public_test.go @@ -66,33 +66,6 @@ func (s *CemOSCEVSuite) Test_Public() { _, _, _, err = s.sut.CurrentLimits(s.evEntity) assert.NotNil(s.T(), err) - mData := &model.MeasurementDescriptionListDataType{ - MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ - }, - } - _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) - assert.Nil(s.T(), errT) - - _, _, _, err = s.sut.CurrentLimits(s.evEntity) - assert.NotNil(s.T(), err) - - mData = &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), - }, - }, - } - _, errT = meas.UpdateData(true, model.FunctionTypeMeasurementDescriptionListData, mData, nil, nil) - assert.Nil(s.T(), errT) - - _, _, _, err = s.sut.CurrentLimits(s.evEntity) - assert.NotNil(s.T(), err) - _, err = s.sut.LoadControlLimits(s.mockRemoteEntity) assert.NotNil(s.T(), err) From d65de8d967227cf299f6d99defa3b28ed2de32ef Mon Sep 17 00:00:00 2001 From: "ahmed.magdy" Date: Thu, 28 Nov 2024 11:51:40 +0200 Subject: [PATCH 5/5] some aesthetic variable name change --- usecases/cem/opev/public.go | 4 ++-- usecases/cem/oscev/public.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/usecases/cem/opev/public.go b/usecases/cem/opev/public.go index 4a34ed52..188158ba 100644 --- a/usecases/cem/opev/public.go +++ b/usecases/cem/opev/public.go @@ -52,10 +52,10 @@ func (e *OPEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, if measId == nil { return nil, nil, nil, api.ErrDataNotAvailable } - filter := model.MeasurementDescriptionDataType{ + md := model.MeasurementDescriptionDataType{ MeasurementId: measId, } - measDescs = append(measDescs, filter) + measDescs = append(measDescs, md) } return ec.GetPhaseCurrentLimits(measDescs) } diff --git a/usecases/cem/oscev/public.go b/usecases/cem/oscev/public.go index 23972f27..1a2a64c5 100644 --- a/usecases/cem/oscev/public.go +++ b/usecases/cem/oscev/public.go @@ -52,10 +52,10 @@ func (e *OSCEV) CurrentLimits(entity spineapi.EntityRemoteInterface) ([]float64, if measId == nil { return nil, nil, nil, api.ErrDataNotAvailable } - filter := model.MeasurementDescriptionDataType{ + md := model.MeasurementDescriptionDataType{ MeasurementId: measId, } - measDescs = append(measDescs, filter) + measDescs = append(measDescs, md) } return ec.GetPhaseCurrentLimits(measDescs) }