package goodcalc // Theme is the basic element of the matrix. // No defines the id of the excel balance. // A1 for Human dignity in the supply chain type Theme struct { No string `json:"no"` Weight float32 `json:"weight"` Aspects []Aspect `json:"aspects"` NegativeAspects []NegativeAspect `json:"negative_aspects"` NegPointsFactor int `json:"neg_points_factor"` Calc *ThemeCalc `json:"calculation"` } func (t *Theme) calcNrPosAspects() { t.Calc.NrPositiveAspects = len(t.Aspects) } func (t *Theme) calcValPoints() { t.Calc.ValuationPoints = 0 for _, a := range t.Aspects { t.Calc.ValuationPoints += a.ValuationPoints * int(a.Weight) } for _, na := range t.NegativeAspects { t.Calc.NegativeValuationPoints += na.ValuationPoints * int(na.Weight) } } func (t *Theme) calcEstPercentage() { t.Calc.EstPercentage = 0 if t.Calc.MaxValuationPoints != 0 { t.Calc.EstPercentage = float32(t.Calc.ValuationPoints / t.Calc.MaxValuationPoints) } } 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) } // ThemeCalc contains the different calculation // steps. type ThemeCalc struct { CalcWeight float32 `json:"calc_weight"` WeightFactor float32 `json:"weight_factor"` MaxBalancePoints float32 `json:"max_points"` NrPositiveAspects int `json:"nr_positive_aspects"` ValuationPoints int `json:"valuation_points"` MaxValuationPoints int `json:"max_valuation_points"` EstPercentage float32 `json:"est_percentage"` BalancePoints float32 `json:"balance_points"` NegativeValuationPoints int `json:"negative_valuation_points"` NegativeBlancePoints float32 `json:"negative_blance_points"` } // calcMaxPoints // Stakeholder.calcWeight needs to run first func (c *ThemeCalc) calcMaxPoints() { c.MaxBalancePoints = c.CalcWeight * c.WeightFactor }