-
Notifications
You must be signed in to change notification settings - Fork 115
WIP: Add complex tag filtering #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,18 +27,59 @@ | |
| #include <IntervalFilterAllWithTags.h> | ||
| #include <Interval.h> | ||
|
|
||
| IntervalFilterAllWithTags::IntervalFilterAllWithTags (std::set <std::string> tags): _tags (std::move(tags)) | ||
| IntervalFilterAllWithTags::IntervalFilterAllWithTags (std::set <std::string> tags, const bool complexFiltering): _tags (std::move(tags)), _complexFiltering (complexFiltering) | ||
| {} | ||
|
|
||
| bool IntervalFilterAllWithTags::accepts (const Interval& interval) | ||
| { | ||
| for (auto& tag : _tags) | ||
| { | ||
| if (! interval.hasTag (tag)) | ||
| if (_complexFiltering) { | ||
| // TODO: WIP, This does not fully implement boolean logic. | ||
| // Check if OR exists. | ||
| bool isOr = false; | ||
| for (auto& tag : _tags) | ||
| { | ||
| return false; | ||
| if (tag == "OR") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, I would opt for lowercase, i.e. |
||
| { | ||
| isOr = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| for (auto& tag : _tags) | ||
| { | ||
| // Process negation | ||
| bool isNegative = tag[0] == '-'; | ||
| std::string tagName = isNegative ? tag.substr(1) : tag; | ||
| bool hasTag = interval.hasTag(tagName); | ||
| if (isNegative) hasTag = !hasTag; | ||
|
|
||
| // Return true at the first sign of a tag, if we're using OR logic. | ||
| if (isOr && hasTag) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| // Return false at the first sign of miss, if we're using AND logic. | ||
| if (!isOr && !hasTag) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // OR logic : Nothing triggered the match, so this interval does not match. | ||
| // AND logic: Nothing triggered the miss, so this interval matches. | ||
| return isOr ? false : true; | ||
| } | ||
| else { | ||
| // Old filtering AND logic | ||
| for (auto& tag : _tags) | ||
| { | ||
| if (! interval.hasTag (tag)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| return true; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ int renderChart ( | |
| // Load the data. | ||
| auto filtering = IntervalFilterAndGroup ({ | ||
| new IntervalFilterAllInRange ({ filter.start, filter.end }), | ||
| new IntervalFilterAllWithTags (filter.tags()) | ||
| new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not make this a top-level configuration (like e.g. |
||
| }); | ||
|
|
||
| auto tracked = getTracked (database, rules, filtering); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you have already said, this should not be part of
IntervalFilterAllWithTags, but rather some function or factory which translates the individual command line arguments into filters or filter groups, like e.g.IntervalFilterOrGroup,IntervalFilterWithoutTagSet, etc.