Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions src/IntervalFilterAllWithTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Member

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.

// 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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, I would opt for lowercase, i.e. or

{
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;
}
}
3 changes: 2 additions & 1 deletion src/IntervalFilterAllWithTags.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
class IntervalFilterAllWithTags : public IntervalFilter
{
public:
explicit IntervalFilterAllWithTags(std::set <std::string>);
explicit IntervalFilterAllWithTags(std::set <std::string>, const bool complexFiltering);

bool accepts (const Interval&) final;

private:
const std::set <std::string> _tags {};
const bool _complexFiltering {};
};

#endif //INCLUDED_INTERVALFILTERTAGSET
2 changes: 1 addition & 1 deletion src/commands/CmdChart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not make this a top-level configuration (like e.g. verbose), but put it into a commands subgroup. I propose commands.filtering with values simple (= default) and complex (or maybe better: boolean).

});

auto tracked = getTracked (database, rules, filtering);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CmdContinue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int CmdContinue (
}
else if (!filter.tags ().empty ())
{
auto filtering = IntervalFilterAllWithTags (filter.tags());
auto filtering = IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering"));
auto tracked = getTracked (database, rules, filtering);

if (tracked.empty())
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CmdExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int CmdExport (

auto filtering = IntervalFilterAndGroup ({
new IntervalFilterAllInRange ({ filter.start, filter.end }),
new IntervalFilterAllWithTags (filter.tags())
new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering"))
});

auto tracked = getTracked (database, rules, filtering);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CmdReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int CmdReport (
auto filter = cli.getFilter ();
auto filtering = IntervalFilterAndGroup ({
new IntervalFilterAllInRange ({ filter.start, filter.end }),
new IntervalFilterAllWithTags (filter.tags ())
new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering"))
});

auto tracked = getTracked (database, rules, filtering);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CmdSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int CmdSummary (
// Load the data.
auto filtering = IntervalFilterAndGroup ({
new IntervalFilterAllInRange ({ filter.start, filter.end }),
new IntervalFilterAllWithTags (filter.tags())
new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering"))
});

auto tracked = getTracked (database, rules, filtering);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/CmdTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int CmdTags (
auto filter = cli.getFilter ();
auto filtering = IntervalFilterAndGroup ({
new IntervalFilterAllInRange ({ filter.start, filter.end }),
new IntervalFilterAllWithTags (filter.tags ())
new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering"))
});

// Generate a unique, ordered list of tags.
Expand Down
2 changes: 1 addition & 1 deletion src/dom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool domGet (
{
auto filtering = IntervalFilterAndGroup ({
new IntervalFilterAllInRange ({ filter.start, filter.end }),
new IntervalFilterAllWithTags (filter.tags())
new IntervalFilterAllWithTags (filter.tags(), rules.getBoolean("complexFiltering"))
});

auto tracked = getTracked (database, rules, filtering);
Expand Down