Skip to content

Commit

Permalink
Merge pull request #559 from dadosjusbr/retornando-remuneracoes
Browse files Browse the repository at this point in the history
retornando remunerações
  • Loading branch information
joellensilva committed Jun 27, 2023
2 parents 6bb7bef + 94cff36 commit d8f9dc9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/dadosjusbr/proto v0.0.0-20221212025627-91c60aa3cd12
github.com/dadosjusbr/storage v0.0.0-20230606144319-60c7b5d6eb77
github.com/dadosjusbr/storage v0.0.0-20230627121230-1ddd9005aa6a
github.com/gocarina/gocsv v0.0.0-20220712153207-8b2118da4570
github.com/golang/mock v1.6.0
github.com/joho/godotenv v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ github.com/dadosjusbr/storage v0.0.0-20230516114123-dc6ae51c4bb1 h1:cW0gM/0LR2Zt
github.com/dadosjusbr/storage v0.0.0-20230516114123-dc6ae51c4bb1/go.mod h1:ttc45wBL5bjz5uU24mgNNPV9ZHaJ3SmoRwVOmyVRZyY=
github.com/dadosjusbr/storage v0.0.0-20230606144319-60c7b5d6eb77 h1:/nTEm9H8P5IUzDTuQkwFod/BoruZIObWr7sUO07Kov4=
github.com/dadosjusbr/storage v0.0.0-20230606144319-60c7b5d6eb77/go.mod h1:ttc45wBL5bjz5uU24mgNNPV9ZHaJ3SmoRwVOmyVRZyY=
github.com/dadosjusbr/storage v0.0.0-20230627121230-1ddd9005aa6a h1:ib73I62iV04yCl7jvlLCskFiMnCMrsrNptrWcgl81Jw=
github.com/dadosjusbr/storage v0.0.0-20230627121230-1ddd9005aa6a/go.mod h1:ttc45wBL5bjz5uU24mgNNPV9ZHaJ3SmoRwVOmyVRZyY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
24 changes: 24 additions & 0 deletions papi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ func (h handler) GetMonthlyInfo(c echo.Context) error {
Average: mi.Summary.Discounts.Average,
Total: mi.Summary.Discounts.Total,
},
Remunerations: dataSummary{
Max: mi.Summary.Remunerations.Max,
Min: mi.Summary.Remunerations.Min,
Average: mi.Summary.Remunerations.Average,
Total: mi.Summary.Remunerations.Total,
},
},
},
Metadata: &metadata{
Expand Down Expand Up @@ -318,6 +324,12 @@ func (h handler) V2GetMonthlyInfo(c echo.Context) error {
Average: monthlyInfo.Summary.Discounts.Average,
Total: monthlyInfo.Summary.Discounts.Total,
},
Remunerations: dataSummary{
Max: monthlyInfo.Summary.Remunerations.Max,
Min: monthlyInfo.Summary.Remunerations.Min,
Average: monthlyInfo.Summary.Remunerations.Average,
Total: monthlyInfo.Summary.Remunerations.Total,
},
},
},
Metadata: &metadata{
Expand Down Expand Up @@ -432,6 +444,12 @@ func (h handler) GetMonthlyInfosByYear(c echo.Context) error {
Average: mi.Summary.Discounts.Average,
Total: mi.Summary.Discounts.Total,
},
Remunerations: dataSummary{
Max: mi.Summary.Remunerations.Max,
Min: mi.Summary.Remunerations.Min,
Average: mi.Summary.Remunerations.Average,
Total: mi.Summary.Remunerations.Total,
},
},
},
Metadata: &metadata{
Expand Down Expand Up @@ -691,6 +709,12 @@ func (h handler) V2GetAllAgencyInformation(c echo.Context) error {
Average: c.Summary.Discounts.Average,
Total: c.Summary.Discounts.Total,
},
Remunerations: dataSummary{
Max: c.Summary.Remunerations.Max,
Min: c.Summary.Remunerations.Min,
Average: c.Summary.Remunerations.Average,
Total: c.Summary.Remunerations.Total,
},
},
},
Metadata: &metadata{
Expand Down
1 change: 1 addition & 0 deletions papi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type summary struct {
BaseRemuneration dataSummary `json:"remuneracao_base,omitempty"`
OtherRemunerations dataSummary `json:"outras_remuneracoes,omitempty"`
Discounts dataSummary `json:"descontos,omitempty"`
Remunerations dataSummary `json:"remuneracoes,omitempty"`
}

type summaries struct {
Expand Down
20 changes: 14 additions & 6 deletions uiapi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ func (h handler) V2GetSummaryOfAgency(c echo.Context) error {
MaxOther: agencyMonthlyInfo.Summary.OtherRemunerations.Max,
Discounts: agencyMonthlyInfo.Summary.Discounts.Total,
MaxDiscounts: agencyMonthlyInfo.Summary.Discounts.Max,
TotalRemuneration: agencyMonthlyInfo.Summary.BaseRemuneration.Total +
agencyMonthlyInfo.Summary.OtherRemunerations.Total,
TotalMembers: agencyMonthlyInfo.Summary.Count,
MaxRemuneration: agencyMonthlyInfo.Summary.Remunerations.Max,
TotalRemuneration: agencyMonthlyInfo.Summary.Remunerations.Total,
TotalMembers: agencyMonthlyInfo.Summary.Count,
CrawlingTime: timestamp{
Seconds: agencyMonthlyInfo.CrawlingTimestamp.GetSeconds(),
Nanos: agencyMonthlyInfo.CrawlingTimestamp.GetNanos(),
Expand Down Expand Up @@ -220,9 +220,9 @@ func (h handler) V2GetSalaryOfAgencyMonthYear(c echo.Context) error {
},
})
}
return c.JSON(http.StatusOK, agencySalary{
MaxSalary: agencyMonthlyInfo.Summary.BaseRemuneration.Max,
Histogram: agencyMonthlyInfo.Summary.IncomeHistogram,
return c.JSON(http.StatusOK, agencyRemuneration{
MaxRemuneration: agencyMonthlyInfo.Summary.Remunerations.Max,
Histogram: agencyMonthlyInfo.Summary.IncomeHistogram,
Package: &backup{
URL: agencyMonthlyInfo.Package.URL,
Hash: agencyMonthlyInfo.Package.Hash,
Expand Down Expand Up @@ -323,9 +323,11 @@ func (h handler) V2GetTotalsOfAgencyYear(c echo.Context) error {
monthTotals := v2MonthTotals{Month: agencyMonthlyInfo.Month,
BaseRemuneration: agencyMonthlyInfo.Summary.BaseRemuneration.Total,
OtherRemunerations: agencyMonthlyInfo.Summary.OtherRemunerations.Total,
Remunerations: agencyMonthlyInfo.Summary.Remunerations.Total,
Discounts: agencyMonthlyInfo.Summary.Discounts.Total,
BaseRemunerationPerCapita: agencyMonthlyInfo.Summary.BaseRemuneration.Average,
OtherRemunerationsPerCapita: agencyMonthlyInfo.Summary.OtherRemunerations.Average,
RemunerationsPerCapita: agencyMonthlyInfo.Summary.Remunerations.Average,
DiscountsPerCapita: agencyMonthlyInfo.Summary.Discounts.Average,
CrawlingTimestamp: timestamp{
Seconds: agencyMonthlyInfo.CrawlingTimestamp.GetSeconds(),
Expand Down Expand Up @@ -583,6 +585,7 @@ func (h handler) V2GetGeneralRemunerationFromYear(c echo.Context) error {
BaseRemuneration: d.BaseRemuneration,
OtherRemunerations: d.OtherRemunerations,
Discounts: d.Discounts,
Remunerations: d.Remunerations,
})
}
return c.JSON(http.StatusOK, annualRemu)
Expand Down Expand Up @@ -790,6 +793,8 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
baseRemPerCapita := s.BaseRemuneration / float64(s.TotalCount)
otherRemPerMonth := s.OtherRemunerations / float64(s.NumMonthsWithData)
otherRemPerCapita := s.OtherRemunerations / float64(s.TotalCount)
remPerMonth := s.Remunerations / float64(s.NumMonthsWithData)
remPerCapita := s.Remunerations / float64(s.TotalCount)
discountsRemPerMonth := s.Discounts / float64(s.NumMonthsWithData)
discountsRemPerCapita := s.Discounts / float64(s.TotalCount)
annualData = append(annualData, annualSummaryData{
Expand All @@ -804,6 +809,9 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
Discounts: s.Discounts,
DiscountsPerMonth: discountsRemPerMonth,
DiscountsPerCapita: discountsRemPerCapita,
Remunerations: s.Remunerations,
RemunerationsPerMonth: remPerMonth,
RemunerationsPerCapita: remPerCapita,
NumMonthsWithData: s.NumMonthsWithData,
Package: &backup{
URL: s.Package.URL,
Expand Down
17 changes: 13 additions & 4 deletions uiapi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type dataForChartAtAgencyScreen struct {
PackageSize int64
}

type agencySalary struct {
MaxSalary float64 `json:"max_salario"`
Histogram map[int]int `json:"histograma"`
Package *backup `json:"package"`
type agencyRemuneration struct {
MaxRemuneration float64 `json:"max_salario"`
Histogram map[int]int `json:"histograma"`
Package *backup `json:"package"`
}

// generalTotals - contains the summary from all DadosJusBr data
Expand Down Expand Up @@ -105,6 +105,7 @@ type v2AgencySummary struct {
MaxOther float64 `json:"max_outras_remuneracoes"`
Discounts float64 `json:"descontos"`
MaxDiscounts float64 `json:"max_descontos"`
MaxRemuneration float64 `json:"max_remuneracao"`
CrawlingTime timestamp `json:"timestamp"`
TotalMembers int `json:"total_membros"`
TotalRemuneration float64 `json:"total_remuneracao"`
Expand Down Expand Up @@ -146,6 +147,8 @@ type monthTotals struct {
TotalMembers int
BaseRemuneration float64
OtherRemunerations float64
Discounts float64
Remunerations float64
CrawlingTimestamp *timestamppb.Timestamp
}

Expand All @@ -159,6 +162,8 @@ type v2MonthTotals struct {
OtherRemunerationsPerCapita float64 `json:"outras_remuneracoes_por_membro"`
Discounts float64 `json:"descontos"`
DiscountsPerCapita float64 `json:"descontos_por_membro"`
Remunerations float64 `json:"remuneracoes"`
RemunerationsPerCapita float64 `json:"remuneracoes_por_membro"`
CrawlingTimestamp timestamp `json:"timestamp"`
}

Expand Down Expand Up @@ -257,6 +262,9 @@ type annualSummaryData struct {
Discounts float64 `json:"descontos"`
DiscountsPerMonth float64 `json:"descontos_por_mes"`
DiscountsPerCapita float64 `json:"descontos_por_membro"`
Remunerations float64 `json:"remuneracoes"`
RemunerationsPerMonth float64 `json:"remuneracoes_por_mes"`
RemunerationsPerCapita float64 `json:"remuneracoes_por_membro"`
NumMonthsWithData int `json:"meses_com_dados"`
Package *backup `json:"package,omitempty"`
}
Expand All @@ -267,4 +275,5 @@ type mensalRemuneration struct {
BaseRemuneration float64 `json:"remuneracao_base"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
Discounts float64 `json:"descontos"`
Remunerations float64 `json:"remuneracoes"`
}
23 changes: 20 additions & 3 deletions uiapi/uiapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (g getSummaryOfAgency) testWhenDataExists(t *testing.T) {
{
"orgao": "Tribunal de Justiça do Estado de Alagoas",
"remuneracao_base": 7.099024400000013e+06,
"max_remuneracao": 35462.22,
"max_remuneracao_base": 35462.22,
"outras_remuneracoes": 1.9515865600000022e+06,
"max_outras_remuneracoes": 45200.05,
Expand All @@ -95,7 +96,7 @@ func (g getSummaryOfAgency) testWhenDataExists(t *testing.T) {
"nanos": 1
},
"total_membros": 214,
"total_remuneracao": 9.050610960000016e+06,
"total_remuneracao": 7.099024400000013e+06,
"tem_proximo": true,
"tem_anterior": true
}
Expand Down Expand Up @@ -947,13 +948,15 @@ func (g getGenerealRemunerationFromYear) testWhenDataExists(t *testing.T) {
BaseRemuneration: 10000,
OtherRemunerations: 1000,
Discounts: 1000,
Remunerations: 10000,
},
{
Month: 2,
Count: 200,
BaseRemuneration: 20000,
OtherRemunerations: 2000,
Discounts: 1000,
Remunerations: 21000,
},
}
dbMock.EXPECT().Connect().Return(nil).Times(1)
Expand Down Expand Up @@ -985,14 +988,16 @@ func (g getGenerealRemunerationFromYear) testWhenDataExists(t *testing.T) {
"num_membros": 100,
"remuneracao_base": 10000,
"outras_remuneracoes": 1000,
"descontos": 1000
"descontos": 1000,
"remuneracoes": 10000
},
{
"mes": 2,
"num_membros": 200,
"remuneracao_base": 20000,
"outras_remuneracoes": 2000,
"descontos": 1000
"descontos": 1000,
"remuneracoes": 21000
}
]
`
Expand Down Expand Up @@ -1138,6 +1143,8 @@ func (g getTotalsOfAgencyYear) testWhenDataExists(t *testing.T) {
"remuneracao_base_por_membro":33173.01121495333,
"descontos": 2221879.66,
"descontos_por_membro": 10382.615233644861,
"remuneracoes": 7.099024400000013e+06,
"remuneracoes_por_membro": 33173.01121495333,
"timestamp": {
"seconds": 1,
"nanos": 1
Expand Down Expand Up @@ -1279,6 +1286,7 @@ func (g getAnnualSummary) testWhenDataExists(t *testing.T) {
BaseRemuneration: 10000,
OtherRemunerations: 1000,
Discounts: 1000,
Remunerations: 10000,
NumMonthsWithData: 12,
Package: &models.Backup{
URL: "https://dadosjusbr.org/download/tjal/datapackage/tjal-2020-1.zip",
Expand Down Expand Up @@ -1336,6 +1344,9 @@ func (g getAnnualSummary) testWhenDataExists(t *testing.T) {
"descontos": 1000,
"descontos_por_membro": 0.3894080996884735,
"descontos_por_mes": 83.33333333333333,
"remuneracoes": 10000,
"remuneracoes_por_membro": 3.8940809968847354,
"remuneracoes_por_mes": 833.3333333333334,
"meses_com_dados": 12,
"package": {
"url": "https://dadosjusbr.org/download/tjal/datapackage/tjal-2020-1.zip",
Expand Down Expand Up @@ -1509,6 +1520,12 @@ func agencyMonthlyInfos() []models.AgencyMonthlyInfo {
Average: 10382.615233644861,
Total: 2221879.66,
},
Remunerations: models.DataSummary{
Max: 35462.22,
Min: 7473.09,
Average: 33173.01121495333,
Total: 7099024.400000013,
},
IncomeHistogram: map[int]int{
-1: 0,
10000: 1,
Expand Down

0 comments on commit d8f9dc9

Please sign in to comment.