mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Use new filtering in getTracked
Replace getTracked in commands CmdSummary, CmdChart, CmdExport, CmdFill, CmdReport, CmdTags, and CmdContinue. Also in functions domGet and autoFill Relates to #468 Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
This commit is contained in:
parent
a7e2d8c08c
commit
c546add03f
12 changed files with 90 additions and 19 deletions
|
@ -34,6 +34,9 @@
|
|||
#include <format.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterAndGroup.h>
|
||||
|
||||
int renderChart (const CLI&, const std::string&, Interval&, Rules&, Database&);
|
||||
|
||||
|
@ -95,7 +98,12 @@ int renderChart (
|
|||
const bool verbose = rules.getBoolean ("verbose");
|
||||
|
||||
// Load the data.
|
||||
const auto tracked = getTracked (database, rules, filter);
|
||||
auto filtering = IntervalFilterAndGroup ({
|
||||
new IntervalFilterAllInRange ({ filter.start, filter.end }),
|
||||
new IntervalFilterAllWithTags (filter.tags())
|
||||
});
|
||||
|
||||
auto tracked = getTracked (database, rules, filtering);
|
||||
|
||||
if (tracked.empty ())
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <timew.h>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdContinue (
|
||||
|
@ -74,9 +75,8 @@ int CmdContinue (
|
|||
}
|
||||
else if (!filter.tags ().empty ())
|
||||
{
|
||||
Interval tagFilter = {filter};
|
||||
tagFilter.setRange (0, 0);
|
||||
auto tracked = getTracked (database, rules, tagFilter);
|
||||
auto filtering = IntervalFilterAllWithTags (filter.tags());
|
||||
auto tracked = getTracked (database, rules, filtering);
|
||||
|
||||
if (tracked.empty())
|
||||
{
|
||||
|
@ -120,11 +120,13 @@ int CmdContinue (
|
|||
to_copy.end = end_time;
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
if (validate (cli, rules, database, to_copy))
|
||||
{
|
||||
database.addInterval (to_copy, verbose);
|
||||
journal.endTransaction ();
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << intervalSummarize (rules, to_copy);
|
||||
|
|
|
@ -27,6 +27,9 @@
|
|||
#include <commands.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterAndGroup.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdExport (
|
||||
|
@ -35,7 +38,16 @@ int CmdExport (
|
|||
Database& database)
|
||||
{
|
||||
auto filter = cli.getFilter ();
|
||||
std::cout << jsonFromIntervals (getTracked (database, rules, filter));
|
||||
|
||||
auto filtering = IntervalFilterAndGroup ({
|
||||
new IntervalFilterAllInRange ({ filter.start, filter.end }),
|
||||
new IntervalFilterAllWithTags (filter.tags())
|
||||
});
|
||||
|
||||
auto intervals = getTracked (database, rules, filtering);
|
||||
|
||||
std::cout << jsonFromIntervals (intervals);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <commands.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdFill (
|
||||
|
@ -49,7 +50,9 @@ int CmdFill (
|
|||
// Load the data.
|
||||
// Note: There is no filter.
|
||||
Interval filter;
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
|
||||
auto filtering = IntervalFilterAllInRange ({ 0, 0 });
|
||||
auto tracked = getTracked (database, rules, filtering);
|
||||
|
||||
journal.startTransaction ();
|
||||
|
||||
|
|
|
@ -44,13 +44,17 @@ int CmdGet (
|
|||
for (auto& reference : references)
|
||||
{
|
||||
std::string value;
|
||||
|
||||
if (! domGet (database, filter, rules, reference, value))
|
||||
{
|
||||
throw format ("DOM reference '{1}' is not valid.", reference);
|
||||
}
|
||||
|
||||
results.push_back (value);
|
||||
}
|
||||
|
||||
std::cout << join (" ", results) << '\n';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <FS.h>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterAndGroup.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Given a partial match for an extension script name, find the full patch of
|
||||
|
@ -91,7 +94,12 @@ int CmdReport (
|
|||
|
||||
// Compose Header info.
|
||||
auto filter = cli.getFilter ();
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
auto filtering = IntervalFilterAndGroup ({
|
||||
new IntervalFilterAllInRange ({ filter.start, filter.end }),
|
||||
new IntervalFilterAllWithTags (filter.tags ())
|
||||
});
|
||||
|
||||
auto tracked = getTracked (database, rules, filtering);
|
||||
|
||||
rules.set ("temp.report.start", filter.is_started () ? filter.start.toISO () : "");
|
||||
rules.set ("temp.report.end", filter.is_ended () ? filter.end.toISO () : "");
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#include <commands.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
#include <IntervalFilterAndGroup.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
|
||||
// Implemented in CmdChart.cpp.
|
||||
std::map <Datetime, std::string> createHolidayMap (Rules&, Interval&);
|
||||
|
@ -48,7 +51,12 @@ int CmdSummary (
|
|||
auto filter = cli.getFilter (Range { Datetime ("today"), Datetime ("tomorrow") });
|
||||
|
||||
// Load the data.
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
auto filtering = IntervalFilterAndGroup ({
|
||||
new IntervalFilterAllInRange ({ filter.start, filter.end }),
|
||||
new IntervalFilterAllWithTags (filter.tags())
|
||||
});
|
||||
|
||||
auto tracked = getTracked (database, rules, filtering);
|
||||
|
||||
if (tracked.empty ())
|
||||
{
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#include <Color.h>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterAndGroup.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdTags (
|
||||
|
@ -42,10 +45,14 @@ int CmdTags (
|
|||
|
||||
// Create a filter, with no default range.
|
||||
auto filter = cli.getFilter ();
|
||||
auto filtering = IntervalFilterAndGroup ({
|
||||
new IntervalFilterAllInRange ({ filter.start, filter.end }),
|
||||
new IntervalFilterAllWithTags (filter.tags ())
|
||||
});
|
||||
|
||||
// Generate a unique, ordered list of tags.
|
||||
std::set <std::string> tags;
|
||||
for (const auto& interval : getTracked (database, rules, filter))
|
||||
for (const auto& interval : getTracked (database, rules, filtering))
|
||||
for (auto& tag : interval.tags ())
|
||||
tags.insert (tag);
|
||||
|
||||
|
|
16
src/data.cpp
16
src/data.cpp
|
@ -36,6 +36,7 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <IntervalFactory.h>
|
||||
#include <IntervalFilter.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Read rules and extract all holiday definitions. Create a Range for each
|
||||
|
@ -495,7 +496,7 @@ Interval clip (const Interval& interval, const Range& range)
|
|||
std::vector <Interval> getTracked (
|
||||
Database& database,
|
||||
const Rules& rules,
|
||||
Interval& filter)
|
||||
IntervalFilter& filter)
|
||||
{
|
||||
int current_id = 0;
|
||||
std::vector <Interval> intervals;
|
||||
|
@ -513,11 +514,15 @@ std::vector <Interval> getTracked (
|
|||
for (auto& interval : expandLatest (latest, rules))
|
||||
{
|
||||
++current_id;
|
||||
if (matchesFilter (interval, filter))
|
||||
if (filter.accepts (interval))
|
||||
{
|
||||
interval.id = current_id;
|
||||
intervals.push_back (interval);
|
||||
}
|
||||
else if (filter.is_done ())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -526,11 +531,11 @@ std::vector <Interval> getTracked (
|
|||
Interval interval = IntervalFactory::fromSerialization(*it);
|
||||
interval.id = ++current_id;
|
||||
|
||||
if (matchesFilter (interval, filter))
|
||||
if (filter.accepts (interval))
|
||||
{
|
||||
intervals.push_back (std::move (interval));
|
||||
}
|
||||
else if ((interval.start < filter.start) && ! interval.intersects (filter))
|
||||
else if (filter.is_done ())
|
||||
{
|
||||
// Since we are moving backwards in time, and the intervals are in sorted
|
||||
// order, if the filter is after the interval, we know there will be no
|
||||
|
@ -541,9 +546,10 @@ std::vector <Interval> getTracked (
|
|||
|
||||
debug (format ("Loaded {1} tracked intervals", intervals.size ()));
|
||||
|
||||
// By default intervals are sorted by id, but getTracked needs to return the
|
||||
// By default, intervals are sorted by id, but getTracked needs to return the
|
||||
// intervals sorted by date, which are ids in reverse order.
|
||||
std::reverse (intervals.begin (), intervals.end ());
|
||||
|
||||
return intervals;
|
||||
}
|
||||
|
||||
|
|
10
src/dom.cpp
10
src/dom.cpp
|
@ -31,6 +31,9 @@
|
|||
#include <format.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
#include <IntervalFilterAllWithTags.h>
|
||||
#include <IntervalFilterAndGroup.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool domGet (
|
||||
|
@ -107,7 +110,12 @@ bool domGet (
|
|||
// dom.tracked.<...>
|
||||
else if (pig.skipLiteral ("tracked."))
|
||||
{
|
||||
auto tracked = getTracked (database, rules, filter);
|
||||
auto filtering = IntervalFilterAndGroup ({
|
||||
new IntervalFilterAllInRange ({ filter.start, filter.end }),
|
||||
new IntervalFilterAllWithTags (filter.tags())
|
||||
});
|
||||
|
||||
auto tracked = getTracked (database, rules, filtering);
|
||||
int count = static_cast <int> (tracked.size ());
|
||||
|
||||
// dom.tracked.tags
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <Exclusion.h>
|
||||
#include <Palette.h>
|
||||
#include <Color.h>
|
||||
#include <IntervalFilter.h>
|
||||
|
||||
// data.cpp
|
||||
std::vector <Range> getHolidays (const Rules&);
|
||||
|
@ -52,7 +53,7 @@ Range outerRange (const std::vector <Interval>&);
|
|||
bool matchesRange (const Interval&, const Range&);
|
||||
bool matchesFilter (const Interval&, const Interval&);
|
||||
Interval clip (const Interval&, const Range&);
|
||||
std::vector <Interval> getTracked (Database&, const Rules&, Interval&);
|
||||
std::vector <Interval> getTracked (Database&, const Rules&, IntervalFilter&);
|
||||
std::vector <Range> getUntracked (Database&, const Rules&, Interval&);
|
||||
Interval getLatestInterval (Database&);
|
||||
Range getFullDay (const Datetime&);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <format.h>
|
||||
#include <timew.h>
|
||||
#include <iostream>
|
||||
#include <IntervalFilterAllInRange.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// :fill
|
||||
|
@ -44,7 +45,7 @@ void autoFill (
|
|||
Interval& interval)
|
||||
{
|
||||
// An empty filter allows scanning beyond interval range.
|
||||
Interval range_filter;
|
||||
auto range_filter = IntervalFilterAllInRange ({0, 0});
|
||||
|
||||
// Look backwards from interval.start to a boundary.
|
||||
auto tracked = getTracked (database, rules, range_filter);
|
||||
|
@ -99,9 +100,10 @@ static bool autoAdjust (
|
|||
{
|
||||
const bool verbose = rules.getBoolean ("verbose");
|
||||
|
||||
// We do not need the adjust flag set to "flatten" the database if the last
|
||||
// We do not need the :adjust flag set to "flatten" the database if the last
|
||||
// interval is open and encloses the current interval that we're adding.
|
||||
Interval latest = getLatestInterval (database);
|
||||
|
||||
if (interval.is_open () && latest.encloses (interval))
|
||||
{
|
||||
if (latest.tags () == interval.tags ())
|
||||
|
@ -113,9 +115,11 @@ static bool autoAdjust (
|
|||
|
||||
database.deleteInterval (latest);
|
||||
latest.end = interval.start;
|
||||
|
||||
for (auto& interval : flatten (latest, getAllExclusions (rules, latest)))
|
||||
{
|
||||
database.addInterval (interval, verbose);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << intervalSummarize (rules, interval);
|
||||
|
@ -123,7 +127,7 @@ static bool autoAdjust (
|
|||
}
|
||||
}
|
||||
|
||||
Interval overlaps_filter {interval.start, interval.end};
|
||||
auto overlaps_filter = IntervalFilterAllInRange ({interval.start, interval.end});
|
||||
auto overlaps = getTracked (database, rules, overlaps_filter);
|
||||
|
||||
if (overlaps.empty ())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue