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

@@ -10,6 +10,7 @@ type Ecalc struct {
Type string `json:"type"`
Version string `json:"version"`
CompanyFacts CompanyFacts `json:"companyFacts"`
Matrix Matrix `json:"matrix"`
}
// EncodeJSON writes the JSON of the conf into the Writer
@@ -87,3 +88,16 @@ type Aspect struct {
IsWeightSelectedByUser bool `json:"isWeightSelectedByUser"`
IsPositive bool `json:"isPositive"`
}
type Matrix struct {
Topics []MatrixTopic `json:"topics"`
}
type MatrixTopic struct {
ShortName string `json:"shortName"`
Name string `json:"name"`
Points int `json:"points"`
MaxPoints int `json:"maxPoints"`
PercentageReached int `json:"percentageReached"`
NotApplicable bool `json:"notApplicable"`
}

View File

@@ -32,6 +32,7 @@ type Conf struct {
Values []Value `json:"values"`
Areas []Area `json:"areas"`
Rating Rating `json:"rating"`
Matrix Matrix `json:"matrix"`
}
// EncodeJSON writes the JSON of the conf into the Writer
@@ -103,3 +104,22 @@ type RatingCol struct {
Type string `json:"type"`
Default string `json:"default"`
}
type Matrix struct {
Sheet int `json:"sheet"`
Stakeholders []Stakeholder `json:"stakeholders"`
Values []MatrixValue `json:"values"`
}
type Stakeholder struct {
Row int `json:"row"`
ShortName string `json:"short_name"`
Name string `json:"name"`
}
type MatrixValue struct {
ShortName string `json:"short_name"`
PointsCol string `json:"points_col"`
PercentageReachedCol string `json:"percentage_reached_col"`
MaxPointsCol string `json:"max_points_col"`
}

View File

@@ -229,6 +229,66 @@
"default": ""
}
]
},
"matrix": {
"sheet": 5,
"stakeholders": [
{
"row": 9,
"short_name": "A",
"name": "Suppliers"
},
{
"row": 11,
"short_name": "B",
"name": "Owners"
},
{
"row": 13,
"short_name": "C",
"name": "Employees"
},
{
"row": 15,
"short_name": "D",
"name": "Customers"
},
{
"row": 17,
"short_name": "E",
"name": "Social environment"
}
],
"values": [
{
"short_name": "1",
"name": "Human dignity",
"points_col": "C",
"percentage_reached_col": "F",
"max_points_col": "E"
},
{
"short_name": "2",
"name": "Solidarity",
"points_col": "G",
"percentage_reached_col": "I",
"max_points_col": "J"
},
{
"short_name": "3",
"name": "Environment sustainability",
"points_col": "K",
"percentage_reached_col": "M",
"max_points_col": "N"
},
{
"short_name": "4",
"name": "Transparency",
"points_col": "O",
"percentage_reached_col": "Q",
"max_points_col": "R"
}
]
}
}

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
}

View File

@@ -20,4 +20,14 @@ func TestXLSX(t *testing.T) {
is.Equal(got.CompanyFacts.TotalPurchaseFromSuppliers, 10000)
is.Equal(got.CompanyFacts.SupplyFractions[0].Costs, 500)
is.Equal(got.CompanyFacts.SupplyFractions[0].CountryCode, "ALB")
is.Equal(got.CompanyFacts.FinancialCosts, 12)
is.Equal(got.CompanyFacts.EmployeesFractions[1].CountryCode, "AUT")
is.Equal(got.Matrix.Topics[0].ShortName, "A1")
is.Equal(got.Matrix.Topics[0].MaxPoints, 44)
is.Equal(got.Matrix.Topics[4].ShortName, "B1")
is.Equal(got.Matrix.Topics[4].Points, 27)
is.Equal(got.Matrix.Topics[4].MaxPoints, 33)
is.Equal(got.Matrix.Topics[4].PercentageReached, 80)
}

Binary file not shown.