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
46415b5c
Commit
46415b5c
authored
Dec 06, 2022
by
Sarah Abrishami
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: added CRUD functions
parent
139bcf18
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
81 deletions
+89
-81
app/config.py
app/config.py
+4
-2
app/main/static/rule_config.yml
app/main/static/rule_config.yml
+67
-66
app/main/utils/common.py
app/main/utils/common.py
+9
-4
app/main/views/validate.py
app/main/views/validate.py
+8
-7
app/models.py
app/models.py
+1
-2
wheels/Rulemall-0.1-py3-none-any.whl
wheels/Rulemall-0.1-py3-none-any.whl
+0
-0
No files found.
app/config.py
View file @
46415b5c
...
@@ -4,13 +4,14 @@ basedir = os.path.abspath(os.path.dirname(__file__))
...
@@ -4,13 +4,14 @@ basedir = os.path.abspath(os.path.dirname(__file__))
class
Config
:
class
Config
:
API_DESCRIPTION
=
'Broccoli Rule Engine'
IO
=
'http://sumit_io:5300'
DEBUG
=
False
DEBUG
=
False
TESTING
=
False
TESTING
=
False
API_DESCRIPTION
=
'Broccoli Rule Engine'
SQLALCHEMY_DATABASE_URI
=
'postgresql+psycopg2://postgres:postgres@10.1.1.5:5432/dqdb_test'
SQLALCHEMY_DATABASE_URI
=
'postgresql+psycopg2://postgres:postgres@10.1.1.5:5432/dqdb_test'
SQLALCHEMY_TRACK_MODIFICATIONS
=
False
SQLALCHEMY_TRACK_MODIFICATIONS
=
False
LOG_TO_STDOUT
=
os
.
environ
.
get
(
'LOG_TO_STDOUT'
)
LOG_TO_STDOUT
=
os
.
environ
.
get
(
'LOG_TO_STDOUT'
)
PORT
=
5
8
00
PORT
=
5
2
00
AUTO_UPDATE
=
False
AUTO_UPDATE
=
False
CACHE_TYPE
=
"SimpleCache"
CACHE_TYPE
=
"SimpleCache"
CACHE_DEFAULT_TIMEOUT
=
300
CACHE_DEFAULT_TIMEOUT
=
300
...
@@ -38,6 +39,7 @@ class TestingConfig(Config):
...
@@ -38,6 +39,7 @@ class TestingConfig(Config):
class
LocalConfig
(
Config
):
class
LocalConfig
(
Config
):
IO
=
'http://localhost:5300'
DEBUG
=
True
DEBUG
=
True
AUTO_UPDATE
=
False
AUTO_UPDATE
=
False
...
...
app/main/static/rule_config.yml
View file @
46415b5c
---
---
name
:
test1
rules
:
rules
:
AND
:
-
rule_type
:
Unique
-
rule_type
:
Unique
rule_attributes
:
rule_attributes
:
name
:
unique_customer_id
name
:
unique_customer_id
...
@@ -45,7 +48,6 @@ rules:
...
@@ -45,7 +48,6 @@ rules:
orient
:
column
orient
:
column
validator_parameters
:
validator_parameters
:
minimum
:
18
minimum
:
18
-
rule_type
:
Length
-
rule_type
:
Length
rule_attributes
:
rule_attributes
:
name
:
cellphone_length_valid
name
:
cellphone_length_valid
...
@@ -57,7 +59,6 @@ rules:
...
@@ -57,7 +59,6 @@ rules:
max_len
:
11
max_len
:
11
left_inclusive
:
true
left_inclusive
:
true
right_inclusive
:
true
right_inclusive
:
true
-
rule_type
:
Category
-
rule_type
:
Category
rule_attributes
:
rule_attributes
:
name
:
military_service
name
:
military_service
...
...
app/main/utils/common.py
View file @
46415b5c
import
gzip
import
gzip
import
collections
import
collections
from
flask
import
make_response
,
json
from
flask
import
make_response
,
json
,
current_app
import
numpy
as
np
import
numpy
as
np
import
pandas
as
pd
import
pandas
as
pd
from
app.errors
import
*
from
app.errors
import
*
...
@@ -9,6 +9,7 @@ from rulemall.utils.rule_builder import rule_builder
...
@@ -9,6 +9,7 @@ from rulemall.utils.rule_builder import rule_builder
from
app
import
db
from
app
import
db
from
app.models
import
Validation
from
app.models
import
Validation
import
yaml
import
yaml
import
requests
def
response_message
(
data
=
None
,
status
=
200
):
def
response_message
(
data
=
None
,
status
=
200
):
...
@@ -59,13 +60,17 @@ def convert(o):
...
@@ -59,13 +60,17 @@ def convert(o):
json
.
dumps
(
o
)
json
.
dumps
(
o
)
def
read_data
():
def
read_data
(
ds
=
None
,
uid
=
None
,
cols
=
[]):
if
ds
:
req
=
requests
.
post
(
f
'{current_app.config["IO"]}/r/data/{ds}/{uid}'
,
json
=
{
'columns'
:
cols
})
return
pd
.
DataFrame
(
req
.
json
()[
'data'
])
else
:
return
pd
.
read_excel
(
'app/main/static/sample_data.xlsx'
)
return
pd
.
read_excel
(
'app/main/static/sample_data.xlsx'
)
def
read_rules
():
def
read_rules
():
path
=
'app/main/static/rule_config.yml'
path
=
'app/main/static/rule_config.yml'
return
rule_builder
(
yaml
.
load
(
open
(
path
),
Loader
=
yaml
.
FullLoader
)
)
return
yaml
.
load
(
open
(
path
),
Loader
=
yaml
.
FullLoader
)
def
write_validations
(
data
):
def
write_validations
(
data
):
...
...
app/main/views/validate.py
View file @
46415b5c
...
@@ -5,17 +5,18 @@ import pandas as pd
...
@@ -5,17 +5,18 @@ import pandas as pd
from
datetime
import
datetime
from
datetime
import
datetime
@
main
.
route
(
'/validate'
,
methods
=
[
'GET'
,
'POST'
])
@
main
.
route
(
'/validate/<ds>/<uid>'
,
methods
=
[
'GET'
,
'POST'
])
def
validate
():
def
validate
(
ds
,
uid
):
data
=
read_data
()
configs
=
read_rules
()
configs
=
read_rules
()
rs
=
RulesGroup
()
.
from_dict
(
configs
)
rg
=
RulesGroup
()
.
from_dict
(
configs
)
rs
.
reset_data
(
data
)
cols
=
rg
.
get_target
()
validation
,
responsible
=
rs
.
validate
()
data
=
read_data
(
ds
,
uid
,
cols
)
rg
.
reset_data
(
data
)
validation
,
responsible
=
rg
.
validate
()
validation
=
pd
.
concat
([
validation
.
rename
(
'validation'
),
responsible
],
axis
=
1
)
validation
=
pd
.
concat
([
validation
.
rename
(
'validation'
),
responsible
],
axis
=
1
)
validation
=
validation
.
reset_index
()
.
rename
(
columns
=
{
'index'
:
'rid'
})
validation
=
validation
.
reset_index
()
.
rename
(
columns
=
{
'index'
:
'rid'
})
# TODO return rule group id
# TODO return rule group id
validation
[
'rgid'
]
=
r
s
.
id
validation
[
'rgid'
]
=
r
g
.
id
validation
[
'created_date'
]
=
datetime
.
now
()
validation
[
'created_date'
]
=
datetime
.
now
()
validation
[
'modified_date'
]
=
datetime
.
now
()
validation
[
'modified_date'
]
=
datetime
.
now
()
result
=
write_validations
(
validation
)
result
=
write_validations
(
validation
)
...
...
app/models.py
View file @
46415b5c
...
@@ -7,8 +7,7 @@ from uuid import uuid4
...
@@ -7,8 +7,7 @@ from uuid import uuid4
class
Ruleset
(
db
.
Model
):
class
Ruleset
(
db
.
Model
):
__tablename__
=
'ruleset'
__tablename__
=
'ruleset'
uid
=
db
.
Column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid4
)
uid
=
db
.
Column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid4
)
query
=
db
.
Column
(
db
.
String
)
data
=
db
.
Column
(
JSONB
)
connection_string
=
db
.
Column
(
db
.
String
)
created_date
=
db
.
Column
(
db
.
DateTime
)
created_date
=
db
.
Column
(
db
.
DateTime
)
modified_date
=
db
.
Column
(
db
.
DateTime
)
modified_date
=
db
.
Column
(
db
.
DateTime
)
...
...
wheels/Rulemall-0.1-py3-none-any.whl
View file @
46415b5c
No preview for this file type
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