Groovy web console

subscribe to the feed Subscribe
to this
site

log_filter

Published 4 months ago by Peter Gribanov
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def result = true;
def found_on_tag = 0;
def found_off_tag = 0;
def found_all_tag = 0;

def values = [
    "17": "on",
//    "18": "on",
    "18": "off",
//    "17": "all",
//    "18": "all",
];

def msg = [
    'tags': [
        17,
//        18,
    ],
];


def filter_on_tags = values.findAll {tagId, status -> status == 'on' }.each {tagId, status ->
    if (msg.tags.find { it.toInteger() == tagId.toInteger(); }) {
        found_on_tag++;
    };
}.size();

def filter_off_tags = values.findAll {tagId, status -> status == 'off' }.each {tagId, status ->
    if (msg.tags.find { it.toInteger() == tagId.toInteger(); }) {
        found_off_tag++;
    };
}.size();

def filter_all_tags = values.findAll {tagId, status -> status == 'all' }.each {tagId, status ->
    if (msg.tags.find { it.toInteger() == tagId.toInteger(); }) {
        found_all_tag++;
    }
}.size();

println 'filter_on_tags: ' + filter_on_tags;
println 'found_on_tag: ' + found_on_tag;
println 'filter_off_tags: ' + filter_off_tags;
println 'found_off_tag: ' + found_off_tag;
println 'filter_all_tags: ' + filter_all_tags;
println 'found_all_tag: ' + found_all_tag;
println '';

result = result && (filter_on_tags || filter_off_tags || filter_all_tags) && (!filter_on_tags || found_on_tag) && (!filter_off_tags || !found_off_tag) && (!filter_all_tags || found_all_tag == filter_all_tags);
println 'result: ' + result;