private fields for calculated values

This commit is contained in:
Andreas Schröpfer
2021-01-03 08:08:10 +01:00
parent 23214be74e
commit 9f5d258f65
6 changed files with 9 additions and 8 deletions

BIN
README.md

Binary file not shown.

0
go.sum Normal file
View File

View File

@@ -9,8 +9,8 @@ package goodcalc
type Aspect struct {
No string `json:"no"`
Weight float32 `json:"weight"`
MaxValuationPoints int `json:"max_valuation_points"`
ValuationPoints int `json:"valuation_points"`
maxValuationPoints int
}
// NegativeAspect has the same fields like Aspect. But the

View File

@@ -38,6 +38,7 @@ func (m *Matrix) String() string {
return s
}
// BalancePoints calculates the ecogood points for the matrix
func (m *Matrix) BalancePoints() int {
var balancePoints float64
m.calcWeightFactor()
@@ -105,13 +106,13 @@ func (m *Matrix) setMaxValuationPoints() {
m.forall(func(t *Theme) {
maxThemeValPoints := 0
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)
}
t.Calc.MaxValuationPoints = maxThemeValPoints
for _, na := range t.NegativeAspects {
na.MaxValuationPoints = m.MaxNegValuationPoints
na.maxValuationPoints = m.MaxNegValuationPoints
}
t.NegPointsFactor = m.NegPointsFactor
t.negPointsFactor = m.NegPointsFactor
})
}

View File

@@ -35,7 +35,7 @@ func emptyMatrix() *Matrix {
Weight: 1,
Aspects: []Aspect{},
NegativeAspects: []NegativeAspect{},
NegPointsFactor: 0,
negPointsFactor: 0,
Calc: &ThemeCalc{},
}

View File

@@ -10,8 +10,8 @@ type Theme struct {
Weight float32 `json:"weight"`
Aspects []Aspect `json:"aspects"`
NegativeAspects []NegativeAspect `json:"negative_aspects"`
NegPointsFactor int `json:"neg_points_factor"`
Calc *ThemeCalc `json:"calculation"`
negPointsFactor int
}
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(" Aspects: %v\n", t.Aspects)
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)
return s
}
@@ -52,7 +52,7 @@ func (t *Theme) calcBalancePoints() {
t.Calc.BalancePoints =
t.Calc.EstPercentage * t.Calc.MaxBalancePoints
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