<commit_before># Trying out business-rules
# https://github.com/venmo/business-rules

from business_rules import export_rule_data
from business_rules.actions import BaseActions, rule_action
from business_rules.variables import BaseVariables
from business_rules.variables import (
    boolean_rule_variable,
    numeric_rule_variable,
    string_rule_variable
)


class EntryVariables(BaseVariables):

    def __init__(self, entry):
        self.entry = entry

    @numeric_rule_variable()
    def feeling_ranked(self):
        return self.entry.rank

    @string_rule_variable()
    def submitted_day(self):
        return self.entry.submitted_on.strftime("%A")

    @boolean_rule_variable()
    def is_awful(self):
        return self.entry.rank == 1


class EntryActions(BaseActions):

    def __init__(self, entry):
        self.entry = entry

    @rule_action()
    def log_feeling(self):
        args = (self.entry.id, self.entry.get_rank_display(), self.entry)
        print("Entry {0} is feeling {1}: {2}".format(*args))

    @rule_action()  # NOTE: need the params or this doesn't work.
    def send_notification(self):
        args = (self.entry.id, self.entry)
        print("Have a great Weekend, Entry {0}) {1}".format(*args))


def entry_rule_data():
    """Generates a Dict describing Variables/Actions for the Entry model."""
    return export_rule_data(EntryVariables, EntryActions)


# -----------------------------------------------------------------------------
# NOTE: The below are example rules, and a sample method to apply them.
# -----------------------------------------------------------------------------
diary_rules = [

    # If feeling_ranked > 3 AND submitted_day == 'Saturday'
    # Then send_notification
    {
        "conditions": {
            "all": [
                {
                    "name": "feeling_ranked",
                    "operator": "greater_than",
                    "value": 3,
                },
                {
                    "name": "submitted_day",
                    "operator": "equal_to",
                    "value": "Saturday",<commit_msg>testing this out with the diary app<commit_after># Trying out business-rules
# https://github.com/venmo/business-rules

from business_rules import export_rule_data
from business_rules.actions import BaseActions, rule_action
from business_rules.variables import BaseVariables
from business_rules.variables import (
    boolean_rule_variable,
    numeric_rule_variable,
    string_rule_variable
)

from rules.rulesets import ModelRuleset, ruleset
from . models import Entry


class EntryVariables(BaseVariables):

    def __init__(self, entry):
        self.entry = entry

    @numeric_rule_variable()
    def feeling_ranked(self):
        return self.entry.rank

    @string_rule_variable()
    def submitted_day(self):
        return self.entry.submitted_on.strftime("%A")

    @boolean_rule_variable()
    def is_awful(self):
        return self.entry.rank == 1


class EntryActions(BaseActions):

    def __init__(self, entry):
        self.entry = entry

    @rule_action()
    def log_feeling(self):
        args = (self.entry.id, self.entry.get_rank_display(), self.entry)
        print("Entry {0} is feeling {1}: {2}".format(*args))

    @rule_action()  # NOTE: need the params or this doesn't work.
    def send_notification(self):
        args = (self.entry.id, self.entry)
        print("Have a great Weekend, Entry {0}) {1}".format(*args))


class EntryRuleset(ModelRuleset):
    model = Entry  # OR, queryset = Entry.objects.filter(...)
    variables = EntryVariables
    actions = EntryActions
    stop_on_first_trigger = False
ruleset.register('diary', EntryRuleset)


def entry_rule_data():
    """Generates a Dict describing Variables/Actions for the Entry model."""
    return export_rule_data(EntryVariables, EntryActions)


# -----------------------------------------------------------------------------
# NOTE: The below are example rules, and a sample method to apply them.
# -----------------------------------------------------------------------------
diary_rules = [

    # If feeling_ranked > 3 AND submitted_day == 'Saturday'
    # Then send_notification
    {
        "conditions": {
            "all": [
                {
                    "name": "feeling_ranked",
                    "operator": "greater_than",
                    "value": 3,
                },
                {
                    "name": "submitted_day",
                    "operator": "equal_to",
                    "value": "Saturday",
{'fraction_non_alphanumeric': 0.16604436635185593, 'fraction_numerical': 0.0035141664836371624, 'mean_word_length': 2.0728744939271255, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5976363', 'n_tokens_mistral': 1258, 'n_tokens_neox': 1192, 'n_words': 305}