Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Gabriel Weisse
/
presupuestov1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
pr0nstar
2026-04-10 00:20:02 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d093b199a8b1dac54a138585f4c40ea57362cfb9
d093b199
1 parent
d317b254
VII
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
208 additions
and
32 deletions
models/__init__.py
models/classifier.py
models/daily.py
models/entity.py
models/treemap.py
routers/entity.py
schemas/classifier.py
schemas/daily.py
schemas/entity.py
models/__init__.py
View file @
d093b19
...
...
@@ -4,5 +4,6 @@ from . import (
finfun
,
objeto
,
treemap
,
entity
,
daily
,
)
...
...
models/classifier.py
View file @
d093b19
...
...
@@ -100,7 +100,10 @@ class ClasGeografico(ClasBase, Base):
)
ubigeo
:
Mapped
[
str
]
=
mapped_column
(
Text
,
primary_key
=
True
)
desc_departamento
:
Mapped
[
str
]
=
mapped_column
(
String
(
12
))
desc_ubigeo
:
Mapped
[
str
|
None
]
=
mapped_column
(
Text
)
municipio_ubigeo
:
Mapped
[
int
|
None
]
=
mapped_column
(
Integer
)
...
...
models/daily.py
View file @
d093b19
...
...
@@ -9,9 +9,10 @@ from sqlalchemy import (
Index
,
MetaData
,
Boolean
,
DateTime
DateTime
,
Date
)
from
datetime
import
datetime
from
datetime
import
datetime
,
date
class
UpdateStatus
(
Base
):
...
...
@@ -92,7 +93,7 @@ class TimeSeries(Base):
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
)
fecha
:
Mapped
[
str
]
=
mapped_column
(
String
(
10
)
)
fecha
:
Mapped
[
date
]
=
mapped_column
(
Date
)
devengado
:
Mapped
[
float
]
=
mapped_column
(
Numeric
(
30
,
15
))
diferencia
:
Mapped
[
float
]
=
mapped_column
(
Numeric
(
30
,
15
))
dias
:
Mapped
[
int
]
=
mapped_column
(
Integer
)
...
...
models/entity.py
0 → 100644
View file @
d093b19
from
sqlalchemy.orm
import
Mapped
,
mapped_column
from
presupuestov1.model
import
Base
from
sqlalchemy
import
(
Integer
,
String
,
Text
,
Numeric
,
Index
,
MetaData
,
)
class
EntidadDistribuciones
(
Base
):
__tablename__
=
"entidad_distribuciones"
__table_args__
=
(
Index
(
"idx_entidad_distribuciones_tipo"
,
"tipo"
),
Index
(
"idx_entidad_distribuciones_tipo_codigo"
,
"tipo_codigo"
),
Index
(
"idx_entidad_distribuciones_codigo"
,
"codigo"
),
Index
(
"idx_entidad_distribuciones_dimension"
,
"dimension"
),
Index
(
"idx_entidad_distribuciones_gestion"
,
"gestion"
),
{
"schema"
:
"web"
},
)
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
tipo
:
Mapped
[
str
]
=
mapped_column
(
String
(
8
))
tipo_codigo
:
Mapped
[
str
]
=
mapped_column
(
String
(
16
))
codigo
:
Mapped
[
str
]
=
mapped_column
(
String
(
8
))
dimension
:
Mapped
[
str
]
=
mapped_column
(
String
(
10
))
gestion
:
Mapped
[
int
]
=
mapped_column
(
Integer
)
padre
:
Mapped
[
str
]
=
mapped_column
(
String
(
8
))
hijo
:
Mapped
[
str
]
=
mapped_column
(
String
(
8
))
devengado
:
Mapped
[
float
]
=
mapped_column
(
Numeric
(
30
,
15
))
desc_padre
:
Mapped
[
str
]
=
mapped_column
(
Text
)
desc_hijo
:
Mapped
[
str
]
=
mapped_column
(
Text
)
class
EntidadResumenes
(
Base
):
__tablename__
=
"entidad_resumenes"
__table_args__
=
(
Index
(
"idx_entidad_resumenes_tipo"
,
"tipo"
),
Index
(
"idx_entidad_resumenes_tipo_codigo"
,
"tipo_codigo"
),
Index
(
"idx_entidad_resumenes_codigo"
,
"codigo"
),
Index
(
"idx_entidad_resumenes_gestion"
,
"gestion"
),
{
"schema"
:
"web"
},
)
id
:
Mapped
[
int
]
=
mapped_column
(
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
tipo
:
Mapped
[
str
]
=
mapped_column
(
String
(
8
))
tipo_codigo
:
Mapped
[
str
]
=
mapped_column
(
String
(
16
))
codigo
:
Mapped
[
str
]
=
mapped_column
(
String
(
8
))
gestion
:
Mapped
[
int
]
=
mapped_column
(
Integer
)
devengado
:
Mapped
[
float
]
=
mapped_column
(
Numeric
(
30
,
15
))
ranking
:
Mapped
[
int
]
=
mapped_column
(
Integer
)
desc
:
Mapped
[
str
]
=
mapped_column
(
Text
)
desc_padre
:
Mapped
[
str
]
=
mapped_column
(
Text
)
models/treemap.py
View file @
d093b19
...
...
@@ -105,6 +105,9 @@ def get_clas_entities(query_filters, db, query, ClassObject, object_id):
ClassObject
.
gestion
==
query
.
gestion
,
])
if
query
.
nivel
is
not
None
:
query_filters
.
append
(
ClassObject
.
nivel
==
query
.
nivel
)
if
query
.
id
is
not
None
:
ids
=
query
.
id
.
split
(
','
)
ids
=
[
int
(
_
.
strip
())
for
_
in
ids
]
...
...
routers/entity.py
View file @
d093b19
...
...
@@ -9,75 +9,153 @@ from sqlalchemy import and_, or_
from
presupuestov1
import
model
,
schema
,
constant
,
schemas
,
models
,
search
router
=
APIRouter
(
router
_entidad
=
APIRouter
(
prefix
=
'/entidad'
,
tags
=
[
'entidad'
],
)
router_ubigeo
=
APIRouter
(
prefix
=
'/ubigeo'
,
tags
=
[
'ubigeo'
],
)
router_da
=
APIRouter
(
prefix
=
'/direccion_administrativa'
,
tags
=
[
'direccion_administrativa'
],
)
###############################################################################
# GET
###############################################################################
@router.get
(
'/{entity_id:int}'
,
response_model
=
schemas
.
entity
.
ClasInstitucionalIngresosGastos
)
# clas
@router_entidad.get
(
'/clasificador'
,
response_model
=
List
[
schemas
.
classifier
.
ClasInstitucional
])
def
fetch_classifier
(
db
:
Session
=
Depends
(
model
.
get_db
),
):
return
db
.
query
(
models
.
classifier
.
ClasInstitucional
)
.
all
()
@router_ubigeo.get
(
'/clasificador'
,
response_model
=
List
[
schemas
.
classifier
.
ClasGeografico
])
def
fetch_classifier
(
db
:
Session
=
Depends
(
model
.
get_db
),
):
return
db
.
query
(
models
.
classifier
.
ClasGeografico
)
.
all
()
# base
@router_entidad.get
(
'/{entity_id:str}'
,
response_model
=
schemas
.
entity
.
ClasInstitucionalIngresosGastos
)
def
fetch_entity
(
entity_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
):
TreemapObjeto
=
models
.
treemap
.
TreemapObjeto
gastos
=
db
.
query
(
TreemapObjeto
)
.
filter
(
TreemapObjeto
.
entidad
==
entity_id
,
TreemapObjeto
.
objeto
==
0
)
.
all
()
ClasInstitucional
=
models
.
classifier
.
ClasInstitucional
entidad
=
db
.
query
(
ClasInstitucional
)
.
filter
(
ClasInstitucional
.
entidad
==
entity_id
)
.
one
()
setattr
(
entidad
,
'gastos'
,
gastos
)
gastos_ingresos
=
get_resumen
(
'entidad'
,
entity_id
)
setattr
(
entidad
,
'gastos_ingresos'
,
gastos_ingresos
)
return
entidad
@router.get
(
'/clasificador'
,
response_model
=
List
[
schemas
.
classifier
.
ClasInstitucional
])
def
fetch_classifier
(
@router_ubigeo.get
(
'/{ubigeo_id:str}'
,
response_model
=
schemas
.
entity
.
ClasGeograficoIngresosGastos
)
def
fetch_entity
(
ubigeo_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
):
return
db
.
query
(
models
.
classifier
.
ClasInstitucional
)
.
all
()
ClasGeografico
=
models
.
classifier
.
ClasGeografico
ubigeo
=
db
.
query
(
ClasGeografico
)
.
filter
(
ClasGeografico
.
ubigeo
==
ubigeo_id
)
.
one
()
gastos_ingresos
=
get_resumen
(
'municipio_ubigeo'
,
ubigeo_id
)
setattr
(
ubigeo
,
'gastos_ingresos'
,
gastos_ingresos
)
@router.get
(
'/{entity_id:int}/objetos'
,
response_model
=
List
[
schemas
.
treemap
.
TreemapObjeto
])
return
ubigeo
# objetos
@router_entidad.get
(
'/{entity_id:str}/objetos'
,
response_model
=
List
[
schemas
.
entity
.
EntidadDistribucion
])
def
fetch_entity_objetos
(
entity_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
query
:
schema
.
QueryParams
=
Depends
(),
):
TreemapObjeto
=
models
.
treemap
.
TreemapObjeto
return
models
.
treemap
.
get_entity_connections
(
entity_id
,
db
,
query
,
TreemapObjeto
,
'objeto'
)
return
get_distribuciones
(
'entidad'
,
entidad_id
,
'objeto'
,
query
)
@router.get
(
'/{entity_id:int}/finfuns'
,
response_model
=
List
[
schemas
.
treemap
.
TreemapFinFun
])
@router_ubigeo.get
(
'/{ubigeo_id:str}/objetos'
,
response_model
=
List
[
schemas
.
entity
.
EntidadDistribucion
])
def
fetch_entity_objetos
(
ubigeo_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
query
:
schema
.
QueryParams
=
Depends
(),
):
return
get_distribuciones
(
'municipio_ubigeo'
,
ubigeo_id
,
'objeto'
,
query
)
@router_entidad.get
(
'/{entity_id:str}/finfuns'
,
response_model
=
List
[
schemas
.
entity
.
EntidadDistribucion
])
def
fetch_entity_finfuns
(
entity_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
query
:
schema
.
QueryParams
=
Depends
(),
):
TreemapFinFun
=
models
.
treemap
.
TreemapFinFun
return
models
.
treemap
.
get_entity_connections
(
entity_id
,
db
,
query
,
TreemapFinFun
,
'finfun'
)
return
get_distribuciones
(
'entidad'
,
entidad_id
,
'finfun'
,
query
)
@router_ubigeo.get
(
'/{ubigeo_id:str}/finfuns'
,
response_model
=
List
[
schemas
.
entity
.
EntidadDistribucion
])
def
fetch_entity_finfuns
(
ubigeo_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
query
:
schema
.
QueryParams
=
Depends
(),
):
return
get_distribuciones
(
'municipio_ubigeo'
,
ubigeo_id
,
'finfun'
,
query
)
@router
.get
(
'/{entity_id:int}/actecos'
,
response_model
=
List
[
schemas
.
treemap
.
TreemapActeco
])
@router
_entidad.get
(
'/{entity_id:str}/actecos'
,
response_model
=
List
[
schemas
.
entity
.
EntidadDistribucion
])
def
fetch_entity_actecos
(
entity_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
query
:
schema
.
QueryParams
=
Depends
(),
):
TreemapActeco
=
models
.
treemap
.
TreemapActeco
return
models
.
treemap
.
get_entity_connections
(
entity_id
,
db
,
query
,
TreemapActeco
,
'acteco'
return
get_distribuciones
(
'entidad'
,
entidad_id
,
'acteco'
,
query
)
@router_ubigeo.get
(
'/{ubigeo_id:str}/actecos'
,
response_model
=
List
[
schemas
.
entity
.
EntidadDistribucion
])
def
fetch_entity_actecos
(
ubigeo_id
:
int
,
db
:
Session
=
Depends
(
model
.
get_db
),
query
:
schema
.
QueryParams
=
Depends
(),
):
return
get_distribuciones
(
'municipio_ubigeo'
,
ubigeo_id
,
'acteco'
,
query
)
###############################################################################
# private
###############################################################################
def
get_distribuciones
(
tipo_codigo
,
entidad_id
,
dimension
,
query
):
EntidadDistribuciones
=
models
.
entity
.
EntidadDistribuciones
filters
=
[]
if
query
.
gestion
is
not
None
:
filters
.
append
(
EntidadDistribuciones
.
gestion
==
query
.
gestion
)
filters
.
extend
(
EntidadDistribuciones
.
tipo_codigo
==
tipo_codigo
,
EntidadDistribuciones
.
codigo
==
entity_id
,
EntidadDistribuciones
.
dimension
==
dimension
,
)
return
db
.
query
(
EntidadDistribuciones
)
.
filter
(
*
filters
)
.
all
()
def
get_resumen
(
tipo_codigo
,
codigo
):
EntidadResumenes
=
models
.
entity
.
EntidadResumenes
return
db
.
query
(
EntidadResumenes
)
.
filter
(
EntidadResumenes
.
tipo_codigo
==
tipo_codigo
,
EntidadResumenes
.
codigo
==
codigo
,
)
.
all
()
...
...
schemas/classifier.py
View file @
d093b19
...
...
@@ -63,6 +63,7 @@ class ClasActeco(ClasBase):
class
ClasGeografico
(
ClasBase
):
ubigeo
:
str
desc_ubigeo
:
str
|
None
desc_departamento
:
str
|
None
municipio_ubigeo
:
int
|
None
descripciones
:
list
[
get_clasdesc
(
'ubigeo'
)]
|
None
...
...
schemas/daily.py
View file @
d093b19
from
datetime
import
datetime
from
datetime
import
datetime
,
date
from
presupuestov1.schema
import
OrmBaseModel
...
...
@@ -38,7 +38,7 @@ class Timeline(OrmBaseModel):
class
TimeSeries
(
OrmBaseModel
):
fecha
:
str
fecha
:
date
devengado
:
float
|
None
diferencia
:
float
|
None
dias
:
int
...
...
schemas/entity.py
View file @
d093b19
...
...
@@ -4,5 +4,32 @@ from presupuestov1.schema import OrmBaseModel
from
presupuestov1
import
schemas
class
EntidadDistribucion
(
OrmBaseModel
):
tipo
:
str
tipo_codigo
:
str
codigo
:
str
dimension
:
str
gestion
:
int
padre
:
str
hijo
:
str
devengado
:
float
desc_padre
:
str
|
None
desc_hijo
:
str
|
None
class
EntidadResumen
(
OrmBaseModel
):
tipo
:
str
tipo_codigo
:
str
codigo
:
str
gestion
:
int
devengado
:
float
ranking
:
int
|
None
desc
:
str
|
None
desc_padre
:
str
|
None
class
ClasInstitucionalIngresosGastos
(
schemas
.
classifier
.
ClasInstitucional
):
gastos
:
List
[
schemas
.
treemap
.
TreemapObjeto
]
gastos_ingresos
:
List
[
EntidadResumen
]
class
ClasGeograficoIngresosGastos
(
schemas
.
classifier
.
ClasGeografico
):
gastos_ingresos
:
List
[
EntidadResumen
]
...
...
Please
register
or
login
to post a comment