summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-16 04:50:11 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-16 04:50:11 -0400
commit479ac0ce36279125d0d96c422221408fa1970eef (patch)
treebe285f13cea94b850ad23823626b2413a2412141
parent1aff6ec01deaee142209d007a7acebb859677603 (diff)
downloadfork-ledger-479ac0ce36279125d0d96c422221408fa1970eef.tar.gz
fork-ledger-479ac0ce36279125d0d96c422221408fa1970eef.tar.bz2
fork-ledger-479ac0ce36279125d0d96c422221408fa1970eef.zip
Fleshed out the "stats" command
-rw-r--r--src/output.cc91
-rw-r--r--src/output.h24
2 files changed, 98 insertions, 17 deletions
diff --git a/src/output.cc b/src/output.cc
index f7090e4e..fc919d21 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -88,17 +88,58 @@ void gather_statistics::flush()
{
std::ostream& out(report.output_stream);
- out << "Statistics gathered for this report:" << std::endl
- << " Total entries: " ;
-
- out << std::right;
- out.width(6);
- out << statistics.total_entries << std::endl
- << " Total transactions: ";
-
- out << std::right;
- out.width(6);
- out << statistics.total_xacts << std::endl;
+ out << "Statistics gathered for this report:" << std::endl;
+
+ out << std::endl << " Time period: "
+ << statistics.earliest_xact << " to "
+ << statistics.latest_xact << std::endl << std::endl;
+
+ out << " Files these transactions came from:" << std::endl;
+
+ bool first = true;
+ foreach (const path& pathname, statistics.filenames)
+ out << " " << pathname.string() << std::endl;
+ out << std::endl;
+
+ out << " Unique payees: ";
+ out.width(8);
+ out << std::right << statistics.payees_referenced.size() << std::endl;
+
+ out << " Unique accounts: ";
+ out.width(8);
+ out << std::right << statistics.accounts_referenced.size() << std::endl;
+
+ out << " Number of entries: " ;
+ out.width(8);
+ out << std::right << statistics.total_entries << std::endl;
+
+ out << " Number of transactions: ";
+ out.width(8);
+ out << std::right << statistics.total_xacts;
+
+ out << " (";
+ out.precision(2);
+ out << (double(statistics.unique_dates.size()) /
+ double(statistics.total_xacts)) << " per day)" << std::endl;
+
+ out << " Days since last xact: ";
+ out.width(8);
+ out << std::right << (CURRENT_DATE() - statistics.latest_xact).days()
+ << std::endl;
+
+ out << " Xacts in last 7 days: ";
+ out.width(8);
+ out << std::right << statistics.total_last_7_days << std::endl;
+ out << " Xacts in last 30 days: ";
+ out.width(8);
+ out << std::right << statistics.total_last_30_days << std::endl;
+ out << " Xacts seen this month: ";
+ out.width(8);
+ out << std::right << statistics.total_this_month << std::endl;
+
+ out << " Uncleared transactions: ";
+ out.width(8);
+ out << std::right << statistics.total_uncleared_xacts << std::endl;
out.flush();
}
@@ -112,6 +153,34 @@ void gather_statistics::operator()(xact_t& xact)
if (last_xact != &xact) {
statistics.total_xacts++;
last_xact = &xact;
+
+ statistics.filenames.insert(xact.pathname);
+
+ date_t date = xact.reported_date();
+
+ statistics.unique_dates.insert(date);
+
+ if (date.year() == CURRENT_DATE().year() &&
+ date.month() == CURRENT_DATE().month())
+ statistics.total_this_month++;
+
+ if ((CURRENT_DATE() - date).days() <= 30)
+ statistics.total_last_30_days++;
+ if ((CURRENT_DATE() - date).days() <= 7)
+ statistics.total_last_7_days++;
+
+ if (xact.state() != item_t::CLEARED)
+ statistics.total_uncleared_xacts++;
+
+ if (! is_valid(statistics.earliest_xact) ||
+ xact.reported_date() < statistics.earliest_xact)
+ statistics.earliest_xact = xact.reported_date();
+ if (! is_valid(statistics.latest_xact) ||
+ xact.reported_date() > statistics.latest_xact)
+ statistics.latest_xact = xact.reported_date();
+
+ statistics.accounts_referenced.insert(xact.account->fullname());
+ statistics.payees_referenced.insert(xact.entry->payee);
}
}
diff --git a/src/output.h b/src/output.h
index e68e51f3..31214d29 100644
--- a/src/output.h
+++ b/src/output.h
@@ -91,14 +91,26 @@ protected:
xact_t * last_xact;
struct statistics_t {
- std::size_t total_entries;
- std::size_t total_xacts;
+ std::set<path> filenames;
+
+ std::size_t total_entries;
+ std::size_t total_xacts;
+ std::size_t total_uncleared_xacts;
+ std::size_t total_last_7_days;
+ std::size_t total_last_30_days;
+ std::size_t total_this_month;
+
+ date_t earliest_xact;
+ date_t latest_xact;
+
+ std::set<string> accounts_referenced;
+ std::set<string> payees_referenced;
+ std::set<date_t> unique_dates;
statistics_t()
- : total_entries(0),
- total_xacts(0) {}
- }
- statistics;
+ : total_entries(0), total_xacts(0), total_uncleared_xacts(0),
+ total_last_7_days(0), total_last_30_days(0), total_this_month(0) {}
+ } statistics;
public:
gather_statistics(report_t& _report)