Purpose of this package is to support creating and maintaining Darwinium files: .rules, .feature.yaml and .strategy
- Creating features & rules programmatically
- Turning lists of features & rules into sets
- Writing those sets to files
- Converting feature and rule files into their list of objects
Use Cases
- Create wholesale featuresets/rulesets from scratch quicker
- Create them with better protection against misconfiguration
- Easier longer term changes and maintenance. Change logic in the generating procedure rather than messy find/replacing or a bunch of copy pasting.
- Autoname a bunch of features with a consistent programmatic naming convention.
- Ensure features/rules are named uniquely (and by extension, identify where there are duplicates)
- Ensure the features referenced by rules actually exist
Example Usage
# %%
from dwn_ext_decision.feature import Feature, FeatureSet
from dwn_ext_decision.rule import Rule, RuleSet
from dwn_ext_decision.utils import write as dwnwrite
from dwn_ext_decision.utils import read as dwnread
# %%
# FEATURES
features = [
Feature.from_params(
# Parameters not supplied are set to their defaults
find_the=Feature.FindThe.velocity_of,
with_the_same=["profiling.device.identifier"]
),
Feature.from_params(
find_the=Feature.FindThe.velocity_of,
with_the_same=["profiling.device.identifier"],
time_window=Feature.TimeWindow.all,
starting={Feature.Starting.hours_in_the_past: 24},
),
Feature.from_params(
find_the=Feature.FindThe.distinct_count_of,
with_the_same=["profiling.device.identifier"],
attributes=["identity['ACCOUNT'].username.username"],
time_window={Feature.TimeWindow.days: 7},
starting=Feature.Starting.immediately,
with_scope=Feature.WithScope.same_organization,
event_type=["account_login_success", "account_login_failed"],
with_similarity=99.0,
default_value=-1,
include_current_event=True
)
]
featureset = FeatureSet(features, autoname=True)
print(featureset.get_feature_names())
dwnwrite.write_features_to_file(
features=featureset,
file_out="myfeatureset.feature.yaml"
)
# %%
# RULES
def ft(name):
"Helper function to fill in feature attribute"
return f"outcome['CHAMPION'].features.general['{name}']"
rules = [
Rule.from_params(
condition="identity['ACCOUNT'].username.username = 'test'",
signal="Test user"
),
Rule.from_params(
type=Rule.Type.If,
condition="step_name = 'login'",
children=[
Rule.from_params(
# signal string will appear in signals array if triggered
signal="Device seen before",
condition=f"{ft('vlcof_dvcid')} > 0",
category="Velocity",
score=-10,
comment="Device seen multiple times"
)
]
)
]
# autoname does not change signals
ruleset = RuleSet(rules, autoname=True)
dwnwrite.write_rules_to_file(
rules=ruleset,
file_out="myruleset.rules"
)