Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retornando média por membro #582

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,23 @@ const docTemplate = `{
}
}
},
"uiapi.perCapitaData": {
"type": "object",
"properties": {
"descontos": {
"type": "number"
},
"outras_remuneracoes": {
"type": "number"
},
"remuneracao_base": {
"type": "number"
},
"remuneracoes": {
"type": "number"
}
}
},
"uiapi.procError": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1637,6 +1654,9 @@ const docTemplate = `{
"ano": {
"type": "integer"
},
"media_por_membro": {
"$ref": "#/definitions/uiapi.perCapitaData"
},
"meses": {
"type": "array",
"items": {
Expand Down
20 changes: 20 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,23 @@
}
}
},
"uiapi.perCapitaData": {
"type": "object",
"properties": {
"descontos": {
"type": "number"
},
"outras_remuneracoes": {
"type": "number"
},
"remuneracao_base": {
"type": "number"
},
"remuneracoes": {
"type": "number"
}
}
},
"uiapi.procError": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1628,6 +1645,9 @@
"ano": {
"type": "integer"
},
"media_por_membro": {
"$ref": "#/definitions/uiapi.perCapitaData"
},
"meses": {
"type": "array",
"items": {
Expand Down
13 changes: 13 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,17 @@ definitions:
resumo_rubricas:
$ref: '#/definitions/uiapi.itemSummary'
type: object
uiapi.perCapitaData:
properties:
descontos:
type: number
outras_remuneracoes:
type: number
remuneracao_base:
type: number
remuneracoes:
type: number
type: object
uiapi.procError:
properties:
stderr:
Expand Down Expand Up @@ -580,6 +591,8 @@ definitions:
properties:
ano:
type: integer
media_por_membro:
$ref: '#/definitions/uiapi.perCapitaData'
meses:
items:
$ref: '#/definitions/uiapi.v2MonthTotals'
Expand Down
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-20240514131514-43ac5da3ae8a
github.com/dadosjusbr/storage v0.0.0-20240913213102-72765cc03b4e
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 @@ -39,6 +39,8 @@ github.com/dadosjusbr/storage v0.0.0-20240315221019-5da10c81ab80 h1:mo6k/MAl6aF6
github.com/dadosjusbr/storage v0.0.0-20240315221019-5da10c81ab80/go.mod h1:PszGy6CDoG3kNLjIsCmwD3MAWED7xL7U/OWj7ajsiHc=
github.com/dadosjusbr/storage v0.0.0-20240514131514-43ac5da3ae8a h1:1LyzfsNzKgLjC4/cyQr+N724a4dcRCHB5yIauAnhhcI=
github.com/dadosjusbr/storage v0.0.0-20240514131514-43ac5da3ae8a/go.mod h1:rIM/dbZMdrMfVnZgNgRNRRtsxfhSMH8S8X7MZEeKkrQ=
github.com/dadosjusbr/storage v0.0.0-20240913213102-72765cc03b4e h1:RNcbmof3iPyJQNWbEPkNyKKffmQ8jkZa8QH/vZ5eJP0=
github.com/dadosjusbr/storage v0.0.0-20240913213102-72765cc03b4e/go.mod h1:rIM/dbZMdrMfVnZgNgRNRRtsxfhSMH8S8X7MZEeKkrQ=
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
2 changes: 1 addition & 1 deletion papi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ func (h handler) V2GetAggregateIndexesWithParams(c echo.Context) error {
// @Produce json
// @Success 200 {object} []aggregateIndexesByGroup "Requisição bem sucedida."
// @Failure 500 {string} string "Erro interno do servidor."
// @Router /v2/indice [get]
// @Router /v2/indice [get]
func (h handler) V2GetAggregateIndexes(c echo.Context) error {
agregado := c.QueryParam("agregado")
detalhe := c.QueryParam("detalhe")
Expand Down
19 changes: 15 additions & 4 deletions uiapi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ func (h handler) V2GetTotalsOfAgencyYear(c echo.Context) error {
log.Printf("[totals of agency year] error getting data for first screen(estado:%s):%q", aID, err)
return c.JSON(http.StatusBadRequest, fmt.Sprintf("Parâmetro orgao=%s inválido", aID))
}
strAveragePerCapita, err := h.client.Db.GetAveragePerCapita(aID, year)
if err != nil {
log.Printf("[totals of agency year] error getting average per capita (estado:%s):%q", aID, err)
return c.JSON(http.StatusBadRequest, fmt.Sprintf("Parâmetro orgao=%s inválido", aID))
}
host := c.Request().Host
strAgency.URL = fmt.Sprintf("%s/v2/orgao/%s", host, strAgency.ID)
for _, agencyMonthlyInfo := range agenciesMonthlyInfo[aID] {
Expand Down Expand Up @@ -408,6 +413,12 @@ func (h handler) V2GetTotalsOfAgencyYear(c echo.Context) error {
},
MonthTotals: monthTotalsOfYear,
SummaryPackage: pkg,
AveragePerCapita: &perCapitaData{
BaseRemuneration: strAveragePerCapita.BaseRemuneration,
OtherRemunerations: strAveragePerCapita.OtherRemunerations,
Discounts: strAveragePerCapita.Discounts,
Remunerations: strAveragePerCapita.Remunerations,
},
}
return c.JSON(http.StatusOK, agencyTotalsYear)
}
Expand Down Expand Up @@ -820,13 +831,13 @@ func (h handler) GetAnnualSummary(c echo.Context) error {
var annualData []annualSummaryData
for _, s := range summaries {
baseRemPerMonth := s.BaseRemuneration / float64(s.NumMonthsWithData)
baseRemPerCapita := s.BaseRemuneration / float64(s.TotalCount)
baseRemPerCapita := s.BaseRemunerationPerCapita
otherRemPerMonth := s.OtherRemunerations / float64(s.NumMonthsWithData)
otherRemPerCapita := s.OtherRemunerations / float64(s.TotalCount)
otherRemPerCapita := s.OtherRemunerationsPerCapita
remPerMonth := s.Remunerations / float64(s.NumMonthsWithData)
remPerCapita := s.Remunerations / float64(s.TotalCount)
remPerCapita := s.RemunerationsPerCapita
discountsRemPerMonth := s.Discounts / float64(s.NumMonthsWithData)
discountsRemPerCapita := s.Discounts / float64(s.TotalCount)
discountsRemPerCapita := s.DiscountsPerCapita
itemSummary := itemSummary{
FoodAllowance: s.ItemSummary.FoodAllowance,
BonusLicense: s.ItemSummary.BonusLicense,
Expand Down
16 changes: 12 additions & 4 deletions uiapi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ type agencyTotalsYear struct {
}

type v2AgencyTotalsYear struct {
Year int `json:"ano,omitempty"`
Agency *agency `json:"orgao,omitempty"`
MonthTotals []v2MonthTotals `json:"meses,omitempty"`
SummaryPackage *backup `json:"package,omitempty"`
Year int `json:"ano,omitempty"`
Agency *agency `json:"orgao,omitempty"`
AveragePerCapita *perCapitaData `json:"media_por_membro,omitempty"`
MonthTotals []v2MonthTotals `json:"meses,omitempty"`
SummaryPackage *backup `json:"package,omitempty"`
}

type backup struct {
Expand Down Expand Up @@ -292,3 +293,10 @@ type mensalRemuneration struct {
Remunerations float64 `json:"remuneracoes"`
ItemSummary itemSummary `json:"resumo_rubricas"`
}

type perCapitaData struct {
BaseRemuneration float64 `json:"remuneracao_base"`
OtherRemunerations float64 `json:"outras_remuneracoes"`
Discounts float64 `json:"descontos"`
Remunerations float64 `json:"remuneracoes"`
}
52 changes: 44 additions & 8 deletions uiapi/uiapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,20 @@ func (g getTotalsOfAgencyYear) testWhenDataExists(t *testing.T) {
OmbudsmanURL: "http://www.tjal.jus.br/ombudsman",
},
}
avg := models.PerCapitaData{
AgencyID: "tjal",
Year: 2020,
BaseRemuneration: 33173.01121495333,
OtherRemunerations: 9119.563364485992,
Discounts: 10382.615233644861,
Remunerations: 33173.01121495333,
}

dbMock.EXPECT().Connect().Return(nil).Times(1)
dbMock.EXPECT().GetAgency("tjal").Return(&agencies[0], nil).Times(1)
dbMock.EXPECT().GetMonthlyInfo([]models.Agency{{ID: "tjal"}}, 2020).Return(map[string][]models.AgencyMonthlyInfo{"tjal": agmi}, nil).Times(1)
fsMock.EXPECT().GetFile("tjal/datapackage/tjal-2020.zip").Return(agmi[0].Package, nil)
dbMock.EXPECT().GetAveragePerCapita("tjal", 2020).Return(&avg, nil).Times(1)

e := echo.New()
request := httptest.NewRequest(
Expand Down Expand Up @@ -1178,6 +1188,12 @@ func (g getTotalsOfAgencyYear) testWhenDataExists(t *testing.T) {
"ouvidoria": "http://www.tjal.jus.br/ombudsman",
"url": "example.com/v2/orgao/tjal"
},
"media_por_membro": {
"remuneracao_base": 33173.01121495333,
"outras_remuneracoes": 9119.563364485992,
"descontos": 10382.615233644861,
"remuneracoes": 33173.01121495333
},
"meses": [
{
"mes": 1,
Expand Down Expand Up @@ -1232,10 +1248,20 @@ func (g getTotalsOfAgencyYear) testWhenMonthlyInfoDoesNotExist(t *testing.T) {
TwitterHandle: "tjaloficial",
OmbudsmanURL: "http://www.tjal.jus.br/ombudsman",
}
avg := models.PerCapitaData{
AgencyID: "tjal",
Year: 2020,
BaseRemuneration: 0,
OtherRemunerations: 0,
Discounts: 0,
Remunerations: 0,
}

dbMock.EXPECT().Connect().Return(nil).Times(1)
dbMock.EXPECT().GetAgency("tjal").Return(&agency, nil).Times(1)
dbMock.EXPECT().GetMonthlyInfo([]models.Agency{{ID: "tjal"}}, 2020).Return(nil, nil).Times(1)
fsMock.EXPECT().GetFile("tjal/datapackage/tjal-2020.zip").Return(nil, nil).Times(1)
dbMock.EXPECT().GetAveragePerCapita("tjal", 2020).Return(&avg, nil).Times(1)

e := echo.New()
request := httptest.NewRequest(
Expand Down Expand Up @@ -1268,6 +1294,12 @@ func (g getTotalsOfAgencyYear) testWhenMonthlyInfoDoesNotExist(t *testing.T) {
"twitter_handle": "tjaloficial",
"ouvidoria": "http://www.tjal.jus.br/ombudsman",
"url": "example.com/v2/orgao/tjal"
},
"media_por_membro": {
"remuneracao_base": 0,
"outras_remuneracoes": 0,
"descontos": 0,
"remuneracoes": 0
}
}
`
Expand Down Expand Up @@ -1334,14 +1366,18 @@ func (g getAnnualSummary) testWhenDataExists(t *testing.T) {
}
agmi := []models.AnnualSummary{
{
Year: 2020,
AverageCount: 214,
TotalCount: 2568,
BaseRemuneration: 10000,
OtherRemunerations: 1000,
Discounts: 1000,
Remunerations: 10000,
NumMonthsWithData: 12,
Year: 2020,
AverageCount: 214,
TotalCount: 2568,
BaseRemuneration: 10000,
BaseRemunerationPerCapita: 3.8940809968847354,
OtherRemunerations: 1000,
OtherRemunerationsPerCapita: 0.3894080996884735,
Discounts: 1000,
DiscountsPerCapita: 0.3894080996884735,
Remunerations: 10000,
RemunerationsPerCapita: 3.8940809968847354,
NumMonthsWithData: 12,
Package: &models.Backup{
URL: "https://dadosjusbr.org/download/tjal/datapackage/tjal-2020-1.zip",
Hash: "4d7ca8986101673aea060ac1d8e5a529",
Expand Down
Loading