From 7ec59ac173708ec748c140087b527163bd42d312 Mon Sep 17 00:00:00 2001 From: Joellensilva Date: Thu, 30 Nov 2023 14:54:37 -0300 Subject: [PATCH] adicionando a coluna 'resumo' (de rubricas) --- go.mod | 1 - go.sum | 4 ---- models/monthlyInfo.go | 8 +++++++- repo/database/dto/monthlyInfoDTO.go | 28 +++++++++++++++++++++++----- repo/database/init_db.sql | 1 + 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index c41b10d..567ce13 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/golang/mock v1.6.0 github.com/google/go-cmp v0.5.8 // indirect github.com/joho/godotenv v1.4.0 - github.com/joho/sqltocsv v0.0.0-20210428211105-a6d6801d59df github.com/kelseyhightower/envconfig v1.4.0 github.com/lib/pq v1.10.2 github.com/newrelic/go-agent/v3 v3.19.2 diff --git a/go.sum b/go.sum index ef565fc..36c95d0 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,6 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/dadosjusbr/datapackage v0.0.0-20230818123816-40ae9a2f981f h1:d0z2q3Mr+Fe11svtLcy8T0xZUPDnit54oR4EhTUqBys= -github.com/dadosjusbr/datapackage v0.0.0-20230818123816-40ae9a2f981f/go.mod h1:o1FghJC46mR+lgHcQWVve/q84/SAd0WVdYMcgq88BBU= github.com/dadosjusbr/datapackage v0.0.0-20230904162108-6e2264aafb68 h1:DLea5zdEkGQkhwALQl2b+cpld7rVHZgeXKv+SXQ1/6o= github.com/dadosjusbr/datapackage v0.0.0-20230904162108-6e2264aafb68/go.mod h1:o1FghJC46mR+lgHcQWVve/q84/SAd0WVdYMcgq88BBU= github.com/dadosjusbr/proto v0.0.0-20221212025627-91c60aa3cd12 h1:ufl8nbCEo6g2VHUbedGy0gYk9Sgrynf9rcnzuSw4TEg= @@ -156,8 +154,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/joho/sqltocsv v0.0.0-20210428211105-a6d6801d59df h1:Zrb0IbuLOGHL7nrO2WrcuNWgDTlzFv3zY69QMx4ggQE= -github.com/joho/sqltocsv v0.0.0-20210428211105-a6d6801d59df/go.mod h1:mAVCUAYtW9NG31eB30umMSLKcDt6mCUWSjoSn5qBh0k= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= diff --git a/models/monthlyInfo.go b/models/monthlyInfo.go index 39b620e..3f72ecd 100644 --- a/models/monthlyInfo.go +++ b/models/monthlyInfo.go @@ -35,7 +35,8 @@ type AgencyMonthlyInfo struct { Package *Backup `json:"package,omitempty"` // Making this a pointer because it should be an optional field due to backwards compatibility. Meta *Meta `json:"meta,omitempty"` Score *Score `json:"score,omitempty"` - Duration float64 `json:"duration,omitempty"` // Crawling duration (seconds) + Duration float64 `json:"duration,omitempty"` // Crawling duration (seconds) + ItemSummary *ItemSummary `json:"item_summary,omitempty"` // Summary of aggregated values ​​by item } type Meta struct { @@ -103,3 +104,8 @@ type Remunerations struct { NumOther int `json:"num_outras,omitempty"` ZipUrl string `json:"zip_url,omitempty"` } + +type ItemSummary struct { + FoodAllowance float64 `json:"auxilio-alimentacao,omitempty"` + Others float64 `json:"outras,omitempty"` // valor agregado de outras rubricas não identificadas +} diff --git a/repo/database/dto/monthlyInfoDTO.go b/repo/database/dto/monthlyInfoDTO.go index b799fc5..86e52ad 100644 --- a/repo/database/dto/monthlyInfoDTO.go +++ b/repo/database/dto/monthlyInfoDTO.go @@ -31,6 +31,7 @@ type AgencyMonthlyInfoDTO struct { Duration float64 `gorm:"column:duracao_segundos"` // Tempo de execução da coleta em segundos Meta Score + ItemSummary datatypes.JSON `gorm:"column:resumo"` // Resumo de valores agregados por item/rubrica } func (AgencyMonthlyInfoDTO) TableName() string { @@ -62,6 +63,7 @@ func (a AgencyMonthlyInfoDTO) ConvertToModel() (*models.AgencyMonthlyInfo, error var summary models.Summary var procInfo coleta.ProcInfo var pkg models.Backup + var itemSummary models.ItemSummary backupBytes, err := a.Backup.MarshalJSON() if err != nil { @@ -99,6 +101,15 @@ func (a AgencyMonthlyInfoDTO) ConvertToModel() (*models.AgencyMonthlyInfo, error return nil, fmt.Errorf("error while unmarshaling package: %q", err) } + itemSummaryBytes, err := a.ItemSummary.MarshalJSON() + if err != nil { + return nil, fmt.Errorf("error while marshaling item summary: %q", err) + } + err = json.Unmarshal(itemSummaryBytes, &itemSummary) + if err != nil { + return nil, fmt.Errorf("error while unmarshaling item summary: %q", err) + } + return &models.AgencyMonthlyInfo{ AgencyID: a.AgencyID, Month: a.Month, @@ -126,11 +137,12 @@ func (a AgencyMonthlyInfoDTO) ConvertToModel() (*models.AgencyMonthlyInfo, error BaseRevenue: a.Meta.BaseRevenue, OtherRecipes: a.Meta.OtherRecipes, }, - Summary: &summary, - Backups: []models.Backup{backup}, - ProcInfo: &procInfo, - Package: &pkg, - Duration: a.Duration, + Summary: &summary, + Backups: []models.Backup{backup}, + ProcInfo: &procInfo, + Package: &pkg, + Duration: a.Duration, + ItemSummary: &itemSummary, }, nil } @@ -155,6 +167,11 @@ func NewAgencyMonthlyInfoDTO(agmi models.AgencyMonthlyInfo) (*AgencyMonthlyInfoD if err != nil { return nil, fmt.Errorf("error while marshaling package: %q", err) } + itemSummary, err := json.Marshal(agmi.ItemSummary) + if err != nil { + return nil, fmt.Errorf("error while marshaling summary: %q", err) + } + var score Score if agmi.Score != nil { score = Score{ @@ -208,6 +225,7 @@ func NewAgencyMonthlyInfoDTO(agmi models.AgencyMonthlyInfo) (*AgencyMonthlyInfoD ProcInfo: procInfo, Package: pkg, Duration: agmi.Duration, + ItemSummary: itemSummary, }, nil } diff --git a/repo/database/init_db.sql b/repo/database/init_db.sql index e9acba0..e061b5b 100644 --- a/repo/database/init_db.sql +++ b/repo/database/init_db.sql @@ -43,6 +43,7 @@ create table coletas backups json, formato_aberto boolean, duracao_segundos double precision, + resumo json, constraint coleta_pk primary key (id,timestamp), constraint coleta_orgao_fk foreign key (id_orgao) references orgaos(id) on delete cascade