-
Notifications
You must be signed in to change notification settings - Fork 0
/
GullyRestorationCommand.go
70 lines (56 loc) · 2.31 KB
/
GullyRestorationCommand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2019 Australian Rivers Institute.
package particulatenitrogen
import (
"github.com/LindsayBradford/crem/internal/pkg/model/planningunit"
"github.com/LindsayBradford/crem/internal/pkg/model/variable"
"github.com/LindsayBradford/crem/pkg/command"
)
type GullyRestorationCommand struct {
variable.ChangePerPlanningUnitDecisionVariableCommand
undoneGullyContribution float64
doneGullyContribution float64
}
func (c *GullyRestorationCommand) ForVariable(variable variable.PlanningUnitDecisionVariable) *GullyRestorationCommand {
c.WithTarget(variable)
return c
}
func (c *GullyRestorationCommand) InPlanningUnit(planningUnit planningunit.Id) *GullyRestorationCommand {
c.ChangePerPlanningUnitDecisionVariableCommand.InPlanningUnit(planningUnit)
return c
}
func (c *GullyRestorationCommand) WithNitrogenContribution(contribution float64) *GullyRestorationCommand {
c.undoneGullyContribution = c.gullyNitrogenContribution()
c.doneGullyContribution = contribution
return c
}
func (c *GullyRestorationCommand) WithChange(changeValue float64) *GullyRestorationCommand {
c.ChangePerPlanningUnitDecisionVariableCommand.WithChange(changeValue)
return c
}
func (c *GullyRestorationCommand) variable() *ParticulateNitrogenProduction {
return c.Target().(*ParticulateNitrogenProduction)
}
func (c *GullyRestorationCommand) Do() command.CommandStatus {
if c.BaseCommand.Do() == command.NoChange {
return command.NoChange
}
c.ChangePerPlanningUnitDecisionVariableCommand.DoUnguarded()
c.setGullyNitrogenContribution(c.doneGullyContribution)
return command.Done
}
func (c *GullyRestorationCommand) Undo() command.CommandStatus {
if c.BaseCommand.Undo() == command.NoChange {
return command.NoChange
}
c.ChangePerPlanningUnitDecisionVariableCommand.UndoUnguarded()
c.setGullyNitrogenContribution(c.undoneGullyContribution)
return command.UnDone
}
func (c *GullyRestorationCommand) setGullyNitrogenContribution(contribution float64) {
c.variable().subCatchmentAttributes[c.PlanningUnit()] =
c.variable().subCatchmentAttributes[c.PlanningUnit()].Replace(GullyNitrogenContribution, contribution)
}
func (c *GullyRestorationCommand) gullyNitrogenContribution() float64 {
planningUnitAttributes := c.variable().subCatchmentAttributes[c.PlanningUnit()]
return planningUnitAttributes.Value(GullyNitrogenContribution).(float64)
}