Skip to content

Commit

Permalink
have CurrentLimits method in opev and oscev filter for LoadControlLim…
Browse files Browse the repository at this point in the history
…itDescriptionData instead of MeasurementDescriptionData
  • Loading branch information
AhmedMagdyCoretech committed Nov 26, 2024
1 parent 59e7016 commit b3f9e2c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 14 deletions.
37 changes: 30 additions & 7 deletions usecases/cem/opev/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 30 additions & 7 deletions usecases/cem/oscev/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b3f9e2c

Please sign in to comment.