#1 all ratings are maped
This commit is contained in:
3145
cmd/conv/eCalc.json
Normal file
3145
cmd/conv/eCalc.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -19,5 +19,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer xf.Close()
|
defer xf.Close()
|
||||||
eBalance, err := loader.XLSX(xf, nil)
|
eBalance, err := loader.XLSX(xf, nil)
|
||||||
fmt.Printf("%s\n%#v", err, eBalance.CompanyFacts.IndustrySectors)
|
//fmt.Printf("%s\n%#v", err, eBalance.CompanyFacts.Rating.Topics[1])
|
||||||
|
|
||||||
|
out, err := os.OpenFile("eCalc.json", os.O_CREATE, 0777)
|
||||||
|
fmt.Println("createFileErr:", err)
|
||||||
|
eBalance.EncodeJSON(out)
|
||||||
|
out.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,78 +1,90 @@
|
|||||||
package ecalc
|
package ecalc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
type Ecalc struct {
|
type Ecalc struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version"`
|
||||||
CompanyFacts CompanyFacts `json:"companyFacts,omitempty"`
|
CompanyFacts CompanyFacts `json:"companyFacts"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EncodeJSON writes the JSON of the conf into the Writer
|
||||||
|
func (e Ecalc) EncodeJSON(w io.Writer) error {
|
||||||
|
enc := json.NewEncoder(w)
|
||||||
|
enc.SetIndent("", " ")
|
||||||
|
return enc.Encode(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompanyFacts struct {
|
type CompanyFacts struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
TotalPurchaseFromSuppliers int `json:"totalPurchaseFromSuppliers,omitempty"`
|
TotalPurchaseFromSuppliers int `json:"totalPurchaseFromSuppliers"`
|
||||||
TotalStaffCosts int `json:"totalStaffCosts,omitempty"`
|
TotalStaffCosts int `json:"totalStaffCosts"`
|
||||||
Profit int `json:"profit,omitempty"`
|
Profit int `json:"profit"`
|
||||||
FinancialCosts int `json:"financialCosts,omitempty"`
|
FinancialCosts int `json:"financialCosts"`
|
||||||
IncomeFromFinancialInvestments int `json:"incomeFromFinancialInvestments,omitempty"`
|
IncomeFromFinancialInvestments int `json:"incomeFromFinancialInvestments"`
|
||||||
AdditionsToFixedAssets int `json:"additionsToFixedAssets,omitempty"`
|
AdditionsToFixedAssets int `json:"additionsToFixedAssets"`
|
||||||
Turnover int `json:"turnover,omitempty"`
|
Turnover int `json:"turnover"`
|
||||||
TotalAssets int `json:"totalAssets,omitempty"`
|
TotalAssets int `json:"totalAssets"`
|
||||||
FinancialAssetsAndCashBalance int `json:"financialAssetsAndCashBalance,omitempty"`
|
FinancialAssetsAndCashBalance int `json:"financialAssetsAndCashBalance"`
|
||||||
SupplyFractions []SupplyFraction `json:"supplyFractions,omitempty"`
|
SupplyFractions []SupplyFraction `json:"supplyFractions"`
|
||||||
EmployeesFractions []EmployeesFraction `json:"employeesFractions,omitempty"`
|
EmployeesFractions []EmployeesFraction `json:"employeesFractions"`
|
||||||
IndustrySectors []IndustrySector `json:"industrySectors,omitempty"`
|
IndustrySectors []IndustrySector `json:"industrySectors"`
|
||||||
NumberOfEmployees int `json:"numberOfEmployees,omitempty"`
|
NumberOfEmployees int `json:"numberOfEmployees"`
|
||||||
HasCanteen bool `json:"hasCanteen,omitempty"`
|
HasCanteen bool `json:"hasCanteen"`
|
||||||
IsB2B bool `json:"isB2B,omitempty"`
|
IsB2B bool `json:"isB2B"`
|
||||||
AverageJourneyToWorkForStaffInKm float64 `json:"averageJourneyToWorkForStaffInKm,omitempty"`
|
AverageJourneyToWorkForStaffInKm float64 `json:"averageJourneyToWorkForStaffInKm"`
|
||||||
Rating Rating `json:"rating,omitempty"`
|
Rating Rating `json:"rating"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SupplyFraction struct {
|
type SupplyFraction struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
IndustryCode string `json:"industryCode,omitempty"`
|
IndustryCode string `json:"industryCode"`
|
||||||
CountryCode string `json:"countryCode,omitempty"`
|
CountryCode string `json:"countryCode"`
|
||||||
Costs int `json:"costs,omitempty"`
|
Costs int `json:"costs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type EmployeesFraction struct {
|
type EmployeesFraction struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
CountryCode string `json:"countryCode,omitempty"`
|
CountryCode string `json:"countryCode"`
|
||||||
Percentage float64 `json:"percentage,omitempty"`
|
Percentage float64 `json:"percentage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IndustrySector struct {
|
type IndustrySector struct {
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
IndustryCode string `json:"industryCode,omitempty"`
|
IndustryCode string `json:"industryCode"`
|
||||||
AmountOfTotalTurnover int `json:"amountOfTotalTurnover,omitempty"`
|
AmountOfTotalTurnover int `json:"amountOfTotalTurnover"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Rating struct {
|
type Rating struct {
|
||||||
Topics []Topic `json:"topics,omitempty"`
|
Topics []Topic `json:"topics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Topic struct {
|
type Topic struct {
|
||||||
Points int `json:"points,omitempty"`
|
Points int `json:"points"`
|
||||||
MaxPoints float64 `json:"maxPoints,omitempty"`
|
MaxPoints float64 `json:"maxPoints"`
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
ShortName string `json:"shortName,omitempty"`
|
ShortName string `json:"shortName"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name"`
|
||||||
Estimations int `json:"estimations,omitempty"`
|
Estimations int `json:"estimations"`
|
||||||
Weight float64 `json:"weight,omitempty"`
|
Weight float64 `json:"weight"`
|
||||||
IsWeightSelectedByUser bool `json:"isWeightSelectedByUser,omitempty"`
|
IsWeightSelectedByUser bool `json:"isWeightSelectedByUser"`
|
||||||
Aspects []Aspect `json:"aspects,omitempty"`
|
Aspects []Aspect `json:"aspects"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Aspect struct {
|
type Aspect struct {
|
||||||
Points int `json:"points,omitempty"`
|
Points int `json:"points"`
|
||||||
MaxPoints float64 `json:"maxPoints,omitempty"`
|
MaxPoints float64 `json:"maxPoints"`
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
ShortName string `json:"shortName,omitempty"`
|
ShortName string `json:"shortName"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name"`
|
||||||
Estimations int `json:"estimations,omitempty"`
|
Estimations int `json:"estimations"`
|
||||||
Weight float64 `json:"weight,omitempty"`
|
Weight float64 `json:"weight"`
|
||||||
IsWeightSelectedByUser bool `json:"isWeightSelectedByUser,omitempty"`
|
IsWeightSelectedByUser bool `json:"isWeightSelectedByUser"`
|
||||||
Aspects []Aspect `json:"aspects,omitempty"`
|
Aspects []Aspect `json:"aspects"`
|
||||||
IsPositive bool `json:"isPositive,omitempty"`
|
IsPositive bool `json:"isPositive"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ type Rating struct {
|
|||||||
Sheet int `json:"sheet"`
|
Sheet int `json:"sheet"`
|
||||||
StartRow int `json:"start_row"`
|
StartRow int `json:"start_row"`
|
||||||
EndRow int `json:"end_row"`
|
EndRow int `json:"end_row"`
|
||||||
|
Cols []RatingCol `json:"cols"`
|
||||||
PointsCol string `json:"points_col"`
|
PointsCol string `json:"points_col"`
|
||||||
MaxPointsCol string `json:"max_points_col"`
|
MaxPointsCol string `json:"max_points_col"`
|
||||||
IDCol string `json:"id_col"`
|
IDCol string `json:"id_col"`
|
||||||
@@ -93,3 +94,10 @@ type Rating struct {
|
|||||||
WeightCol string `json:"weight_col"`
|
WeightCol string `json:"weight_col"`
|
||||||
SelectedByUserCol string `json:"selected_by_user_col"`
|
SelectedByUserCol string `json:"selected_by_user_col"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RatingCol struct {
|
||||||
|
Col string `json:"col"`
|
||||||
|
Field string `json:"field"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Default string `json:"default"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -185,14 +185,45 @@
|
|||||||
"sheet": 3,
|
"sheet": 3,
|
||||||
"start_row": 9,
|
"start_row": 9,
|
||||||
"end_row": 93,
|
"end_row": 93,
|
||||||
"points_col": "I",
|
|
||||||
"max_points_col": "J",
|
|
||||||
"id_col": "",
|
|
||||||
"short_name_col": "B",
|
"short_name_col": "B",
|
||||||
"name_col": "C",
|
"cols": [
|
||||||
"estimations_col": "H",
|
{
|
||||||
"weight_col": "D",
|
"col": "I",
|
||||||
"selected_by_user_col": "N"
|
"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": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +94,52 @@ func XLSX(r io.Reader, conf *Conf) (*ecalc.Ecalc, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
var topic ecalc.Topic
|
||||||
|
for r := conf.Rating.StartRow; r <= conf.Rating.EndRow; r++ {
|
||||||
|
shortName, err := xFile.GetCellValue(
|
||||||
|
xFile.GetSheetName(conf.Rating.Sheet),
|
||||||
|
fmt.Sprintf("%s%d", conf.Rating.ShortNameCol, r),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
if len(shortName) < 2 {
|
||||||
|
continue
|
||||||
|
} else if len(shortName) == 2 {
|
||||||
|
if topic.ShortName != "" {
|
||||||
|
eBalance.CompanyFacts.Rating.Topics = append(eBalance.CompanyFacts.Rating.Topics, topic)
|
||||||
|
}
|
||||||
|
topic = ecalc.Topic{
|
||||||
|
ShortName: shortName,
|
||||||
|
}
|
||||||
|
for _, c := range conf.Rating.Cols {
|
||||||
|
cellValue, err := xFile.GetCellValue(
|
||||||
|
xFile.GetSheetName(conf.Rating.Sheet),
|
||||||
|
fmt.Sprintf("%s%d", c.Col, r),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
set.Field(&topic, c.Field, cellValue)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
aspect := ecalc.Aspect{
|
||||||
|
ShortName: shortName,
|
||||||
|
}
|
||||||
|
for _, c := range conf.Rating.Cols {
|
||||||
|
cellValue, err := xFile.GetCellValue(
|
||||||
|
xFile.GetSheetName(conf.Rating.Sheet),
|
||||||
|
fmt.Sprintf("%s%d", c.Col, r),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
set.Field(&aspect, c.Field, cellValue)
|
||||||
|
}
|
||||||
|
topic.Aspects = append(topic.Aspects, aspect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eBalance.CompanyFacts.Rating.Topics = append(eBalance.CompanyFacts.Rating.Topics, topic)
|
||||||
// TODO: error handling of errs
|
// TODO: error handling of errs
|
||||||
return eBalance, nil
|
return eBalance, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user