diff --git a/pkg/ecalc/ecalc.go b/pkg/ecalc/ecalc.go index f8919d0..dbccaf8 100644 --- a/pkg/ecalc/ecalc.go +++ b/pkg/ecalc/ecalc.go @@ -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"` +} diff --git a/pkg/loader/conf.go b/pkg/loader/conf.go index 57d78b5..25e0ded 100644 --- a/pkg/loader/conf.go +++ b/pkg/loader/conf.go @@ -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"` +} diff --git a/pkg/loader/conf/default.json b/pkg/loader/conf/default.json index 1902ca0..822c03a 100644 --- a/pkg/loader/conf/default.json +++ b/pkg/loader/conf/default.json @@ -1,234 +1,294 @@ { - "title": "Good Balance Calculator", - "version": "5.04", - "type": "Full", + "title": "Good Balance Calculator", + "version": "5.04", + "type": "Full", + "values": [ + { + "sheet": 2, + "cell": "C7", + "type": "int", + "struct": "CompanyFacts", + "field": "TotalPurchaseFromSuppliers", + "default": "" + }, + { + "sheet": 2, + "cell": "C27", + "type": "int", + "struct": "CompanyFacts", + "field": "TotalStaffCosts", + "default": "" + }, + { + "sheet": 2, + "cell": "C18", + "type": "int", + "struct": "CompanyFacts", + "field": "Profit", + "default": "" + }, + { + "sheet": 2, + "cell": "C19", + "type": "int", + "struct": "CompanyFacts", + "field": "FinancialCosts", + "default": "" + }, + { + "sheet": 2, + "cell": "C20", + "type": "int", + "struct": "CompanyFacts", + "field": "IncomeFromFinancialInvestments", + "default": "" + }, + { + "sheet": 2, + "cell": "C22", + "type": "int", + "struct": "CompanyFacts", + "field": "AdditionsToFixedAssets", + "default": "" + }, + { + "sheet": 2, + "cell": "C37", + "type": "int", + "struct": "CompanyFacts", + "field": "Turnover", + "default": "" + }, + { + "sheet": 2, + "cell": "C21", + "type": "int", + "struct": "CompanyFacts", + "field": "TotalAssets", + "default": "" + }, + { + "sheet": 2, + "cell": "C23", + "type": "int", + "struct": "CompanyFacts", + "field": "FinancialAssetsAndCashBalance", + "default": "" + }, + { + "sheet": 2, + "cell": "C26", + "type": "int", + "struct": "CompanyFacts", + "field": "NumberOfEmployees", + "default": "" + }, + { + "sheet": 2, + "cell": "C24", + "type": "bool", + "struct": "CompanyFacts", + "field": "HasCanteen", + "default": "" + }, + { + "sheet": 2, + "cell": "C38", + "type": "bool", + "struct": "CompanyFacts", + "field": "IsB2B", + "default": "" + }, + { + "sheet": 2, + "cell": "C33", + "type": "int", + "struct": "CompanyFacts", + "field": "AverageJourneyToWorkForStaffInKm", + "default": "" + } + ], + "areas": [ + { + "sheet": 2, + "start_row": 10, + "end_row": 14, + "struct": "SupplyFraction", + "cols": [ + { + "col": "B", + "field": "IndustryCode", + "type": "string", + "split": " ", + "default": "Please choose" + }, + { + "col": "D", + "field": "CountryCode", + "type": "string", + "split": " ", + "default": "Please choose" + }, + { + "col": "F", + "field": "Costs", + "type": "string", + "default": "0" + } + ] + }, + { + "sheet": 2, + "start_row": 30, + "end_row": 32, + "struct": "EmployeesFraction", + "cols": [ + { + "col": "B", + "field": "CountryCode", + "type": "string", + "split": " ", + "default": "Please choose" + }, + { + "col": "D", + "field": "Percentage", + "type": "float64", + "default": "0" + } + ] + }, + { + "sheet": 2, + "start_row": 41, + "end_row": 43, + "struct": "IndustrySector", + "cols": [ + { + "col": "B", + "field": "IndustryCode", + "type": "string", + "split": " ", + "default": "Please choose" + }, + { + "col": "C", + "field": "Description", + "type": "string", + "default": "" + }, + { + "col": "D", + "field": "AmountOfTotalTurnover", + "type": "int", + "default": "0" + } + ] + } + ], + "rating": { + "sheet": 3, + "start_row": 9, + "end_row": 93, + "short_name_col": "B", + "cols": [ + { + "col": "I", + "field": "Points", + "type": "int", + "default": "" + }, + { + "col": "J", + "field": "MaxPoints", + "type": "float64", + "default": "" + }, + { + "col": "C", + "field": "Name", + "type": "int", + "default": "" + }, + { + "col": "H", + "field": "Estimations", + "type": "int", + "default": "" + }, + { + "col": "D", + "field": "Weight", + "type": "float64", + "default": "" + }, + { + "col": "N", + "field": "IsWeightSelectedByUser", + "type": "bool", + "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": [ { - "sheet": 2, - "cell": "C7", - "type": "int", - "struct": "CompanyFacts", - "field": "TotalPurchaseFromSuppliers", - "default": "" + "short_name": "1", + "name": "Human dignity", + "points_col": "C", + "percentage_reached_col": "F", + "max_points_col": "E" }, { - "sheet": 2, - "cell": "C27", - "type": "int", - "struct": "CompanyFacts", - "field": "TotalStaffCosts", - "default": "" + "short_name": "2", + "name": "Solidarity", + "points_col": "G", + "percentage_reached_col": "I", + "max_points_col": "J" }, { - "sheet": 2, - "cell": "C18", - "type": "int", - "struct": "CompanyFacts", - "field": "Profit", - "default": "" + "short_name": "3", + "name": "Environment sustainability", + "points_col": "K", + "percentage_reached_col": "M", + "max_points_col": "N" }, { - "sheet": 2, - "cell": "C19", - "type": "int", - "struct": "CompanyFacts", - "field": "FinancialCosts", - "default": "" - }, - { - "sheet": 2, - "cell": "C20", - "type": "int", - "struct": "CompanyFacts", - "field": "IncomeFromFinancialInvestments", - "default": "" - }, - { - "sheet": 2, - "cell": "C22", - "type": "int", - "struct": "CompanyFacts", - "field": "AdditionsToFixedAssets", - "default": "" - }, - { - "sheet": 2, - "cell": "C37", - "type": "int", - "struct": "CompanyFacts", - "field": "Turnover", - "default": "" - }, - { - "sheet": 2, - "cell": "C21", - "type": "int", - "struct": "CompanyFacts", - "field": "TotalAssets", - "default": "" - }, - { - "sheet": 2, - "cell": "C23", - "type": "int", - "struct": "CompanyFacts", - "field": "FinancialAssetsAndCashBalance", - "default": "" - }, - { - "sheet": 2, - "cell": "C26", - "type": "int", - "struct": "CompanyFacts", - "field": "NumberOfEmployees", - "default": "" - }, - { - "sheet": 2, - "cell": "C24", - "type": "bool", - "struct": "CompanyFacts", - "field": "HasCanteen", - "default": "" - }, - { - "sheet": 2, - "cell": "C38", - "type": "bool", - "struct": "CompanyFacts", - "field": "IsB2B", - "default": "" - }, - { - "sheet": 2, - "cell": "C33", - "type": "int", - "struct": "CompanyFacts", - "field": "AverageJourneyToWorkForStaffInKm", - "default": "" - } - ], - "areas": [ - { - "sheet": 2, - "start_row": 10, - "end_row": 14, - "struct": "SupplyFraction", - "cols": [ - { - "col": "B", - "field": "IndustryCode", - "type": "string", - "split": " ", - "default": "Please choose" - }, - { - "col": "D", - "field": "CountryCode", - "type": "string", - "split": " ", - "default": "Please choose" - }, - { - "col": "F", - "field": "Costs", - "type": "string", - "default": "0" - } - ] - }, - { - "sheet": 2, - "start_row": 30, - "end_row": 32, - "struct": "EmployeesFraction", - "cols": [ - { - "col": "B", - "field": "CountryCode", - "type": "string", - "split": " ", - "default": "Please choose" - }, - { - "col": "D", - "field": "Percentage", - "type": "float64", - "default": "0" - } - ] - }, - { - "sheet": 2, - "start_row": 41, - "end_row": 43, - "struct": "IndustrySector", - "cols": [ - { - "col": "B", - "field": "IndustryCode", - "type": "string", - "split": " ", - "default": "Please choose" - }, - { - "col": "C", - "field": "Description", - "type": "string", - "default": "" - }, - { - "col": "D", - "field": "AmountOfTotalTurnover", - "type": "int", - "default": "0" - } - ] - } - ], - "rating": { - "sheet": 3, - "start_row": 9, - "end_row": 93, - "short_name_col": "B", - "cols": [ - { - "col": "I", - "field": "Points", - "type": "int", - "default": "" - }, - { - "col": "J", - "field": "MaxPoints", - "type": "float64", - "default": "" - }, - { - "col": "C", - "field": "Name", - "type": "int", - "default": "" - }, - { - "col": "H", - "field": "Estimations", - "type": "int", - "default": "" - }, - { - "col": "D", - "field": "Weight", - "type": "float64", - "default": "" - }, - { - "col": "N", - "field": "IsWeightSelectedByUser", - "type": "bool", - "default": "" - } - ] + "short_name": "4", + "name": "Transparency", + "points_col": "O", + "percentage_reached_col": "Q", + "max_points_col": "R" } + + ] } - \ No newline at end of file +} \ No newline at end of file diff --git a/pkg/loader/loader.go b/pkg/loader/loader.go index a52dd57..02612aa 100644 --- a/pkg/loader/loader.go +++ b/pkg/loader/loader.go @@ -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 } diff --git a/pkg/loader/loader_test.go b/pkg/loader/loader_test.go index 3f1460f..5a231cf 100644 --- a/pkg/loader/loader_test.go +++ b/pkg/loader/loader_test.go @@ -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) + } diff --git a/pkg/loader/test/testfile.xlsx b/pkg/loader/test/testfile.xlsx index 2aca32c..e46b3ed 100644 Binary files a/pkg/loader/test/testfile.xlsx and b/pkg/loader/test/testfile.xlsx differ