Skip to content

Commit e8b7796

Browse files
committed
Add functions to read currently stored meter readings and use in tests
1 parent 47947ab commit e8b7796

File tree

3 files changed

+268
-10
lines changed

3 files changed

+268
-10
lines changed

usecases/api/mu_mpc.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ type MuMPCInterface interface {
1717
// - power: the active power
1818
SetPower(power float64) error
1919

20+
// return the momentary active power consumption or production
21+
//
22+
// possible errors:
23+
// - ErrDataNotAvailable if no such value is (yet) available
24+
// - and others
25+
Power() (float64, error)
26+
2027
// set the momentary active phase specific power consumption or production per phase
2128
//
2229
// parameters:
@@ -25,6 +32,13 @@ type MuMPCInterface interface {
2532
// - phaseC: the active power of phase C
2633
SetPowerPerPhase(phaseA, phaseB, phaseC float64) error
2734

35+
// return the momentary active phase specific power consumption or production per phase
36+
//
37+
// possible errors:
38+
// - ErrDataNotAvailable if no such values are (yet) available
39+
// - and others
40+
PowerPerPhase() ([]float64, error)
41+
2842
// Scenario 2
2943

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

50+
// return the total feed in energy
51+
//
52+
// return values:
53+
// - negative values are used for production
54+
EnergyConsumed() (float64, error)
55+
3656
// set the total feed in energy
3757
//
3858
// parameters:
3959
// - produced: the total feed in energy
4060
SetEnergyProduced(produced float64) error
4161

62+
// return the total feed in energy
63+
//
64+
// return values:
65+
// - negative values are used for production
66+
EnergyProduced() (float64, error)
67+
4268
// Scenario 3
4369

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

78+
// return the momentary phase specific current consumption or production
79+
//
80+
// return values
81+
// - positive values are used for consumption
82+
// - negative values are used for production
83+
CurrentPerPhase() ([]float64, error)
84+
5285
// Scenario 4
5386

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

95+
// return the phase specific voltage details
96+
VoltagePerPhase() ([]float64, error)
97+
6298
// Scenario 5
6399

64100
// set frequency
65101
//
66102
// parameters:
67103
// - frequency: the frequency
68104
SetFrequency(frequency float64) error
105+
106+
// return frequency
107+
Frequency() (float64, error)
69108
}

usecases/mu/mpc/public.go

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ func (e *MPC) SetPower(power float64) error {
2424
return nil
2525
}
2626

27+
// get the momentary active power consumption or production
28+
//
29+
// possible errors:
30+
// - ErrMissingData if the id is not available
31+
// - and others
32+
func (e *MPC) Power() (float64, error) {
33+
if e.acPowerTotal == nil {
34+
return 0, api.ErrMissingData
35+
}
36+
37+
return e.getMeasurementDataForId(e.acPowerTotal)
38+
}
39+
2740
// set the momentary active power consumption or production per phase
2841
//
2942
// possible errors:
@@ -52,6 +65,34 @@ func (e *MPC) SetPowerPerPhase(phaseA, phaseB, phaseC float64) error {
5265
return nil
5366
}
5467

68+
// get the momentary active power consumption or production per phase
69+
//
70+
// possible errors:
71+
// - ErrMissingData if the id is not available
72+
// - and others
73+
func (e *MPC) PowerPerPhase() ([]float64, error) {
74+
if e.acPower[0] == nil || e.acPower[1] == nil || e.acPower[2] == nil {
75+
return nil, api.ErrMissingData
76+
}
77+
78+
phaseA, err := e.getMeasurementDataForId(e.acPower[0])
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
phaseB, err := e.getMeasurementDataForId(e.acPower[1])
84+
if err != nil {
85+
return nil, err
86+
}
87+
88+
phaseC, err := e.getMeasurementDataForId(e.acPower[2])
89+
if err != nil {
90+
return nil, err
91+
}
92+
93+
return []float64{phaseA, phaseB, phaseC}, nil
94+
}
95+
5596
// Scenario 2
5697

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

114+
// get the total feed in energy
115+
//
116+
// - negative values are used for production
117+
//
118+
// possible errors:
119+
// - ErrMissingData if the id is not available
120+
// - and others
121+
func (e *MPC) EnergyConsumed() (float64, error) {
122+
if e.acEnergyConsumed == nil {
123+
return 0, api.ErrMissingData
124+
}
125+
126+
return e.getMeasurementDataForId(e.acEnergyConsumed)
127+
}
128+
73129
// set the total feed in energy
74130
//
75131
// - negative values are used for production
@@ -86,6 +142,21 @@ func (e *MPC) SetEnergyProduced(energy float64) error {
86142
return nil
87143
}
88144

145+
// get the total feed in energy
146+
//
147+
// - negative values are used for production
148+
//
149+
// possible errors:
150+
// - ErrMissingData if the id is not available
151+
// - and others
152+
func (e *MPC) EnergyProduced() (float64, error) {
153+
if e.acEnergyProduced == nil {
154+
return 0, api.ErrMissingData
155+
}
156+
157+
return e.getMeasurementDataForId(e.acEnergyProduced)
158+
}
159+
89160
// Scenario 3
90161

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

189+
// get the momentary phase specific current consumption or production
190+
//
191+
// - positive values are used for consumption
192+
// - negative values are used for production
193+
//
194+
// possible errors:
195+
// - ErrMissingData if the id is not available
196+
// - and others
197+
func (e *MPC) CurrentPerPhase() ([]float64, error) {
198+
if e.acCurrent[0] == nil || e.acCurrent[1] == nil || e.acCurrent[2] == nil {
199+
return nil, api.ErrMissingData
200+
}
201+
202+
phaseA, err := e.getMeasurementDataForId(e.acCurrent[0])
203+
if err != nil {
204+
return nil, err
205+
}
206+
207+
phaseB, err := e.getMeasurementDataForId(e.acCurrent[1])
208+
if err != nil {
209+
return nil, err
210+
}
211+
212+
phaseC, err := e.getMeasurementDataForId(e.acCurrent[2])
213+
if err != nil {
214+
return nil, err
215+
}
216+
217+
return []float64{phaseA, phaseB, phaseC}, nil
218+
}
219+
118220
// Scenario 4
119221

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

248+
// get the phase specific voltage details
249+
//
250+
// possible errors:
251+
// - ErrMissingData if the id is not available
252+
// - and others
253+
func (e *MPC) VoltagePerPhase() ([]float64, error) {
254+
for _, id := range e.acVoltage {
255+
if id == nil {
256+
return nil, api.ErrMissingData
257+
}
258+
}
259+
260+
phaseA, err := e.getMeasurementDataForId(e.acVoltage[0])
261+
if err != nil {
262+
return nil, err
263+
}
264+
265+
phaseB, err := e.getMeasurementDataForId(e.acVoltage[1])
266+
if err != nil {
267+
return nil, err
268+
}
269+
270+
phaseC, err := e.getMeasurementDataForId(e.acVoltage[2])
271+
if err != nil {
272+
return nil, err
273+
}
274+
275+
return []float64{phaseA, phaseB, phaseC}, nil
276+
}
277+
146278
// Scenario 5
147279

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

159291
return nil
160292
}
293+
294+
// get frequency
295+
//
296+
// possible errors:
297+
// - ErrMissingData if the id is not available
298+
// - and others
299+
func (e *MPC) Frequency() (float64, error) {
300+
if e.acFrequency == nil {
301+
return 0, api.ErrMissingData
302+
}
303+
304+
return e.getMeasurementDataForId(e.acFrequency)
305+
}

0 commit comments

Comments
 (0)