Timeline: Implemented ::tracked

This commit is contained in:
Paul Beckingham 2016-04-22 01:02:57 -04:00
parent a364c75dce
commit 31d2ebe488

View file

@ -28,7 +28,6 @@
#include <Timeline.h> #include <Timeline.h>
#include <timew.h> #include <timew.h>
#include <sstream> #include <sstream>
#include <iostream> // TODO Remove
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// The Timeline object represents a continuum with a defined start and end // The Timeline object represents a continuum with a defined start and end
@ -71,38 +70,41 @@ void Timeline::exclude (const Exclusion& exclusion)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::vector <Interval> Timeline::tracked (Rules& rules) const std::vector <Interval> Timeline::tracked (Rules& rules) const
{ {
// Create a range representing the whole timeline. // Create a range representing the whole timeline.
// If no range is defined, then assume the full range of all the inclusions. // If no range is defined, then assume the full range of all the inclusions.
Daterange timelineRange {_range}; Daterange overallRange {_range};
if (timelineRange.start ().toEpoch () == 0 && if (! overallRange.isStarted () &&
timelineRange.end ().toEpoch () == 0) ! overallRange.isEnded ())
{ overallRange = overallRangeFromIntervals (_inclusions);
for (auto& inclusion : _inclusions)
{
if (inclusion.start () < timelineRange.start () || timelineRange.start ().toEpoch () == 0)
timelineRange.start (inclusion.start ());
// Deliberately mixed start/end. // Cobmine all the non-trackable time.
if (inclusion.start () > timelineRange.end ()) auto nonTrackable = combineHolidaysAndExclusions (overallRange, rules, _exclusions);
timelineRange.end (inclusion.start ());
if (inclusion.end () > timelineRange.end ())
timelineRange.end (inclusion.end ());
}
std::cout << "# Timeline augmented range: " << timelineRange.start ().toISO () << " - " << timelineRange.end ().toISO () << "\n";
}
// TODO Return results, which should be the stored inclusions, clipped by
// subtracting all the exclusions nad holidays.
/*
std::vector <Interval> combined; std::vector <Interval> combined;
for (auto& interval : _inclusions)
{
std::vector <Daterange> intervalFragments {interval.range ()};
return combined; for (auto& exclusion : nonTrackable)
*/ {
std::vector <Daterange> brokenFragments;
for (auto& fragment : intervalFragments)
for (auto& broken : fragment.subtract (exclusion))
brokenFragments.push_back (broken);
intervalFragments = brokenFragments;
}
for (auto& fragment : intervalFragments)
{
// Clone the interval, set the new range.
Interval clipped {interval};
clipped.range (fragment);
combined.push_back (clipped);
}
}
return combined;;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////