Added xact_t::count member
This allows reports to access the "whicheth" index of the reported transaction. It's used mainly by the --average report, which divides the running total by this count to get the arithmetic mean.
This commit is contained in:
parent
36b96c47ac
commit
03219d910f
3 changed files with 17 additions and 2 deletions
|
|
@ -186,8 +186,13 @@ void calc_xacts::operator()(xact_t& xact)
|
|||
try {
|
||||
xact_t::xdata_t& xdata(xact.xdata());
|
||||
|
||||
if (last_xact && last_xact->has_xdata())
|
||||
if (last_xact) {
|
||||
assert(last_xact->has_xdata());
|
||||
add_or_set_value(xdata.total, last_xact->xdata().total);
|
||||
xdata.count = last_xact->xdata().count + 1;
|
||||
} else {
|
||||
xdata.count = 1;
|
||||
}
|
||||
|
||||
xact.add_to_value(xdata.total, amount_expr);
|
||||
|
||||
|
|
|
|||
|
|
@ -182,6 +182,11 @@ namespace {
|
|||
return xact.amount;
|
||||
}
|
||||
|
||||
value_t get_count(xact_t& xact) {
|
||||
assert(xact.xdata_);
|
||||
return xact.xdata_->count;
|
||||
}
|
||||
|
||||
value_t get_account(call_scope_t& scope)
|
||||
{
|
||||
xact_t& xact(find_scope<xact_t>(scope));
|
||||
|
|
@ -231,6 +236,8 @@ expr_t::ptr_op_t xact_t::lookup(const string& name)
|
|||
return WRAP_FUNCTOR(get_wrapper<&get_code>);
|
||||
else if (name == "cost")
|
||||
return WRAP_FUNCTOR(get_wrapper<&get_cost>);
|
||||
else if (name == "count")
|
||||
return WRAP_FUNCTOR(get_wrapper<&get_count>);
|
||||
else if (name == "calculated")
|
||||
return WRAP_FUNCTOR(get_wrapper<&get_is_calculated>);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ public:
|
|||
#define XACT_EXT_MATCHES 0x80
|
||||
|
||||
value_t total;
|
||||
std::size_t count;
|
||||
value_t value;
|
||||
date_t date;
|
||||
account_t * account;
|
||||
|
|
@ -147,12 +148,14 @@ public:
|
|||
|
||||
std::list<sort_value_t> sort_values;
|
||||
|
||||
xdata_t() : supports_flags<>(), account(NULL), ptr(NULL) {
|
||||
xdata_t()
|
||||
: supports_flags<>(), count(0), account(NULL), ptr(NULL) {
|
||||
TRACE_CTOR(xact_t::xdata_t, "");
|
||||
}
|
||||
xdata_t(const xdata_t& other)
|
||||
: supports_flags<>(other.flags()),
|
||||
total(other.total),
|
||||
count(other.count),
|
||||
value(other.value),
|
||||
date(other.date),
|
||||
account(other.account),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue