ecg matrix as output

This commit is contained in:
Andreas Schröpfer
2021-03-02 19:32:25 +01:00
parent cd7ee015a9
commit 72eb5c74d8
6 changed files with 362 additions and 223 deletions

View File

@@ -3,6 +3,8 @@ package loader
import (
"fmt"
"io"
"math"
"strconv"
"strings"
"git.ecogood.org/andreas.schroepfer/excelConverter/pkg/ecalc"
@@ -185,6 +187,39 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
}
}
eBalance.CompanyFacts.Rating.Topics = append(eBalance.CompanyFacts.Rating.Topics, topic)
for _, stakeh := range conf.Matrix.Stakeholders {
for _, val := range conf.Matrix.Values {
mTopic := ecalc.MatrixTopic{
ShortName: fmt.Sprintf("%s%s", stakeh.ShortName, val.ShortName),
}
readCell := func(col, field string) {
axis := fmt.Sprintf("%s%d", col, stakeh.Row)
cellValue, err := xFile.GetCellValue(
xFile.GetSheetName(conf.Matrix.Sheet),
axis,
)
if err != nil {
errs = append(errs, err)
}
f, err := strconv.ParseFloat(cellValue, 64)
switch field {
case "Points":
f = math.Round(f)
mTopic.Points = int(f)
case "MaxPoints":
f = math.Round(f)
mTopic.MaxPoints = int(f)
case "PercentageReached":
mTopic.PercentageReached = int(f * 100)
}
}
readCell(val.PointsCol, "Points")
readCell(val.MaxPointsCol, "MaxPoints")
readCell(val.PercentageReachedCol, "PercentageReached")
eBalance.Matrix.Topics = append(eBalance.Matrix.Topics, mTopic)
}
}
// TODO: error handling of errs
return eBalance, nil
}