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 = false;
def found_off_tag = false;
def found_all_tag = 0;
def filter_on_tags = 0;
def filter_off_tags = 0;
def filter_all_tags = 0;

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

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


values.each {tagId, status ->
    def found = msg.tags.find{ it.toInteger() == tagId.toInteger(); };

    switch(status) {
        case 'on':
            filter_on_tags++;
            found_on_tag = found_on_tag || found;
            break;
        case 'off':
            filter_off_tags++;
            found_off_tag = found_off_tag || found;
            break;
        case 'all':
            filter_all_tags++;
            found_all_tag += found ? 1 : 0;
            break;
    };
};

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;