Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CSS-Engine-Python-Cusca
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Proyectos-Innovacion-2024
CSS-Engine-Python-Cusca
Commits
b9a72588
Commit
b9a72588
authored
Jun 24, 2024
by
Cristian Aguirre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update match-and-exclude-records-actions_v1.py
parent
eb0ad02e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
match-and-exclude-records-actions_v1.py
conf/scripts/match-and-exclude-records-actions_v1.py
+10
-6
No files found.
conf/scripts/match-and-exclude-records-actions_v1.py
View file @
b9a72588
...
...
@@ -98,12 +98,13 @@ class MatchAndExcludeRecordsAction(ActionInterface):
self
.
app
.
logger
.
info
(
f
"Insumos cargados - {self.identifier}"
)
if
self
.
create_tmp_table
:
import
random
from
app.main.engine.util.Timezone
import
Timezone
from
sqlalchemy
import
text
# Creamos las tablas temporales del pivot y contraparte con sufijo N° aleatorio de 6 dígitos
random_number
=
random
.
randint
(
100000
,
999999
)
pivot_query
=
f
"CREATE TABLE ENGINE_{pivot_table}_{random_number} AS SELECT * FROM {pivot_table}"
ctp_query
=
f
"CREATE TABLE ENGINE_{ctp_table}_{random_number} AS SELECT * FROM {ctp_table}"
timezone
=
Timezone
(
self
.
app
)
current_time
=
timezone
.
datetime_by_tzone
()
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M"
)
pivot_query
=
f
"CREATE TABLE ENGINE_{pivot_table}_{current_time} AS SELECT * FROM {pivot_table}"
ctp_query
=
f
"CREATE TABLE ENGINE_{ctp_table}_{current_time} AS SELECT * FROM {ctp_table}"
source_obj
.
create_engine
()
engine
=
source_obj
.
engine
with
engine
.
connect
()
as
conn
:
...
...
@@ -237,7 +238,8 @@ class MatchAndExcludeRecordsAction(ActionInterface):
total_cols
=
group_cols
+
[
amount_col
,
id_col
,
"DIFF"
]
self
.
app
.
logger
.
info
(
f
"Aplicando algoritmo de exclusión. Máximo de {str(max_combinations)} combinaciones - {self.identifier}"
)
resultado
=
df3
.
groupby
(
group_cols
)[
total_cols
]
.
apply
(
lambda
x
:
custom_func
(
x
,
amount_col
,
id_col
,
max_combinations
))
if
resultado
.
empty
:
return
pd
.
DataFrame
([])
resultado
=
resultado
.
reset_index
()
if
len
(
resultado
.
columns
)
==
1
:
resultado
=
pd
.
DataFrame
([],
columns
=
group_cols
+
[
"LISTA_DIFF"
])
...
...
@@ -256,14 +258,16 @@ class MatchAndExcludeRecordsAction(ActionInterface):
meged2
=
meged2
.
compute
()
if
meged2
.
empty
:
pass
self
.
app
.
logger
.
info
(
f
"El dataset resultante esta vacío luego de la ejecución del script"
)
elif
self
.
exclude_pivot
:
meged2
[
'INTER_PIVOT_ID'
]
=
meged2
.
apply
(
lambda
row
:
self
.
array_except
(
row
[
self
.
pivot_params
[
"id-column"
]],
row
[
'LISTA_DIFF'
]),
axis
=
1
)
meged2
=
meged2
[
meged2
[
"INTER_PIVOT_ID"
]
.
apply
(
lambda
x
:
True
if
isinstance
(
x
,
List
)
and
len
(
x
)
>
0
else
False
)]
meged2
=
meged2
.
rename
(
columns
=
{
self
.
ctp_params
[
"id-column"
]:
"INTER_CTP_ID"
})
if
meged2
[
'INTER_CTP_ID'
]
.
dtype
==
'int64'
:
meged2
[
'INTER_CTP_ID'
]
=
meged2
[
'INTER_CTP_ID'
]
.
apply
(
lambda
x
:
[
x
])
.
astype
(
'object'
)
else
:
meged2
[
'INTER_CTP_ID'
]
=
meged2
.
apply
(
lambda
row
:
self
.
array_except
(
row
[
self
.
ctp_params
[
"id-column"
]],
row
[
'LISTA_DIFF'
]),
axis
=
1
)
meged2
=
meged2
[
meged2
[
'INTER_CTP_ID'
]
.
apply
(
lambda
x
:
True
if
isinstance
(
x
,
List
)
and
len
(
x
)
>
0
else
False
)]
meged2
=
meged2
.
rename
(
columns
=
{
self
.
pivot_params
[
"id-column"
]:
"INTER_PIVOT_ID"
})
if
meged2
[
'INTER_PIVOT_ID'
]
.
dtype
==
'int64'
:
meged2
[
'INTER_PIVOT_ID'
]
=
meged2
[
'INTER_PIVOT_ID'
]
.
apply
(
lambda
x
:
[
x
])
.
astype
(
'object'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment