Skip to content

Commit

Permalink
adicionando a coluna 'resumo' (de rubricas)
Browse files Browse the repository at this point in the history
  • Loading branch information
joellensilva committed Nov 30, 2023
1 parent 7063d34 commit 7ec59ac
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
8 changes: 7 additions & 1 deletion models/monthlyInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
28 changes: 23 additions & 5 deletions repo/database/dto/monthlyInfoDTO.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand All @@ -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{
Expand Down Expand Up @@ -208,6 +225,7 @@ func NewAgencyMonthlyInfoDTO(agmi models.AgencyMonthlyInfo) (*AgencyMonthlyInfoD
ProcInfo: procInfo,
Package: pkg,
Duration: agmi.Duration,
ItemSummary: itemSummary,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions repo/database/init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ec59ac

Please sign in to comment.