Added a --forecast-years option
This sets how many years of forecasting Ledger will do before it terminates the attempt.
This commit is contained in:
parent
451b0e9b76
commit
b0f12c600c
5 changed files with 20 additions and 8 deletions
|
|
@ -209,7 +209,11 @@ post_handler_ptr chain_post_handlers(report_t& report,
|
||||||
= new forecast_posts(handler,
|
= new forecast_posts(handler,
|
||||||
item_predicate(report.HANDLER(forecast_while_).str(),
|
item_predicate(report.HANDLER(forecast_while_).str(),
|
||||||
report.what_to_keep()),
|
report.what_to_keep()),
|
||||||
report);
|
report,
|
||||||
|
report.HANDLED(forecast_years_) ?
|
||||||
|
static_cast<std::size_t>
|
||||||
|
(report.HANDLER(forecast_years_).value.to_long()) :
|
||||||
|
5UL);
|
||||||
forecast_handler->add_period_xacts(report.session.journal->period_xacts);
|
forecast_handler->add_period_xacts(report.session.journal->period_xacts);
|
||||||
handler.reset(forecast_handler);
|
handler.reset(forecast_handler);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -871,9 +871,11 @@ void forecast_posts::flush()
|
||||||
date_t next = *(*least).first.next;
|
date_t next = *(*least).first.next;
|
||||||
assert(next > begin);
|
assert(next > begin);
|
||||||
|
|
||||||
if ((next - last).days() > 365 * 5) {
|
if (static_cast<std::size_t>((next - last).days()) >
|
||||||
|
static_cast<std::size_t>(365U) * forecast_years) {
|
||||||
DEBUG("filters.forecast",
|
DEBUG("filters.forecast",
|
||||||
"Forecast transaction exceeds 5 years beyond today");
|
"Forecast transaction exceeds " << forecast_years
|
||||||
|
<< " years beyond today");
|
||||||
pending_posts.erase(least);
|
pending_posts.erase(least);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -764,16 +764,19 @@ public:
|
||||||
*/
|
*/
|
||||||
class forecast_posts : public generate_posts
|
class forecast_posts : public generate_posts
|
||||||
{
|
{
|
||||||
item_predicate pred;
|
item_predicate pred;
|
||||||
scope_t& context;
|
scope_t& context;
|
||||||
|
const std::size_t forecast_years;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
forecast_posts(post_handler_ptr handler,
|
forecast_posts(post_handler_ptr handler,
|
||||||
const item_predicate& predicate,
|
const item_predicate& predicate,
|
||||||
scope_t& _context)
|
scope_t& _context,
|
||||||
: generate_posts(handler), pred(predicate), context(_context) {
|
const std::size_t _forecast_years)
|
||||||
|
: generate_posts(handler), pred(predicate), context(_context),
|
||||||
|
forecast_years(_forecast_years) {
|
||||||
TRACE_CTOR(forecast_posts,
|
TRACE_CTOR(forecast_posts,
|
||||||
"post_handler_ptr, const item_predicate&, scope_t&");
|
"post_handler_ptr, item_predicate, scope_t&, std::size_t");
|
||||||
}
|
}
|
||||||
virtual ~forecast_posts() throw() {
|
virtual ~forecast_posts() throw() {
|
||||||
TRACE_DTOR(forecast_posts);
|
TRACE_DTOR(forecast_posts);
|
||||||
|
|
|
||||||
|
|
@ -559,6 +559,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
||||||
case 'f':
|
case 'f':
|
||||||
OPT(flat);
|
OPT(flat);
|
||||||
else OPT_ALT(forecast_while_, forecast_);
|
else OPT_ALT(forecast_while_, forecast_);
|
||||||
|
else OPT(forecast_years_);
|
||||||
else OPT(format_);
|
else OPT(format_);
|
||||||
else OPT(force_color);
|
else OPT(force_color);
|
||||||
else OPT(force_pager);
|
else OPT(force_pager);
|
||||||
|
|
|
||||||
|
|
@ -240,6 +240,7 @@ public:
|
||||||
HANDLER(force_color).report(out);
|
HANDLER(force_color).report(out);
|
||||||
HANDLER(force_pager).report(out);
|
HANDLER(force_pager).report(out);
|
||||||
HANDLER(forecast_while_).report(out);
|
HANDLER(forecast_while_).report(out);
|
||||||
|
HANDLER(forecast_years_).report(out);
|
||||||
HANDLER(format_).report(out);
|
HANDLER(format_).report(out);
|
||||||
HANDLER(gain).report(out);
|
HANDLER(gain).report(out);
|
||||||
HANDLER(head_).report(out);
|
HANDLER(head_).report(out);
|
||||||
|
|
@ -544,6 +545,7 @@ public:
|
||||||
OPTION(report_t, force_color);
|
OPTION(report_t, force_color);
|
||||||
OPTION(report_t, force_pager);
|
OPTION(report_t, force_pager);
|
||||||
OPTION(report_t, forecast_while_);
|
OPTION(report_t, forecast_while_);
|
||||||
|
OPTION(report_t, forecast_years_);
|
||||||
OPTION(report_t, format_); // -F
|
OPTION(report_t, format_); // -F
|
||||||
|
|
||||||
OPTION_(report_t, gain, DO() { // -G
|
OPTION_(report_t, gain, DO() { // -G
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue