The last test is closer to working now

This commit is contained in:
John Wiegley 2012-03-05 02:26:15 -06:00
parent 8d6bf11334
commit 3ea5d88eb3
2 changed files with 24 additions and 15 deletions

View file

@ -690,22 +690,14 @@ void changed_value_posts::output_revaluation(post_t& post, const date_t& date)
} }
namespace { namespace {
struct create_price_xact { struct insert_prices_in_map {
post_t& post; price_map_t& all_prices;
const date_t& current;
price_map_t& all_prices;
create_price_xact(post_t& _post, const date_t& _current, insert_prices_in_map(price_map_t& _all_prices)
price_map_t& _all_prices) : all_prices(_all_prices) {}
: post(_post), current(_current), all_prices(_all_prices) {}
void operator()(datetime_t& date, const amount_t& price) { void operator()(datetime_t& date, const amount_t& price) {
if (date.date() > post.value_date() && date.date() < current) { all_prices.insert(price_map_t::value_type(date, price));
DEBUG("filters.revalued",
post.value_date() << " < " << date << " < " << current);
DEBUG("filters.revalued", "inserting " << price << " at " << date);
all_prices.insert(price_map_t::value_type(date, price));
}
} }
}; };
} }
@ -780,7 +772,9 @@ void changed_value_posts::output_intermediate_prices(post_t& post,
foreach (const balance_t::amounts_map::value_type& amt_comm, foreach (const balance_t::amounts_map::value_type& amt_comm,
display_total.as_balance().amounts) display_total.as_balance().amounts)
amt_comm.first->map_prices(create_price_xact(post, current, all_prices)); amt_comm.first->map_prices(insert_prices_in_map(all_prices),
datetime_t(current),
datetime_t(post.value_date()));
// Choose the last price from each day as the price to use // Choose the last price from each day as the price to use
typedef std::map<const date_t, bool> date_map; typedef std::map<const date_t, bool> date_map;

View file

@ -90,18 +90,30 @@ public:
template <typename Edge> template <typename Edge>
bool operator()(const Edge& e) const bool operator()(const Edge& e) const
{ {
DEBUG("history.find", " reftime = " << *reftime);
if (*last_reftime)
DEBUG("history.find", " last_reftime = " << **last_reftime);
if (*oldest)
DEBUG("history.find", " oldest = " << **oldest);
if (*last_oldest)
DEBUG("history.find", " last_oldest = " << **last_oldest);
if (*last_reftime && *reftime == **last_reftime && if (*last_reftime && *reftime == **last_reftime &&
*oldest == *last_oldest) *oldest == *last_oldest) {
DEBUG("history.find", " using previous reftime");
return get(weight, e) != std::numeric_limits<std::size_t>::max(); return get(weight, e) != std::numeric_limits<std::size_t>::max();
}
const price_map_t& prices(get(ratios, e)); const price_map_t& prices(get(ratios, e));
if (prices.empty()) { if (prices.empty()) {
DEBUG("history.find", " prices map is empty for this edge");
put(weight, e, std::numeric_limits<std::size_t>::max()); put(weight, e, std::numeric_limits<std::size_t>::max());
return false; return false;
} }
price_map_t::const_iterator low = prices.upper_bound(*reftime); price_map_t::const_iterator low = prices.upper_bound(*reftime);
if (low != prices.end() && low == prices.begin()) { if (low != prices.end() && low == prices.begin()) {
DEBUG("history.find", " don't use this edge");
put(weight, e, std::numeric_limits<std::size_t>::max()); put(weight, e, std::numeric_limits<std::size_t>::max());
return false; return false;
} else { } else {
@ -109,6 +121,7 @@ public:
assert(((*low).first <= *reftime)); assert(((*low).first <= *reftime));
if (*oldest && (*low).first < **oldest) { if (*oldest && (*low).first < **oldest) {
DEBUG("history.find", " edge is out of range");
put(weight, e, std::numeric_limits<std::size_t>::max()); put(weight, e, std::numeric_limits<std::size_t>::max());
return false; return false;
} }
@ -119,6 +132,8 @@ public:
put(weight, e, secs); put(weight, e, secs);
put(price_point, e, price_point_t((*low).first, (*low).second)); put(price_point, e, price_point_t((*low).first, (*low).second));
DEBUG("history.find", " using edge at price point "
<< (*low).first << " " << (*low).second);
return true; return true;
} }
} }