Skip to content

Commit

Permalink
colocando na coluna "sumario"
Browse files Browse the repository at this point in the history
  • Loading branch information
joellensilva committed Nov 30, 2023
1 parent 7ec59ac commit 6019324
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
8 changes: 1 addition & 7 deletions models/monthlyInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ 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)
ItemSummary *ItemSummary `json:"item_summary,omitempty"` // Summary of aggregated values ​​by item
Duration float64 `json:"duration,omitempty"` // Crawling duration (seconds)
}

type Meta struct {
Expand Down Expand Up @@ -104,8 +103,3 @@ 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
}
6 changes: 6 additions & 0 deletions models/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Summary struct {
Discounts DataSummary `json:"descontos,omitempty"` // Statistics (Max, Min, Median, Total)
Remunerations DataSummary `json:"remuneracoes,omitempty"` // Statistics (Max, Min, Median, Total)
IncomeHistogram map[int]int `json:"histograma_renda,omitempty"`
ItemSummary ItemSummary `json:"resumo_rubricas,omitempty"` // resumo de valores agregadado por rubrica
}

// DataSummary A Struct containing data summary with statistics.
Expand All @@ -25,3 +26,8 @@ type DataSummary struct {
Average float64 `json:"media,omitempty"`
Total float64 `json:"total,omitempty"`
}

type ItemSummary struct {
FoodAllowance float64 `json:"auxilio_alimentacao,omitempty"`
Others float64 `json:"outras,omitempty"` // valor agregado de outras rubricas não identificadas
}
27 changes: 5 additions & 22 deletions repo/database/dto/monthlyInfoDTO.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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 @@ -63,7 +62,6 @@ 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 @@ -101,15 +99,6 @@ 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 @@ -137,12 +126,11 @@ 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,
ItemSummary: &itemSummary,
Summary: &summary,
Backups: []models.Backup{backup},
ProcInfo: &procInfo,
Package: &pkg,
Duration: a.Duration,
}, nil
}

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

Expand Down
1 change: 0 additions & 1 deletion repo/database/init_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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 6019324

Please sign in to comment.