private fields for calculated values
This commit is contained in:
@@ -9,8 +9,8 @@ package goodcalc
|
|||||||
type Aspect struct {
|
type Aspect struct {
|
||||||
No string `json:"no"`
|
No string `json:"no"`
|
||||||
Weight float32 `json:"weight"`
|
Weight float32 `json:"weight"`
|
||||||
MaxValuationPoints int `json:"max_valuation_points"`
|
|
||||||
ValuationPoints int `json:"valuation_points"`
|
ValuationPoints int `json:"valuation_points"`
|
||||||
|
maxValuationPoints int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NegativeAspect has the same fields like Aspect. But the
|
// NegativeAspect has the same fields like Aspect. But the
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ func (m *Matrix) String() string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BalancePoints calculates the ecogood points for the matrix
|
||||||
func (m *Matrix) BalancePoints() int {
|
func (m *Matrix) BalancePoints() int {
|
||||||
var balancePoints float64
|
var balancePoints float64
|
||||||
m.calcWeightFactor()
|
m.calcWeightFactor()
|
||||||
@@ -105,13 +106,13 @@ func (m *Matrix) setMaxValuationPoints() {
|
|||||||
m.forall(func(t *Theme) {
|
m.forall(func(t *Theme) {
|
||||||
maxThemeValPoints := 0
|
maxThemeValPoints := 0
|
||||||
for _, a := range t.Aspects {
|
for _, a := range t.Aspects {
|
||||||
a.MaxValuationPoints = m.MaxValuationPoints * int(a.Weight)
|
a.maxValuationPoints = m.MaxValuationPoints * int(a.Weight)
|
||||||
maxThemeValPoints += m.MaxValuationPoints * int(a.Weight)
|
maxThemeValPoints += m.MaxValuationPoints * int(a.Weight)
|
||||||
}
|
}
|
||||||
t.Calc.MaxValuationPoints = maxThemeValPoints
|
t.Calc.MaxValuationPoints = maxThemeValPoints
|
||||||
for _, na := range t.NegativeAspects {
|
for _, na := range t.NegativeAspects {
|
||||||
na.MaxValuationPoints = m.MaxNegValuationPoints
|
na.maxValuationPoints = m.MaxNegValuationPoints
|
||||||
}
|
}
|
||||||
t.NegPointsFactor = m.NegPointsFactor
|
t.negPointsFactor = m.NegPointsFactor
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func emptyMatrix() *Matrix {
|
|||||||
Weight: 1,
|
Weight: 1,
|
||||||
Aspects: []Aspect{},
|
Aspects: []Aspect{},
|
||||||
NegativeAspects: []NegativeAspect{},
|
NegativeAspects: []NegativeAspect{},
|
||||||
NegPointsFactor: 0,
|
negPointsFactor: 0,
|
||||||
Calc: &ThemeCalc{},
|
Calc: &ThemeCalc{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
theme.go
6
theme.go
@@ -10,8 +10,8 @@ type Theme struct {
|
|||||||
Weight float32 `json:"weight"`
|
Weight float32 `json:"weight"`
|
||||||
Aspects []Aspect `json:"aspects"`
|
Aspects []Aspect `json:"aspects"`
|
||||||
NegativeAspects []NegativeAspect `json:"negative_aspects"`
|
NegativeAspects []NegativeAspect `json:"negative_aspects"`
|
||||||
NegPointsFactor int `json:"neg_points_factor"`
|
|
||||||
Calc *ThemeCalc `json:"calculation"`
|
Calc *ThemeCalc `json:"calculation"`
|
||||||
|
negPointsFactor int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Theme) String() string {
|
func (t *Theme) String() string {
|
||||||
@@ -20,7 +20,7 @@ func (t *Theme) String() string {
|
|||||||
s += fmt.Sprintf(" Weight: %.1f\n", t.Weight)
|
s += fmt.Sprintf(" Weight: %.1f\n", t.Weight)
|
||||||
s += fmt.Sprintf(" Aspects: %v\n", t.Aspects)
|
s += fmt.Sprintf(" Aspects: %v\n", t.Aspects)
|
||||||
s += fmt.Sprintf(" NegativeAspects: %v\n", t.NegativeAspects)
|
s += fmt.Sprintf(" NegativeAspects: %v\n", t.NegativeAspects)
|
||||||
s += fmt.Sprintf(" NegPointsFactor: %v\n", t.NegPointsFactor)
|
s += fmt.Sprintf(" NegPointsFactor: %v\n", t.negPointsFactor)
|
||||||
s += fmt.Sprintf(" Calc: %s\n", t.Calc)
|
s += fmt.Sprintf(" Calc: %s\n", t.Calc)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
@@ -52,7 +52,7 @@ func (t *Theme) calcBalancePoints() {
|
|||||||
t.Calc.BalancePoints =
|
t.Calc.BalancePoints =
|
||||||
t.Calc.EstPercentage * t.Calc.MaxBalancePoints
|
t.Calc.EstPercentage * t.Calc.MaxBalancePoints
|
||||||
t.Calc.NegativeBlancePoints =
|
t.Calc.NegativeBlancePoints =
|
||||||
float32(t.Calc.NegativeValuationPoints) * t.Calc.MaxBalancePoints / float32(t.NegPointsFactor)
|
float32(t.Calc.NegativeValuationPoints) * t.Calc.MaxBalancePoints / float32(t.negPointsFactor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ThemeCalc contains the different calculation
|
// ThemeCalc contains the different calculation
|
||||||
|
|||||||
Reference in New Issue
Block a user