Restored --percent option, added baseline test
This commit is contained in:
parent
7287aad336
commit
521b935aa8
9 changed files with 157 additions and 9 deletions
|
|
@ -194,6 +194,10 @@ namespace {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_t get_true(account_t&) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
value_t get_depth_spacer(account_t& account)
|
value_t get_depth_spacer(account_t& account)
|
||||||
{
|
{
|
||||||
std::size_t depth = 0;
|
std::size_t depth = 0;
|
||||||
|
|
@ -217,6 +221,10 @@ namespace {
|
||||||
value_t get_wrapper(call_scope_t& scope) {
|
value_t get_wrapper(call_scope_t& scope) {
|
||||||
return (*Func)(find_scope<account_t>(scope));
|
return (*Func)(find_scope<account_t>(scope));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_t get_parent(account_t& account) {
|
||||||
|
return value_t(static_cast<scope_t *>(account.parent));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t::ptr_op_t account_t::lookup(const string& name)
|
expr_t::ptr_op_t account_t::lookup(const string& name)
|
||||||
|
|
@ -243,9 +251,16 @@ expr_t::ptr_op_t account_t::lookup(const string& name)
|
||||||
return WRAP_FUNCTOR(get_wrapper<&get_depth_spacer>);
|
return WRAP_FUNCTOR(get_wrapper<&get_depth_spacer>);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
if (name == "is_account")
|
||||||
|
return WRAP_FUNCTOR(get_wrapper<&get_true>);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
if (name == "partial_account")
|
if (name == "partial_account")
|
||||||
return WRAP_FUNCTOR(get_partial_name);
|
return WRAP_FUNCTOR(get_partial_name);
|
||||||
|
else if (name == "parent")
|
||||||
|
return WRAP_FUNCTOR(get_wrapper<&get_parent>);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
|
|
|
||||||
11
src/item.cc
11
src/item.cc
|
|
@ -247,6 +247,10 @@ namespace {
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_t ignore(item_t&) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
template <value_t (*Func)(item_t&)>
|
template <value_t (*Func)(item_t&)>
|
||||||
value_t get_wrapper(call_scope_t& scope) {
|
value_t get_wrapper(call_scope_t& scope) {
|
||||||
return (*Func)(find_scope<item_t>(scope));
|
return (*Func)(find_scope<item_t>(scope));
|
||||||
|
|
@ -330,6 +334,11 @@ expr_t::ptr_op_t item_t::lookup(const string& name)
|
||||||
return WRAP_FUNCTOR(ledger::has_tag);
|
return WRAP_FUNCTOR(ledger::has_tag);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
if (name == "is_account")
|
||||||
|
return WRAP_FUNCTOR(get_wrapper<&ignore>);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
if (name == "meta")
|
if (name == "meta")
|
||||||
return WRAP_FUNCTOR(ledger::get_tag);
|
return WRAP_FUNCTOR(ledger::get_tag);
|
||||||
|
|
@ -343,6 +352,8 @@ expr_t::ptr_op_t item_t::lookup(const string& name)
|
||||||
case 'p':
|
case 'p':
|
||||||
if (name == "pending")
|
if (name == "pending")
|
||||||
return WRAP_FUNCTOR(get_wrapper<&get_pending>);
|
return WRAP_FUNCTOR(get_wrapper<&get_pending>);
|
||||||
|
else if (name == "parent")
|
||||||
|
return WRAP_FUNCTOR(get_wrapper<&ignore>);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,10 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus)
|
||||||
call_scope_t call_args(scope);
|
call_scope_t call_args(scope);
|
||||||
if (value_t obj = left()->left()->as_function()(call_args)) {
|
if (value_t obj = left()->left()->as_function()(call_args)) {
|
||||||
if (obj.is_pointer()) {
|
if (obj.is_pointer()) {
|
||||||
|
if (obj.as_pointer_lval<scope_t>() == NULL) {
|
||||||
|
throw_(calc_error,
|
||||||
|
_("Left operand of . operator is NULL"));
|
||||||
|
} else {
|
||||||
scope_t& objscope(obj.as_ref_lval<scope_t>());
|
scope_t& objscope(obj.as_ref_lval<scope_t>());
|
||||||
if (ptr_op_t member = objscope.lookup(right()->as_ident())) {
|
if (ptr_op_t member = objscope.lookup(right()->as_ident())) {
|
||||||
result = member->calc(objscope);
|
result = member->calc(objscope);
|
||||||
|
|
@ -174,6 +178,7 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (right()->kind != IDENT)
|
if (right()->kind != IDENT)
|
||||||
throw_(calc_error,
|
throw_(calc_error,
|
||||||
_("Right operand of . operator must be an identifier"));
|
_("Right operand of . operator must be an identifier"));
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,8 @@ void format_accounts::flush()
|
||||||
foreach (account_t * account, posted_accounts)
|
foreach (account_t * account, posted_accounts)
|
||||||
displayed += post_account(*account);
|
displayed += post_account(*account);
|
||||||
|
|
||||||
if (! report.HANDLED(no_total) && displayed > 1) {
|
if (displayed > 1 &&
|
||||||
|
! report.HANDLED(no_total) && ! report.HANDLED(percent)) {
|
||||||
bind_scope_t bound_scope(report, *report.session.master);
|
bind_scope_t bound_scope(report, *report.session.master);
|
||||||
separator_format.format(out, bound_scope);
|
separator_format.format(out, bound_scope);
|
||||||
total_line_format.format(out, bound_scope);
|
total_line_format.format(out, bound_scope);
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,8 @@ expr_t::ptr_op_t post_t::lookup(const string& name)
|
||||||
return WRAP_FUNCTOR(get_wrapper<&get_payee>);
|
return WRAP_FUNCTOR(get_wrapper<&get_payee>);
|
||||||
else if (name == "primary")
|
else if (name == "primary")
|
||||||
return WRAP_FUNCTOR(get_wrapper<&get_commodity_is_primary>);
|
return WRAP_FUNCTOR(get_wrapper<&get_commodity_is_primary>);
|
||||||
|
else if (name == "parent")
|
||||||
|
return WRAP_FUNCTOR(get_wrapper<&get_xact>);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
|
|
|
||||||
|
|
@ -291,6 +291,13 @@ value_t report_t::fn_ansify_if(call_scope_t& scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value_t report_t::fn_percent(call_scope_t& scope)
|
||||||
|
{
|
||||||
|
interactive_t args(scope, "aa");
|
||||||
|
return (amount_t("100.00%") *
|
||||||
|
(args.get<amount_t>(0) / args.get<amount_t>(1)).number());
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
value_t fn_black(call_scope_t&) {
|
value_t fn_black(call_scope_t&) {
|
||||||
return string_value("black");
|
return string_value("black");
|
||||||
|
|
@ -402,7 +409,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
||||||
{
|
{
|
||||||
switch (*p) {
|
switch (*p) {
|
||||||
case '%':
|
case '%':
|
||||||
OPT_CH(percentage);
|
OPT_CH(percent);
|
||||||
break;
|
break;
|
||||||
case 'A':
|
case 'A':
|
||||||
OPT_CH(average);
|
OPT_CH(average);
|
||||||
|
|
@ -568,7 +575,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
||||||
OPT(pager_);
|
OPT(pager_);
|
||||||
else OPT(payee_as_account);
|
else OPT(payee_as_account);
|
||||||
else OPT(pending);
|
else OPT(pending);
|
||||||
else OPT(percentage);
|
else OPT(percent);
|
||||||
else OPT_(period_);
|
else OPT_(period_);
|
||||||
else OPT(period_sort_);
|
else OPT(period_sort_);
|
||||||
else OPT(plot_amount_format_);
|
else OPT(plot_amount_format_);
|
||||||
|
|
@ -842,6 +849,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
|
||||||
}
|
}
|
||||||
else if (is_eq(p, "post"))
|
else if (is_eq(p, "post"))
|
||||||
return WRAP_FUNCTOR(fn_false);
|
return WRAP_FUNCTOR(fn_false);
|
||||||
|
else if (is_eq(p, "percent"))
|
||||||
|
return MAKE_FUNCTOR(report_t::fn_percent);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,7 @@ public:
|
||||||
value_t fn_join(call_scope_t& scope);
|
value_t fn_join(call_scope_t& scope);
|
||||||
value_t fn_format_date(call_scope_t& scope);
|
value_t fn_format_date(call_scope_t& scope);
|
||||||
value_t fn_ansify_if(call_scope_t& scope);
|
value_t fn_ansify_if(call_scope_t& scope);
|
||||||
|
value_t fn_percent(call_scope_t& scope);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
value_t fn_now(call_scope_t&) {
|
value_t fn_now(call_scope_t&) {
|
||||||
|
|
@ -248,7 +249,7 @@ public:
|
||||||
HANDLER(pager_).report(out);
|
HANDLER(pager_).report(out);
|
||||||
HANDLER(payee_as_account).report(out);
|
HANDLER(payee_as_account).report(out);
|
||||||
HANDLER(pending).report(out);
|
HANDLER(pending).report(out);
|
||||||
HANDLER(percentage).report(out);
|
HANDLER(percent).report(out);
|
||||||
HANDLER(period_).report(out);
|
HANDLER(period_).report(out);
|
||||||
HANDLER(period_sort_).report(out);
|
HANDLER(period_sort_).report(out);
|
||||||
HANDLER(plot_amount_format_).report(out);
|
HANDLER(plot_amount_format_).report(out);
|
||||||
|
|
@ -582,7 +583,11 @@ public:
|
||||||
parent->HANDLER(limit_).on(string("--pending"), "pending");
|
parent->HANDLER(limit_).on(string("--pending"), "pending");
|
||||||
});
|
});
|
||||||
|
|
||||||
OPTION(report_t, percentage); // -%
|
OPTION_(report_t, percent, DO() { // -%
|
||||||
|
parent->HANDLER(total_)
|
||||||
|
.set_expr(string("--percent"),
|
||||||
|
"is_account&parent&parent.total&percent(total, parent.total)");
|
||||||
|
});
|
||||||
|
|
||||||
OPTION__
|
OPTION__
|
||||||
(report_t, period_, // -p
|
(report_t, period_, // -p
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,12 @@ session_t::session_t()
|
||||||
commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET);
|
commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET);
|
||||||
else
|
else
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
||||||
|
// Add a "percentile" commodity
|
||||||
|
if (commodity_t * commodity = commodity_pool->create("%"))
|
||||||
|
commodity->add_flags(COMMODITY_BUILTIN | COMMODITY_NOMARKET);
|
||||||
|
else
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t session_t::read_journal(std::istream& in,
|
std::size_t session_t::read_journal(std::istream& in,
|
||||||
|
|
|
||||||
94
test/baseline/opt-percent.test
Normal file
94
test/baseline/opt-percent.test
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
bal --percent
|
||||||
|
<<<
|
||||||
|
2008/01/11 LIAT
|
||||||
|
Expenses:Travel:Airfare $40.00
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/01/14 cheaptickets.com
|
||||||
|
Expenses:Travel:Airfare $182.19
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/02/05 CTX
|
||||||
|
Expenses:Travel:Auto $240.38
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/02/05 UNITED
|
||||||
|
Expenses:Travel:Airfare $238.80
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/02/05 UNITED
|
||||||
|
Expenses:Travel:Airfare $238.80
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/02/22 BUDGET RENT-A-CAR
|
||||||
|
Expenses:Travel:Auto $40.59
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/03/16 IBERIA
|
||||||
|
Expenses:Travel:Airfare $1,231.60
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/03/16 IBERIA
|
||||||
|
Expenses:Travel:Airfare $1,231.60
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/04/03 AMERICAN
|
||||||
|
Expenses:Travel:Airfare $155.86
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/04/03 AMERICAN
|
||||||
|
Expenses:Travel:Airfare $155.86
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/04/30 UNITED
|
||||||
|
Expenses:Travel:Airfare $437.21
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/04/30 UNITED
|
||||||
|
Expenses:Travel:Airfare $437.21
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/08/08 BCIS I-131 FILING FEE-
|
||||||
|
Expenses:Travel:Passport $170.00
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/09/06 AMERICAN
|
||||||
|
Expenses:Travel:Airfare $912.60
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/09/06 AMERICAN
|
||||||
|
Expenses:Travel:Airfare $912.60
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/09/22 AGNT FEE
|
||||||
|
Expenses:Travel:Airfare $70.00
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/09/22 DELTA
|
||||||
|
Expenses:Travel:Airfare $806.20
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/09/22 DELTA
|
||||||
|
Expenses:Travel:Airfare $806.20
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/09/22 LIAT 1974 LIMITED
|
||||||
|
Expenses:Travel:Airfare $418.34
|
||||||
|
Liabilities:MasterCard
|
||||||
|
|
||||||
|
2008/12/26 U.S. Department of State
|
||||||
|
Expenses:Travel:Passport $127.00
|
||||||
|
Assets:Checking
|
||||||
|
|
||||||
|
2008/12/26 U.S. Department of State
|
||||||
|
Expenses:Travel:Passport $127.00
|
||||||
|
Assets:Checking
|
||||||
|
>>>1
|
||||||
|
100.00% Assets:Checking
|
||||||
|
100.00% Expenses:Travel
|
||||||
|
92.15% Airfare
|
||||||
|
3.13% Auto
|
||||||
|
4.72% Passport
|
||||||
|
100.00% Liabilities:MasterCard
|
||||||
|
>>>2
|
||||||
|
=== 0
|
||||||
Loading…
Add table
Reference in a new issue