Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
R
Rule Engine Service
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
brooklyn
Rule Engine Service
Commits
776d9129
Commit
776d9129
authored
Oct 25, 2022
by
Sarah Abrishami
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated validation structure
parent
156b2d2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
6 deletions
+20
-6
app/main/utils/common.py
app/main/utils/common.py
+7
-2
app/main/views/validate.py
app/main/views/validate.py
+13
-4
No files found.
app/main/utils/common.py
View file @
776d9129
...
...
@@ -7,6 +7,7 @@ from app.errors import *
import
gc
from
rulemall.utils.rule_builder
import
rule_builder
from
app
import
db
from
app.models
import
Validation
def
response_message
(
data
=
None
,
status
=
200
):
...
...
@@ -65,9 +66,13 @@ def read_rules():
return
rule_builder
(
'app/main/static/rule_config.yml'
)
def
write_validations
(
d
f
,
table_name
=
'test2'
):
def
write_validations
(
d
ata
):
try
:
df
.
to_sql
(
table_name
,
con
=
db
.
engine
,
if_exists
=
'replace'
,
index
=
False
)
data
=
data
.
loc
[
~
data
[
'validation'
]]
obj
=
[]
data
.
apply
(
lambda
x
:
obj
.
append
(
Validation
(
rid
=
x
[
'rid'
],
rgid
=
x
[
'rgid'
],
modified_date
=
x
[
'modified_date'
],
responsible
=
x
[
'responsible'
],
created_date
=
x
[
'created_date'
])),
axis
=
1
)
db
.
session
.
bulk_save_objects
(
obj
)
except
Exception
as
e
:
return
str
(
e
)
return
'success'
app/main/views/validate.py
View file @
776d9129
from
app.main
import
main
from
app.main.utils.common
import
response_message
,
read_data
,
read_rules
,
write_validations
from
rulemall
import
RulesGroup
import
pandas
as
pd
from
datetime
import
datetime
@
main
.
route
(
'/validate'
,
methods
=
[
'GET'
,
'POST'
])
def
validate
():
data
=
read_data
()
rules
=
read_rules
()
rs
=
RulesGroup
(
data
=
data
,
rules
=
rules
)
validation
=
rs
.
validate
()
result
=
write_validations
(
validation
,
table_name
=
'sample_data'
)
name
,
rules
=
read_rules
()
rs
=
RulesGroup
(
data
=
data
,
name
=
name
)
rs
.
from_dict
(
rules
)
validation
,
responsible
=
rs
.
validate
()
validation
=
pd
.
concat
([
validation
.
rename
(
'validation'
),
responsible
],
axis
=
1
)
validation
=
validation
.
reset_index
()
.
rename
(
columns
=
{
'index'
:
'rid'
})
# TODO return rule group id
validation
[
'rgid'
]
=
rs
.
id
validation
[
'created_date'
]
=
datetime
.
now
()
validation
[
'modified_date'
]
=
datetime
.
now
()
result
=
write_validations
(
validation
)
return
response_message
(
result
)
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