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
Hide 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__))
class
Config
:
API_DESCRIPTION
=
'Broccoli Rule Engine'
IO
=
'http://sumit_io:5300'
DEBUG
=
False
TESTING
=
False
API_DESCRIPTION
=
'Broccoli Rule Engine'
SQLALCHEMY_DATABASE_URI
=
'postgresql+psycopg2://postgres:postgres@10.1.1.5:5432/dqdb_test'
SQLALCHEMY_TRACK_MODIFICATIONS
=
False
LOG_TO_STDOUT
=
os
.
environ
.
get
(
'LOG_TO_STDOUT'
)
PORT
=
5
8
00
PORT
=
5
2
00
AUTO_UPDATE
=
False
CACHE_TYPE
=
"SimpleCache"
CACHE_DEFAULT_TIMEOUT
=
300
...
...
@@ -38,6 +39,7 @@ class TestingConfig(Config):
class
LocalConfig
(
Config
):
IO
=
'http://localhost:5300'
DEBUG
=
True
AUTO_UPDATE
=
False
...
...
app/main/static/rule_config.yml
View file @
46415b5c
---
name
:
test1
rules
:
-
rule_type
:
Unique
rule_attributes
:
name
:
unique_customer_id
target
:
customer_id
orient
:
column
invert
:
false
validator_parameters
:
keep
:
false
-
rule_type
:
Unique
rule_attributes
:
name
:
not_unique_loan_id
target
:
loan_id
orient
:
column
invert
:
true
validator_parameters
:
keep
:
false
-
rule_type
:
Range
rule_attributes
:
name
:
age_range_18_50
target
:
age
orient
:
column
validator_parameters
:
maximum
:
50
minimum
:
18
left_inclusive
:
true
right_inclusive
:
true
-
rule_type
:
Category
rule_attributes
:
name
:
cutomer_type_category
target
:
customer_type
orient
:
column
validator_parameters
:
categories
:
-
1
-
2
-
3
-
4
-
5
-
rule_type
:
Range
rule_attributes
:
name
:
age_range_under_18
target
:
age
orient
:
column
validator_parameters
:
minimum
:
18
-
rule_type
:
Length
rule_attributes
:
name
:
cellphone_length_valid
target
:
cell_phone
orient
:
column
invert
:
true
validator_parameters
:
min_len
:
11
max_len
:
11
left_inclusive
:
true
right_inclusive
:
true
-
rule_type
:
Category
rule_attributes
:
name
:
military_service
target
:
military_service_status
orient
:
column
validator_parameters
:
categories
:
-
true
AND
:
-
rule_type
:
Unique
rule_attributes
:
name
:
unique_customer_id
target
:
customer_id
orient
:
column
invert
:
false
validator_parameters
:
keep
:
false
-
rule_type
:
Unique
rule_attributes
:
name
:
not_unique_loan_id
target
:
loan_id
orient
:
column
invert
:
true
validator_parameters
:
keep
:
false
-
rule_type
:
Range
rule_attributes
:
name
:
age_range_18_50
target
:
age
orient
:
column
validator_parameters
:
maximum
:
50
minimum
:
18
left_inclusive
:
true
right_inclusive
:
true
-
rule_type
:
Category
rule_attributes
:
name
:
cutomer_type_category
target
:
customer_type
orient
:
column
validator_parameters
:
categories
:
-
1
-
2
-
3
-
4
-
5
-
rule_type
:
Range
rule_attributes
:
name
:
age_range_under_18
target
:
age
orient
:
column
validator_parameters
:
minimum
:
18
-
rule_type
:
Length
rule_attributes
:
name
:
cellphone_length_valid
target
:
cell_phone
orient
:
column
invert
:
true
validator_parameters
:
min_len
:
11
max_len
:
11
left_inclusive
:
true
right_inclusive
:
true
-
rule_type
:
Category
rule_attributes
:
name
:
military_service
target
:
military_service_status
orient
:
column
validator_parameters
:
categories
:
-
true
app/main/utils/common.py
View file @
46415b5c
import
gzip
import
collections
from
flask
import
make_response
,
json
from
flask
import
make_response
,
json
,
current_app
import
numpy
as
np
import
pandas
as
pd
from
app.errors
import
*
...
...
@@ -9,6 +9,7 @@ from rulemall.utils.rule_builder import rule_builder
from
app
import
db
from
app.models
import
Validation
import
yaml
import
requests
def
response_message
(
data
=
None
,
status
=
200
):
...
...
@@ -59,13 +60,17 @@ def convert(o):
json
.
dumps
(
o
)
def
read_data
():
return
pd
.
read_excel
(
'app/main/static/sample_data.xlsx'
)
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'
)
def
read_rules
():
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
):
...
...
app/main/views/validate.py
View file @
46415b5c
...
...
@@ -5,17 +5,18 @@ import pandas as pd
from
datetime
import
datetime
@
main
.
route
(
'/validate'
,
methods
=
[
'GET'
,
'POST'
])
def
validate
():
data
=
read_data
()
@
main
.
route
(
'/validate/<ds>/<uid>'
,
methods
=
[
'GET'
,
'POST'
])
def
validate
(
ds
,
uid
):
configs
=
read_rules
()
rs
=
RulesGroup
()
.
from_dict
(
configs
)
rs
.
reset_data
(
data
)
validation
,
responsible
=
rs
.
validate
()
rg
=
RulesGroup
()
.
from_dict
(
configs
)
cols
=
rg
.
get_target
()
data
=
read_data
(
ds
,
uid
,
cols
)
rg
.
reset_data
(
data
)
validation
,
responsible
=
rg
.
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'
]
=
r
s
.
id
validation
[
'rgid'
]
=
r
g
.
id
validation
[
'created_date'
]
=
datetime
.
now
()
validation
[
'modified_date'
]
=
datetime
.
now
()
result
=
write_validations
(
validation
)
...
...
app/models.py
View file @
46415b5c
...
...
@@ -7,8 +7,7 @@ from uuid import uuid4
class
Ruleset
(
db
.
Model
):
__tablename__
=
'ruleset'
uid
=
db
.
Column
(
UUID
(
as_uuid
=
True
),
primary_key
=
True
,
default
=
uuid4
)
query
=
db
.
Column
(
db
.
String
)
connection_string
=
db
.
Column
(
db
.
String
)
data
=
db
.
Column
(
JSONB
)
created_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