Skip to content

Commit

Permalink
Add functions to read currently stored meter readings and use in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sthelen-enqs committed Aug 30, 2024
1 parent 47947ab commit e8b7796
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 10 deletions.
39 changes: 39 additions & 0 deletions usecases/api/mu_mpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ type MuMPCInterface interface {
// - power: the active power
SetPower(power float64) error

// return the momentary active power consumption or production
//
// possible errors:
// - ErrDataNotAvailable if no such value is (yet) available
// - and others
Power() (float64, error)

// set the momentary active phase specific power consumption or production per phase
//
// parameters:
Expand All @@ -25,6 +32,13 @@ type MuMPCInterface interface {
// - phaseC: the active power of phase C
SetPowerPerPhase(phaseA, phaseB, phaseC float64) error

// return the momentary active phase specific power consumption or production per phase
//
// possible errors:
// - ErrDataNotAvailable if no such values are (yet) available
// - and others
PowerPerPhase() ([]float64, error)

// Scenario 2

// set the total consumption energy
Expand All @@ -33,12 +47,24 @@ type MuMPCInterface interface {
// - consumed: the total consumption energy
SetEnergyConsumed(consumed float64) error

// return the total feed in energy
//
// return values:
// - negative values are used for production
EnergyConsumed() (float64, error)

// set the total feed in energy
//
// parameters:
// - produced: the total feed in energy
SetEnergyProduced(produced float64) error

// return the total feed in energy
//
// return values:
// - negative values are used for production
EnergyProduced() (float64, error)

// Scenario 3

// set the momentary phase specific current consumption or production
Expand All @@ -49,6 +75,13 @@ type MuMPCInterface interface {
// - phaseC: the current of phase C
SetCurrentPerPhase(phaseA, phaseB, phaseC float64) error

// return the momentary phase specific current consumption or production
//
// return values
// - positive values are used for consumption
// - negative values are used for production
CurrentPerPhase() ([]float64, error)

// Scenario 4

// set the phase specific voltage details
Expand All @@ -59,11 +92,17 @@ type MuMPCInterface interface {
// - phaseC: the voltage of phase C
SetVoltagePerPhase(phaseA, phaseB, phaseC float64) error

// return the phase specific voltage details
VoltagePerPhase() ([]float64, error)

// Scenario 5

// set frequency
//
// parameters:
// - frequency: the frequency
SetFrequency(frequency float64) error

// return frequency
Frequency() (float64, error)
}
145 changes: 145 additions & 0 deletions usecases/mu/mpc/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ func (e *MPC) SetPower(power float64) error {
return nil
}

// get the momentary active power consumption or production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
func (e *MPC) Power() (float64, error) {
if e.acPowerTotal == nil {
return 0, api.ErrMissingData
}

return e.getMeasurementDataForId(e.acPowerTotal)
}

// set the momentary active power consumption or production per phase
//
// possible errors:
Expand Down Expand Up @@ -52,6 +65,34 @@ func (e *MPC) SetPowerPerPhase(phaseA, phaseB, phaseC float64) error {
return nil
}

// get the momentary active power consumption or production per phase
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
func (e *MPC) PowerPerPhase() ([]float64, error) {
if e.acPower[0] == nil || e.acPower[1] == nil || e.acPower[2] == nil {
return nil, api.ErrMissingData
}

phaseA, err := e.getMeasurementDataForId(e.acPower[0])
if err != nil {
return nil, err
}

phaseB, err := e.getMeasurementDataForId(e.acPower[1])
if err != nil {
return nil, err
}

phaseC, err := e.getMeasurementDataForId(e.acPower[2])
if err != nil {
return nil, err
}

return []float64{phaseA, phaseB, phaseC}, nil
}

// Scenario 2

// set the total consumption energy
Expand All @@ -70,6 +111,21 @@ func (e *MPC) SetEnergyConsumed(energy float64) error {
return nil
}

// get the total feed in energy
//
// - negative values are used for production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
func (e *MPC) EnergyConsumed() (float64, error) {
if e.acEnergyConsumed == nil {
return 0, api.ErrMissingData
}

return e.getMeasurementDataForId(e.acEnergyConsumed)
}

// set the total feed in energy
//
// - negative values are used for production
Expand All @@ -86,6 +142,21 @@ func (e *MPC) SetEnergyProduced(energy float64) error {
return nil
}

// get the total feed in energy
//
// - negative values are used for production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
func (e *MPC) EnergyProduced() (float64, error) {
if e.acEnergyProduced == nil {
return 0, api.ErrMissingData
}

return e.getMeasurementDataForId(e.acEnergyProduced)
}

// Scenario 3

// set the momentary phase specific current consumption or production
Expand Down Expand Up @@ -115,6 +186,37 @@ func (e *MPC) SetCurrentPerPhase(phaseA, phaseB, phaseC float64) error {
return nil
}

// get the momentary phase specific current consumption or production
//
// - positive values are used for consumption
// - negative values are used for production
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
func (e *MPC) CurrentPerPhase() ([]float64, error) {
if e.acCurrent[0] == nil || e.acCurrent[1] == nil || e.acCurrent[2] == nil {
return nil, api.ErrMissingData
}

phaseA, err := e.getMeasurementDataForId(e.acCurrent[0])
if err != nil {
return nil, err
}

phaseB, err := e.getMeasurementDataForId(e.acCurrent[1])
if err != nil {
return nil, err
}

phaseC, err := e.getMeasurementDataForId(e.acCurrent[2])
if err != nil {
return nil, err
}

return []float64{phaseA, phaseB, phaseC}, nil
}

// Scenario 4

// set the phase specific voltage details
Expand Down Expand Up @@ -143,6 +245,36 @@ func (e *MPC) SetVoltagePerPhase(phaseA, phaseB, phaseC float64) error {
return nil
}

// get the phase specific voltage details
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
func (e *MPC) VoltagePerPhase() ([]float64, error) {
for _, id := range e.acVoltage {
if id == nil {
return nil, api.ErrMissingData
}
}

phaseA, err := e.getMeasurementDataForId(e.acVoltage[0])
if err != nil {
return nil, err
}

phaseB, err := e.getMeasurementDataForId(e.acVoltage[1])
if err != nil {
return nil, err
}

phaseC, err := e.getMeasurementDataForId(e.acVoltage[2])
if err != nil {
return nil, err
}

return []float64{phaseA, phaseB, phaseC}, nil
}

// Scenario 5

// SetFrequency set frequency
Expand All @@ -158,3 +290,16 @@ func (e *MPC) SetFrequency(frequency float64) error {

return nil
}

// get frequency
//
// possible errors:
// - ErrMissingData if the id is not available
// - and others
func (e *MPC) Frequency() (float64, error) {
if e.acFrequency == nil {
return 0, api.ErrMissingData
}

return e.getMeasurementDataForId(e.acFrequency)
}
Loading

0 comments on commit e8b7796

Please sign in to comment.