first simple test for positive aspects
This commit is contained in:
47
matrix.go
47
matrix.go
@@ -1,5 +1,10 @@
|
||||
package goodcalc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// Matrix contains the stakeholders and the maximal
|
||||
// allowed points of the calculation. The calculation
|
||||
// is pretty simple. Inside each aspect ValuationPoints
|
||||
@@ -16,7 +21,38 @@ type Matrix struct {
|
||||
MaxNegValuationPoints int `json:"max_neg_valuation_points"` // -200
|
||||
NegPointsFactor int `json:"neg_points_factor"` // 50
|
||||
Stakeholders []*Stakeholder `json:"stakeholders"`
|
||||
Calculation MatrixCalc `json:"calculation"`
|
||||
Calculation *MatrixCalc `json:"calculation"`
|
||||
}
|
||||
|
||||
func (m *Matrix) String() string {
|
||||
if m == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
var s string
|
||||
s += fmt.Sprintf("MaxPoints: %d\n", m.MaxPoints)
|
||||
s += fmt.Sprintf("MaxValuationPoints: %d\n", m.MaxValuationPoints)
|
||||
s += fmt.Sprintf("MaxNegValuationPoints: %d\n", m.MaxNegValuationPoints)
|
||||
s += fmt.Sprintf("NegPointsFactor: %d\n", m.NegPointsFactor)
|
||||
s += fmt.Sprintf("Calculation: %#v\n", m.Calculation)
|
||||
s += fmt.Sprintf("Stakeholders: {\n%s\n}\n", m.Stakeholders)
|
||||
return s
|
||||
}
|
||||
|
||||
func (m *Matrix) BalancePoints() int {
|
||||
var balancePoints float64
|
||||
m.calcWeightFactor()
|
||||
m.setMaxValuationPoints()
|
||||
m.forall(func(t *Theme) {
|
||||
t.Calc.calcMaxPoints()
|
||||
t.calcNrPosAspects()
|
||||
t.calcValPoints()
|
||||
t.calcEstPercentage()
|
||||
t.calcBalancePoints()
|
||||
balancePoints += float64(t.Calc.BalancePoints)
|
||||
balancePoints += float64(t.Calc.NegativeBlancePoints)
|
||||
})
|
||||
balancePoints = math.Round(balancePoints)
|
||||
return int(balancePoints)
|
||||
}
|
||||
|
||||
// MatrixCalc contains calculated values
|
||||
@@ -34,7 +70,14 @@ func (m *Matrix) forall(f func(t *Theme)) {
|
||||
}
|
||||
}
|
||||
|
||||
// sumCalcWeight sums all the calculated weights of
|
||||
// the matrix.
|
||||
func (m *Matrix) sumCalcWeight() {
|
||||
// calculate the stakeholder weight to each
|
||||
// theme
|
||||
for _, s := range m.Stakeholders {
|
||||
s.calcWeight()
|
||||
}
|
||||
m.Calculation.SumCalcWeight = 0
|
||||
m.forall(func(t *Theme) {
|
||||
m.Calculation.SumCalcWeight += t.Calc.CalcWeight
|
||||
@@ -63,7 +106,7 @@ func (m *Matrix) setMaxValuationPoints() {
|
||||
maxThemeValPoints := 0
|
||||
for _, a := range t.Aspects {
|
||||
a.MaxValuationPoints = m.MaxValuationPoints * int(a.Weight)
|
||||
maxThemeValPoints += m.MaxNegValuationPoints * int(a.Weight)
|
||||
maxThemeValPoints += m.MaxValuationPoints * int(a.Weight)
|
||||
}
|
||||
t.Calc.MaxValuationPoints = maxThemeValPoints
|
||||
for _, na := range t.NegativeAspects {
|
||||
|
||||
Reference in New Issue
Block a user